From ed5c4d8597288361fcff6547325b4fec8ebdbd9b Mon Sep 17 00:00:00 2001 From: John McQuah Date: Wed, 1 Jun 2022 23:11:58 -0400 Subject: [PATCH] pkgmeek: more informative progress messages --- scripts/pkgmeek | 121 ++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 65 deletions(-) diff --git a/scripts/pkgmeek b/scripts/pkgmeek index a55e755..8f451a7 100755 --- a/scripts/pkgmeek +++ b/scripts/pkgmeek @@ -8,7 +8,8 @@ main() { ######################## main routine ################################ -local o_ignored work _local_ here url u f errDL errUZ; local pkg_ood=1 +local o_ignored work _local_ here url u f +local errDL=0; local errUZ=0; local pkg_ood=1 parse_options "$@" [ "$PKGMK_RECURSIVE" = "no" ] || recursive "$@" # @@ -29,9 +30,7 @@ fi # validate_pkgfile || exit $E_PKGFILE [ -f .32bit ] && PGKMK_ARCH=32 || PKGMK_ARCH=64 -. "Pkgfile"; . "$PKGMK_CONF" - -set -e +. "Pkgfile"; . "$PKGMK_CONF"; set -e # respect the settings for centralized source and package directories ... [ -v pkg_dir ] || pkg_dir="$PKGMK_PACKAGE_DIR"/ @@ -66,7 +65,7 @@ done rm -rf "$work"; mkdir -p "$work"/{src,pkg} && cd "$work" # Skip the retrieval of sources if the user only asked for '-utd' -errDL=0; [ "$PKGMK_MTIME_ONLY" = "yes" ] || { +[ "$PKGMK_MTIME_ONLY" = "yes" ] || { for (( u=0; u<${#_local_[@]}; u++ )); do here="${_local_[$u]}"; url="${source[$u]}"; # at least one of the following commands should put a file of the @@ -80,27 +79,29 @@ here="${_local_[$u]}"; url="${source[$u]}"; [ -e "$here" ] || [[ ! $url =~ ^(https|ssh|git)://.*/(.+)\.git ]] || \ ( "$PKGMK_GIT_COMMAND" clone "$url" "$here" ) || continue ; # but if not, exit with an informative error message -if [ ! -e "$here" ]; then - error "failed to download $here. Check connection and try again." - errDL+=1 -fi ; +[ -e "$here" ] || { error "failed to download $here. Check connection and try again."; + errDL+=1; } done ; } -[ "$errDL" != 0 ] || info "Successfully obtained all needed source files." +[ $errDL != 0 ] || info "Successfully obtained all needed source files." # If the user only asked for '-utd', perform the check using the sources that do exist. -check_pkg_mtime && pkg_ood=0 || pkg_ood=1 +check_pkg_mtime && pkg_ood=0 [ "$PKGMK_MTIME_ONLY" = "no" ] || exit $pkg_ood -[ "$PKGMK_DOWNLOAD_ONLY" = "no" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "yes" ] || [ "$errDL" = 0 ] || exit $(( E_DOWNLOAD*(errDL != 0) )) - # Some further tests before proceeding with the build -[ "$pkg_ood" = 1 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \ +[ "$PKGMK_DOWNLOAD_ONLY" = "no" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || \ + [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] || [ "$PKGMK_UPDATE_SIG" = "yes" ] || \ + [ "$PKGMK_EXTRACT_ONLY" = "yes" ] || [ "$errDL" = 0 ] || exit $(( E_DOWNLOAD*(errDL != 0) )) + +# Take into account all the actions that can be done with a previously built package, +# or with a full set of sources +[ "$pkg_ood" = 0 ] || [ "$PKGMK_FORCE" = "yes" ] || [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ] \ || [ "$PKGMK_UPDATE_SIG" = "yes" ] || [ "$PKGMK_UPDATE_MD5" = "yes" ] || [ "$PKGMK_EXTRACT_ONLY" = "no" ] \ || { info "$package is up to date, use '-f' to force a rebuild."; exit 0; } # Silence the progress report if the user never intended to proceed with unpacking -[ "$PKGMK_CHECK_SIG" = "yes" ] || echo "Checking signatures before unpacking..." +[ "$pkg_ood" = 0 ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || echo "Checking signatures before unpacking..." # The option -uf is meant to be used AFTER a previous invocation of pkgmeek has # alerted the user to a footprint mismatch. The options -us|-um are likewise meant @@ -134,7 +135,8 @@ fi # All the sources should be here by now, let's verify that we can trust them. readonly cs_fail_msg="Use '--ignore-signature' to override, if you have determined integrity by other means." -[ "$PKGMK_IGNORE_SIG" = "yes" ] || { check_signature "pre-build" | parse_signify_output; +[ "$pkg_ood" = 0 ] || [ "$PKGMK_IGNORE_SIG" = "yes" ] || \ + { check_signature "pre-build" | parse_signify_output; case $? in 0) info "Sources successfully authenticated." ;; 1) error "Signature file missing or corrupted." ; echo "$cs_fail_msg" ;; @@ -145,8 +147,9 @@ esac; } # What used to be called unpack_source() is now hard-coded into the main routine. # If you need to shield specific source files from unpacking, use the "renames" # feature of Pkgfile(5) to avoid matching any of the following patterns. -errUZ=0 -for (( u=0; u<${#_local_[@]}; u++ )) ; do +if [ "$pkg_ood" = 1 ] || [ "$PKGMK_FORCE" = "yes" ]; then + + for (( u=0; u<${#_local_[@]}; u++ )) ; do here="${_local_[$u]}" case "$here" in *.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.tar.lz|*.zip|*.rpm) @@ -154,47 +157,44 @@ for (( u=0; u<${#_local_[@]}; u++ )) ; do *) cp -r "$here" src/ ;; esac -done + done -[ $errUZ = 0 ] && info "Sources successfully unpacked." || \ + [ $errUZ != 0 ] || info "Sources successfully unpacked." || \ { error "Failed to unpack all sources."; exit "$E_UNPACK"; } -[ "$PKGMK_EXTRACT_ONLY" = "no" ] || exit 0 + [ "$PKGMK_EXTRACT_ONLY" = "no" ] || exit 0 # The actual build step! -if ! (SRC=$(pwd)/src; PKG=$(pwd)/pkg; cd src; set -x; build); then - error "Unsuccessful build!"; exit $E_BUILD -else - info "Build succeeded. Moving on to compression." -fi + (SRC=$(pwd)/src; PKG=$(pwd)/pkg; cd src; set -x; build) && + info "Build succeeded. Moving on to compression." || + { error "Unsuccessful build!"; exit "$E_BUILD"; } -[ -f "$PKGMK_ROOT/.nostrip" ] && ns_filter="| grep -v -f .nostrip" -find pkg -type f $ns_filter | while read -r f; do - case $(file -b "$f") in + [ -f "$PKGMK_ROOT/.nostrip" ] && ns_filter="| grep -v -f .nostrip" + find pkg -type f $ns_filter | while read -r f; do + case $(file -b "$f") in *ELF*executable*not\ stripped*) strip --strip-all "$f" ;; *ELF*shared\ object*not\ stripped*) strip --strip-unneeded "$f" ;; current\ ar\ archive) strip --strip-debug "$f" ;; - esac -done + esac + done -find pkg -type f -path '*/man/man*/*' | grep -v '.gz$' | xargs -r -I{} gzip -9 '{}' -find pkg -xtype l -path '*/man/man*/*' -print0 \ - | xargs -x -r -n1 sh -c "ln -sf \"\$(readlink -n '{}')\" '{}'" + find pkg -type f -path '*/man/man*/*' | grep -v '.gz$' | xargs -r -I{} gzip -9 '{}' + find pkg -xtype l -path '*/man/man*/*' -print0 \ + | xargs -x -r -n1 sh -c "ln -sf \"\$(readlink -n '{}')\" '{}'" -[ $UID = 0 ] || fake_uid="--uid 0 --gid 0" -if (cd pkg; bsdtar --format=gnutar $fake_uid -cf "$pkg_dir$package" *); then - info "Package creation successful." -else - error "Unable to create the compressed package $package." - exit $E_DIRPERM -fi + [ $UID = 0 ] || fake_uid="--uid 0 --gid 0" + if (cd pkg; bsdtar --format=gnutar $fake_uid -cf "$pkg_dir$package" *); then + info "Package creation successful." + else { error "Unable to create the compressed package $package."; exit $E_DIRPERM; } + fi -# Ensure that $work/ contains the package or a symlink to it, then check the footprint -[ "$pkg_dir" = "$(pwd)/" ] || ln -sf "$pkg_dir$package" . -[ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ] || check_manifest footprint || exit $E_MANIFEST + # Ensure that $work/ contains the package or a symlink to it, then check the footprint + [ "$pkg_dir" = "$(pwd)/" ] || ln -sf "$pkg_dir$package" . + [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ] || check_manifest footprint || exit $E_MANIFEST -# Clean up, part 1: remove soft links and the {src,pkg} trees -find . -maxdepth 1 -mindepth 1 -type l -delete -[ "$PKGMK_KEEP_WORK" = "yes" ] || rm -rf src pkg + # Clean up, part 1: remove soft links and the {src,pkg} trees + find . -maxdepth 1 -mindepth 1 -type l -delete + [ "$PKGMK_KEEP_WORK" = "yes" ] || rm -rf src pkg +fi # Continue from here if the build was skipped # Install if requested # First find out how the effective user will invoke pkgadd @@ -283,35 +283,26 @@ parse_options() { -i|--install) PKGMK_INSTALL_COMMAND="/usr/bin/pkgadd" ;; -u|--upgrade) PKGMK_INSTALL_COMMAND="/usr/bin/pkgadd -u" ;; -pk|--public-key) - if [ ! "$2" ]; then - echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument" - exit 1 - fi + [ "$2" ] || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument"; + exit 1; } PKGMK_PUBLICKEY="$2" shift ;; -sk|--secret-key) - if [ ! "$2" ]; then - echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument" - exit 1 - fi + [ "$2" ] || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument"; + exit 1; } PKGMK_PRIVATEKEY="$2" shift ;; -cf|--config-file) - if [ ! "$2" ]; then - echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument" - exit 1 - fi + [ "$2" ] || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument"; + exit 1; } PKGMK_CONF="$2" shift ;; -v|--version) - echo "$(basename "$PKGMK_COMMAND") (pkgutils) $PKGMK_VERSION" - exit 0 ;; + echo "$(basename "$PKGMK_COMMAND") (pkgutils) $PKGMK_VERSION"; exit 0 ;; -h|--help) - print_help - exit 0 ;; + print_help; exit 0 ;; *) - echo "$(basename "$PKGMK_COMMAND"): invalid option $1" - exit 1 ;; + echo "$(basename "$PKGMK_COMMAND"): invalid option $1"; exit 1 ;; esac shift done