diff options
author | classabbyamp <void@placeviolette.net> | 2023-10-31 00:12:08 -0400 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2023-11-02 14:35:10 +0100 |
commit | f10e139eb1c619ce781df0cc692353a21ec50d0d (patch) | |
tree | 0b3160b06028ed34a9da1676a02ee17077eec864 | |
parent | 87845f52f18e1dedc963f1c7a86b33f3248d21fe (diff) | |
download | xtools-f10e139eb1c619ce781df0cc692353a21ec50d0d.tar.gz xtools-f10e139eb1c619ce781df0cc692353a21ec50d0d.tar.xz xtools-f10e139eb1c619ce781df0cc692353a21ec50d0d.zip |
xgensum: allow gensumming multiple templates
this should allow xgensum to checksum multiple templates at once, hopefully keeping everything isolated between template sources too exit code now counts the number of templates with errors
-rw-r--r-- | README | 2 | ||||
-rwxr-xr-x | xgensum | 236 | ||||
-rw-r--r-- | xtools.1 | 2 |
3 files changed, 127 insertions, 113 deletions
diff --git a/README b/README index d481f27..dff0baa 100644 --- a/README +++ b/README @@ -51,7 +51,7 @@ COMMANDS xetcchanges – show diff of /etc against binary packages - xgensum [-f] [-c] [-i] [-H hostdir] template + xgensum [-f] [-c] [-i] [-H hostdir] templates ... – update SHA256 sum in templates -f force (re-)download of distfiles -c use content checksum diff --git a/xgensum b/xgensum index f556967..58829cb 100755 --- a/xgensum +++ b/xgensum @@ -1,11 +1,119 @@ #!/bin/bash -# xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE - update SHA256 sums in templates +# xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATES ... - update SHA256 sums in templates usage() { - echo 'Usage: xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE' >&2 + echo 'Usage: xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATES ...' >&2 exit 1 } +gensum_template() { + local template="$1" + + . "$template" + + # pick the first supported arch. This is required for packages unavailable for + # the host arch + FLAG_a= + if ! "$XBPS_DISTDIR/xbps-src" show-avail "$pkgname" ; then + FLAG_a="-a $("$XBPS_DISTDIR/xbps-src" show "$pkgname" | sed -En -e 's/archs:[[:space:]]*([.*]*)/\1/p' | sed -e 's/\*$//' | grep -v -e '^~' | head -n1 )" + fi + + # Try to source the build-style as well. This is required for R-cran packages. + if [ -f "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh" ]; then + . "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh" + fi + + XBPS_SRCDISTDIR=$("$XBPS_DISTDIR/xbps-src" $FLAG_h show-var XBPS_SRCDISTDIR | tail -1) + srcdir="$XBPS_SRCDISTDIR/$pkgname-$version" + + if [ -n "$FLAG_f" ]; then + for f in $distfiles; do + curfile="${f#*>}" + curfile="${curfile##*/}" + distfile="$srcdir/$curfile" + rm -vf "$distfile" + done + "$XBPS_DISTDIR/xbps-src" $FLAG_h -I clean $pkgname + fi + + "$XBPS_DISTDIR/xbps-src" $FLAG_h $FLAG_a -I fetch $pkgname + + ret=0 + sums="" + for f in $distfiles; do + curfile="${f#*>}" + curfile="${curfile##*/}" + distfile="$srcdir/$curfile" + if [ -n "$FLAG_c" ];then + sum="@" + case ${distfile} in + *tar.lzma|*.tar|*.txz|*.tar.xz|*.tbz|*.tar.gz) + sum+=$(xbps-uhelper digest <(tar xf "$distfile" --to-stdout)) || ret=1 + ;; + *.gz) + sum+=$(xbps-uhelper digest <(gunzip -c "$distfile")) || ret=1 + ;; + *.tar.bz2|*.bz2) + sum+=$(xbps-uhelper digest <(bunzip2 -c "$distfile")) || ret=1 + ;; + *.zip) + if command -v unzip &>/dev/null; then + sum+=$(xbps-uhelper digest <(unzip -p "$distfile")) + if [ $? -ne 0 ]; then + echo "$pkgver: extracting $curfile to pipe." + ret=1 + fi + else + echo "$pkgver: cannot find unzip bin for extraction." + ret=1 + fi + ;; + *.rpm) + if command -v rpmextract &>/dev/null; then + sum+=$(xbps-uhelper digest <(rpm2cpio "$distfile" | bsdtar xf - --to-stdout)) + if [ $? -ne 0 ]; then + echo "$pkgver: extracting $curfile to pipe." + ret=1 + fi + else + echo "$pkgver: cannot find rpmextract for extraction." + ret=1 + fi + ;; + *.7z) + if command -v 7z &>/dev/null; then + sum+=$(xbps-uhelper digest <(7z x -o "$distfile")) + if [ $? -ne 0 ]; then + echo "$pkgver: extracting $curfile to pipe." + ret=1 + fi + else + echo "$pkgver: cannot find 7z bin for extraction." + ret=1 + fi + ;; + *.txt|*.patch|*.diff) + sum+=$(xbps-uhelper digest "$distfile") || ret=1 + ;; + *) + sum=$(xbps-uhelper digest "$distfile") || ret=1 + + esac + else + sum=$(xbps-uhelper digest "$distfile") || ret=1 + fi + sums+="${sum% *}\n " + done + + sed $FLAG_i -e "/^checksum=/,/^[^ \t]/{ + /^[ \t]/d + s/^checksum=.*/checksum=\"${sums%\n }\"/ + /^checksum=\"[^ ]*\"/s/\"//g + }" "$template" || ret=1 + + return $ret +} + while getopts fciH:h flag; do case $flag in f) FLAG_f=1 ;; @@ -20,116 +128,22 @@ shift $(( OPTIND - 1 )) XBPS_DISTDIR=$(xdistdir) || exit 1 -if [ -f "$1" ]; then - template="$1" -elif [ -f "$1/template" ]; then - template="$1/template" -elif [ -f "$XBPS_DISTDIR/srcpkgs/$1/template" ]; then - template="$XBPS_DISTDIR/srcpkgs/$1/template" -else - usage -fi - -. "$template" - -# pick the first supported arch. This is required for packages unavailable for -# the host arch -FLAG_a= -if ! "$XBPS_DISTDIR/xbps-src" show-avail $pkgname ; then - FLAG_a="-a $("$XBPS_DISTDIR/xbps-src" show $pkgname | sed -En -e 's/archs:[[:space:]]*([.*]*)/\1/p' | sed -e 's/\*$//' | grep -v -e '^~' | head -n1 )" -fi - -# Try to source the build-style as well. This is required for R-cran packages. -if [ -f "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh" ]; then - . "${XBPS_DISTDIR}/common/environment/build-style/${build_style}.sh" -fi - -XBPS_SRCDISTDIR=$("$XBPS_DISTDIR/xbps-src" $FLAG_h show-var XBPS_SRCDISTDIR | tail -1) -srcdir="$XBPS_SRCDISTDIR/$pkgname-$version" - -if [ -n "$FLAG_f" ]; then - for f in $distfiles; do - curfile="${f#*>}" - curfile="${curfile##*/}" - distfile="$srcdir/$curfile" - rm -vf "$distfile" - done - "$XBPS_DISTDIR/xbps-src" $FLAG_h -I clean $pkgname -fi - -"$XBPS_DISTDIR/xbps-src" $FLAG_h $FLAG_a -I fetch $pkgname - -ret=0 -sums="" -for f in $distfiles; do - curfile="${f#*>}" - curfile="${curfile##*/}" - distfile="$srcdir/$curfile" - if [ -n "$FLAG_c" ];then - sum="@" - case ${distfile} in - *tar.lzma|*.tar|*.txz|*.tar.xz|*.tbz|*.tar.gz) - sum+=$(xbps-uhelper digest <(tar xf "$distfile" --to-stdout)) || ret=1 - ;; - *.gz) - sum+=$(xbps-uhelper digest <(gunzip -c "$distfile")) || ret=1 - ;; - *.tar.bz2|*.bz2) - sum+=$(xbps-uhelper digest <(bunzip2 -c "$distfile")) || ret=1 - ;; - *.zip) - if command -v unzip &>/dev/null; then - sum+=$(xbps-uhelper digest <(unzip -p "$distfile")) - if [ $? -ne 0 ]; then - echo "$pkgver: extracting $curfile to pipe." - ret=1 - fi - else - echo "$pkgver: cannot find unzip bin for extraction." - ret=1 - fi - ;; - *.rpm) - if command -v rpmextract &>/dev/null; then - sum+=$(xbps-uhelper digest <(rpm2cpio "$distfile" | bsdtar xf - --to-stdout)) - if [ $? -ne 0 ]; then - echo "$pkgver: extracting $curfile to pipe." - ret=1 - fi - else - echo "$pkgver: cannot find rpmextract for extraction." - ret=1 - fi - ;; - *.7z) - if command -v 7z &>/dev/null; then - sum+=$(xbps-uhelper digest <(7z x -o "$distfile")) - if [ $? -ne 0 ]; then - echo "$pkgver: extracting $curfile to pipe." - ret=1 - fi - else - echo "$pkgver: cannot find 7z bin for extraction." - ret=1 - fi - ;; - *.txt|*.patch|*.diff) - sum+=$(xbps-uhelper digest "$distfile") || ret=1 - ;; - *) - sum=$(xbps-uhelper digest $distfile) || ret=1 - - esac +rv=0 + +for template; do + if [ -f "$template" ]; then + : + elif [ -f "$template/template" ]; then + template="$template/template" + elif [ -f "$XBPS_DISTDIR/srcpkgs/$template/template" ]; then + template="$XBPS_DISTDIR/srcpkgs/$template/template" else - sum=$(xbps-uhelper digest $distfile) || ret=1 + echo "xgensum: could not find template: $template" >&2 + rv=$(( rv + 1 )) + continue fi - sums+="${sum% *}\n " -done -sed $FLAG_i -e "/^checksum=/,/^[^ \t]/{ - /^[ \t]/d - s/^checksum=.*/checksum=\"${sums%\n }\"/ - /^checksum=\"[^ ]*\"/s/\"//g - }" "$template" || ret=1 + ( gensum_template "$template" ) || rv=$(( rv + 1 )) +done -exit $ret +exit $rv diff --git a/xtools.1 b/xtools.1 index 8aa5b1f..4f5eeac 100644 --- a/xtools.1 +++ b/xtools.1 @@ -64,7 +64,7 @@ Oo Fl f Oc \ Oo Fl c Oc \ Oo Fl i Oc \ Oo Fl H Ar hostdir Oc \ -Ar template +Ar templates\ ... .Nd update SHA256 sum in templates .Bl -tag -offset 2n -width 2n -compact .It Fl f |