From 0ddcfa250e64c682addb7e7d18851a5e596ca7ad Mon Sep 17 00:00:00 2001 From: John McQuah Date: Mon, 20 Feb 2023 08:22:40 -0500 Subject: [PATCH] pkgmeek: rearrange the options presented by print_help --- scripts/pkgmeek | 84 +++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/scripts/pkgmeek b/scripts/pkgmeek index b59da2c..35feecc 100755 --- a/scripts/pkgmeek +++ b/scripts/pkgmeek @@ -40,7 +40,7 @@ for (( s=0; s<${#source[@]}; s++ )); do http://*|https://*|ftp://*|__git__*) _local_[s]="${source[s]##*/}" # strip the leading path # and for git sources, extract the project name: - [[ "${source[s]}" =~ ^__git__ ]] && { _local_[s]="${_local_[s]%\#*}"; + [[ "${source[s]}" =~ ^__git__ ]] && { _local_[s]="${_local_[s]%%\#*}"; _local_[s]="${_local_[s]%.git}"; } ;; *) _local_[s]="${source[s]}" ;; @@ -62,7 +62,7 @@ rm -rf "$work"; mkdir -p "$work"/{src,pkg} && cd "$work" # Skip the retrieval of sources if the user asked for '-utd' or '-uf'. [[ "$PKGMK_MTIME_ONLY $PKGMK_UPDATE_FOOTPRINT" =~ yes ]] && [ -e "$PKGMK_PACKAGE_DIR/$package" ] \ || { for (( u=0; u<${#_local_[@]}; u++ )); do -here="${_local_[$u]}"; url="${source[$u]}"; +here="${_local_[u]}"; url="${source[u]}"; # at least one of the following commands should put a file of the # appropriate name in the current directory [ -e "$here" ] || [ "$src_dir" = "" ] || [ ! -e "$src_dir/$here" ] || ln -sf "$src_dir/$here" . ; @@ -82,8 +82,7 @@ done ; } # If '-utd' was requested, check the modification times and then exit. check_pkg_mtime; pkg_utd=$? -[ "$PKGMK_MTIME_ONLY" = "no" ] || [ "$PKGMK_CHECK_SIG" = "yes" ] || \ - [ "$PKGMK_FORCE" = "yes" ] || { cleanup_work; exit $pkg_utd; } +[ "$PKGMK_MTIME_ONLY" = "no" ] || { cleanup_work; exit $pkg_utd; } # Take into account all the actions that can be done without extracting # the downloaded sources @@ -129,7 +128,7 @@ if [ "$pkg_utd" = 0 ] || [[ "$PKGMK_FORCE $PKGMK_EXTRACT_ONLY" =~ yes ]]; then SRC=$PWD/src unpack_source || errUZ+=1 else for (( u=0; u<${#_local_[@]}; u++ )) ; do - here="${_local_[$u]}" + here="${_local_[u]}" case "$here" in *.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.tar.lz|*.7z|*.zip|*.rpm) bsdtar -p -o -C src -xf "$here" || errUZ+=1 ;; @@ -138,7 +137,6 @@ if [ "$pkg_utd" = 0 ] || [[ "$PKGMK_FORCE $PKGMK_EXTRACT_ONLY" =~ yes ]]; then esac done fi - [ $errUZ = 0 ] && info "Sources successfully unpacked." || \ { error "Failed to unpack all sources."; cleanup_work; exit "$E_UNPACK"; } [ "$PKGMK_EXTRACT_ONLY" = "no" ] || exit 0 @@ -233,15 +231,17 @@ PKGMK_IGNORE_NEW="no"; PKGMK_PRIVATEKEY="" ######################## subroutines ################################ parse_options() { while [ "$1" ]; do - case $1 in + case "$1" in + -h|--help) print_help; exit 0 ;; + -v|--version) + echo "$(basename "$PKGMK_COMMAND") (pkgutils) $PKGMK_VERSION"; exit 0 ;; -uf|--update-footprint) PKGMK_UPDATE_FOOTPRINT="yes" ;; -us|--update-signature) PKGMK_UPDATE_SIG="yes" ;; -rs|--refresh-signature) PKGMK_REFRESH_SIG="yes" ;; -cs|--check-signature) PKGMK_CHECK_SIG="yes" ;; - --check-md5sum|--ignore-md5sum) ;; # deprecated flags - -d|-cm|-im|--download) ;; # but don't throw an error for them + -d|--download) ;; # deprecated flags but don't throw an error for them -um|--update-md5sum) warn "updating md5sums is obsolete, ignoring option '$1'." ;; - -r|--recursive) warn "option '$1' no longer supported. Use a wrapper script for recursive operation." ;; + -r|--recursive) { warn "option '$1' no longer supported. Use a wrapper script for recursive operation."; exit 1; } ;; -c|--clean) { error "option '$1' no longer implemented in $(basename "$PKGMK_COMMAND"). Use prtwash instead."; exit 1; } ;; -do|--download-only) PKGMK_DOWNLOAD_ONLY="yes" ;; -eo|--extract-only) PKGMK_EXTRACT_ONLY="yes" ;; @@ -266,10 +266,6 @@ parse_options() { [ "$2" ] && PKGMK_CONF="$2" || { echo "$(basename "$PKGMK_COMMAND"): option $1 requires an argument"; exit 1; } shift ;; - -v|--version) - echo "$(basename "$PKGMK_COMMAND") (pkgutils) $PKGMK_VERSION"; exit 0 ;; - -h|--help) - print_help; exit 0 ;; *) echo "$(basename "$PKGMK_COMMAND"): invalid option $1"; exit 1 ;; esac @@ -279,27 +275,27 @@ parse_options() { print_help() { echo "usage: $(basename "$PKGMK_COMMAND") [options]" - echo "options: " - echo " -i, --install build and install package" - echo " -u, --upgrade build and install package (as upgrade)" - echo " -do, --download-only stop after downloading all the necessary source file(s)" - echo " -eo, --extract-only stop after downloading and extracting source file(s)" - echo " -utd, --up-to-date report whether the built package is up to date, then exit" - echo " -us, --update-signature update signature of Pkgfile and sources, do not build" - echo " -cs, --check-signature verify the signatures, do not build" - echo " -if, --ignore-footprint build package without checking footprint" - echo " -in, --ignore-new build package, ignoring new files in a footprint mismatch" - echo " -is, --ignore-signature build package without checking signature" - echo " -uf, --update-footprint update footprint using result from last build" - echo " -rs, --refresh-signature create new signature and keep existing sha256 checksums" + echo "options: (highest to lowest precedence)" + echo " -h, --help print help and exit" + echo " -v, --version print version and exit" + echo " -cf, --config-file use alternative configuration file" echo " -sk, --secret-key use to sign the port" echo " -pk, --public-key check the port signature using public-key " + echo " -rs, --refresh-signature create new signature based on existing sha256 checksums" + echo " -utd, --up-to-date report whether the built package is up to date, then exit" + echo " -f, --force override timestamp check, build package or update footprint anyway" + echo " -uf, --update-footprint update footprint using result from last build" + echo " -do, --download-only stop after downloading all the necessary source file(s)" + echo " -cs, --check-signature stop after verifying the signatures of all downloaded sources" + echo " -us, --update-signature update signature of Pkgfile and sources, do not build" + echo " -is, --ignore-signature build package without checking signature" + echo " -eo, --extract-only stop after downloading and extracting source file(s)" echo " -ns, --no-strip do not strip executable binaries or libraries" - echo " -f, --force build package even if it appears to be up to date" echo " -kw, --keep-work keep temporary working directory" - echo " -cf, --config-file use alternative configuration file" - echo " -v, --version print version and exit" - echo " -h, --help print help and exit" + echo " -if, --ignore-footprint build package without checking footprint" + echo " -in, --ignore-new build package, ignoring new files in a footprint mismatch" + echo " -i, --install build and install package" + echo " -u, --upgrade build and upgrade package" } validate_pkgfile() { # called from within PKGMK_ROOT @@ -333,8 +329,8 @@ check_pkg_mtime() { # can be called even if some sources are missing if [ -f "$pkg_dir$package" ]; then utd=1 - while [ $li -lt ${#_local_[@]} ] && [ "$utd" = 1 ]; do - [ ! -e "${_local_[$li]}" ] || \ + while (( li < ${#_local_[@]} )) && [ "$utd" = 1 ]; do + [ ! -e "${_local_[li]}" ] || \ [ "$pkg_dir$package" -nt "$(realpath "${_local_[$li]}")" ] || utd=0 li=$(( li+1 )) done @@ -347,7 +343,7 @@ check_pkg_mtime() { # can be called even if some sources are missing fetch_url() { local u="$1"; local h="$2"; local finished=0; local giturl tag CLONE_ARGS - local REPO SAVE_AS OCONTINUE OOUT; local m=0 + local SAVE_AS REPO OCONTINUE OOUT; local m=0 if [[ "$u" =~ ^__git__ ]]; then # git must be installed in order to obtain such a source @@ -380,12 +376,12 @@ fetch_url() { OOUT="-L -# --fail --ftp-pasv --retry 3 --retry-delay 3 $PKGMK_CURL_OPTIONS -o" ;; - *) SAVE_AS="/bin/false" ;; + *) SAVE_AS="false" ;; esac # # start with the mirrors defined in pkgmk.conf, then go to the url found in the Pkgfile - while [ $m -le ${#PKGMK_SOURCE_MIRRORS[@]} ] && [ $finished = 0 ] \ - && [[ ! $SAVE_AS =~ false$ ]]; do + while (( m <= ${#PKGMK_SOURCE_MIRRORS[@]} )) && [ $finished = 0 ] \ + && [ "$SAVE_AS" != "false" ]; do [ "${PKGMK_SOURCE_MIRRORS[m]}" = "" ] && um=$u || \ { REPO=${PKGMK_SOURCE_MIRRORS[m]%/}; um=$REPO/${u##*/}; } m=$(( m+1 )) @@ -460,11 +456,11 @@ check_signature() { # called from $PKGMK_ROOT in the case "when"="pre-Pkgfile", local reqfiles=(Pkgfile); local s=0; local when="$1"; local SIGNIFY_ARGS=(-C -x "$PKGMK_ROOT/.signature") - [ "$PKGMK_PUBLICKEY" ] || PKGMK_PUBLICKEY=$(repo_key public) + [ "$PKGMK_PUBLICKEY" ] || PKGMK_PUBLICKEY=$(get_repo_key public) if [ -f "$PKGMK_ROOT/.signature" ]; then [ "$when" = "pre-Pkgfile" ] || reqfiles=(.footprint) - while [ "$when" = "pre-build" ] && [ "$s" -lt ${#_local_[@]} ]; do - [[ "${source[$s]}" =~ ^__git__ ]] || reqfiles+=("${_local_[$s]}") + while [ "$when" = "pre-build" ] && (( s < ${#_local_[@]} )); do + [[ "${source[s]}" =~ ^__git__ ]] || reqfiles+=("${_local_[s]}") s=$(( s+1 )) done for FILE in "${reqfiles[@]}"; do @@ -478,7 +474,7 @@ check_signature() { # called from $PKGMK_ROOT in the case "when"="pre-Pkgfile", fi } -repo_key() { +get_repo_key() { local typ="${1:0:3}" for key in "/etc/ports/*.$typ" "$HOME/.ssh/*.$typ"; do [ -e "$key" ] || continue @@ -491,13 +487,13 @@ make_signature() { local ordered si pub [ -w "$PKGMK_ROOT/.signature" ] || { error ".signature not writable."; return $E_DIRPERM; } - [ "$PKGMK_PRIVATEKEY" ] || PKGMK_PRIVATEKEY="$(repo_key secret)" + [ "$PKGMK_PRIVATEKEY" ] || PKGMK_PRIVATEKEY="$(get_repo_key secret)" [ -r "$PKGMK_PRIVATEKEY" ] && \ pub="/etc/ports/$(basename -s ".sec" "$PKGMK_PRIVATEKEY").pub" || \ { error "No suitable secret key found. Specify one explicitly with '-sk'."; return $E_SIGNATURE; } - # distinguish between creating .signature anew, vs. refreshing an existing manifest + # create a new .signature, or refresh an existing manifest? case "$1" in new) [ -e "$PKGMK_ROOT/.footprint" ] || \ @@ -552,7 +548,7 @@ error() { ## Now ensure that they cannot be overwritten when sourcing Pkgfile ## readonly -f main info warning error print_help parse_options validate_pkgfile \ check_reqvars check_pkg_mtime fetch_url cat_footprint check_footprint \ - make_signature repo_key check_signature parse_signify_output cleanup_work + make_signature get_repo_key check_signature parse_signify_output cleanup_work trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM export LC_ALL=C.UTF-8