From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id AF3E7158128 for ; Tue, 17 Jun 2025 03:01:12 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 9BCC63426A0 for ; Tue, 17 Jun 2025 03:01:12 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id A97FD110509; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 94338110509 for ; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3FCE634269E for ; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CC62B29EF for ; Tue, 17 Jun 2025 03:00:49 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1750129242.b623ca324d08cdeea6b5ac638c2b1a3a15ba618e.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/emerge-webrsync X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: b623ca324d08cdeea6b5ac638c2b1a3a15ba618e X-VCS-Branch: master Date: Tue, 17 Jun 2025 03:00:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 3fe0fd7e-61e9-45cc-b2e6-27c1dc06b52b X-Archives-Hash: 9806c5aa6c74aea7aac17a67e3c3ddb7 commit: b623ca324d08cdeea6b5ac638c2b1a3a15ba618e Author: Kerin Millar plushkava net> AuthorDate: Tue Jun 17 01:20:54 2025 +0000 Commit: Sam James gentoo org> CommitDate: Tue Jun 17 03:00:42 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b623ca32 emerge-webrsync: have function declarations precede code Refrain from interspersing function declarations with code that isn't function-scoped. Instead, ensure that the function declarations precede all other commands. Also, have the declarations of both the main() and usage() functions precede the others. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/emerge-webrsync | 286 ++++++++++++++++++++++++++-------------------------- 1 file changed, 143 insertions(+), 143 deletions(-) diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync index 89b33553b7..32656a09d6 100755 --- a/bin/emerge-webrsync +++ b/bin/emerge-webrsync @@ -24,87 +24,96 @@ # gpg --homedir /etc/portage/gnupg --edit-key ${KEY_ID} trust # -# Opportunistically use gentoo-functions for nicer output -functions_script="${EPREFIX}/lib/gentoo/functions.sh" -source "${functions_script}" || { - echo "${argv0}: Could not source ${functions_script}!" 1>&2 - - ebegin() { - printf '%s*%s %s ... ' "${GOOD}" "${NORMAL}" "$*" - } - - eend() { - local r=${1:-0} - shift +main() { + local revert_date arg v - if [[ $r -eq 0 ]] ; then - printf '[ %sok%s ]\n' "${GOOD}" "${NORMAL}" - else - printf '%s [ %s!!%s ]\n' "$*" "${BAD}" "${NORMAL}" - fi - return "${r}" - } + for arg in "$@" ; do + v=${arg#*=} + case ${arg} in + -h|--help) usage ;; + -k|--keep) keep=true ;; + -q|--quiet) PORTAGE_QUIET=1 ;; + -v|--verbose) unset PORTAGE_QUIET ;; + -x|--debug) do_debug=1 ;; + --revert=*) revert_date=${v} ;; + --no-pgp-verify) no_pgp_verify=1 ;; + *) usage "Invalid option '${arg}'" ;; + esac + done - einfo() { - echo "${argv0##*/}: $*" - } + handle_pgp_setup - ewarn() { - echo "${argv0##*/}: warning: $*" 1>&2 - } + if [[ ! -d ${repo_location} ]]; then + mkdir -p "${repo_location}" || die - eerror() { - echo "${argv0##*/}: error: $*" 1>&2 - } + if contains_word usersync "${FEATURES}"; then + chown "${PORTAGE_USERNAME}":"${PORTAGE_GRPNAME}" "${repo_location}" || die + fi + fi -} + if [[ ! -w ${repo_location} ]] ; then + die "Repository '${repo_name}' is not writable: ${repo_location}" + fi -# Only echo if in normal mode -vvecho() { [[ ${PORTAGE_QUIET} != 1 ]] && echo "$@" ; } -# Only echo if in quiet mode -nvecho() { [[ ${PORTAGE_QUIET} == 1 ]] && echo "$@" ; } + [[ -d ${PORTAGE_TMPDIR}/portage ]] || mkdir -p "${PORTAGE_TMPDIR}/portage" -# Unfortunately, gentoo-functions doesn't yet have a die() (bug #878505) -die() { - eerror "$@" - exit 1 -} + # Create a temporary directory whose subsequent removal is guaranteed. + tmpdir= + trap 'rm -rf -- "${tmpdir}"' EXIT + tmpdir=$(mktemp -d -- "${PORTAGE_TMPDIR}/portage/webrsync.XXXXXX") \ + && cd -- "${tmpdir}" \ + || exit -argv0=$0 + ${keep} || DISTDIR=${tmpdir} + [[ ! -d "${DISTDIR}" ]] && mkdir -p "${DISTDIR}" -# Use emerge and portageq from the same directory/prefix as the current script, -# so that we don't have to rely on PATH including the current EPREFIX. -emerge=$(PATH="${BASH_SOURCE[0]%/*}:${PATH}" type -P emerge) -[[ -n ${emerge} ]] || die "could not find 'emerge'; aborting" -portageq=$(PATH="${BASH_SOURCE[0]%/*}:${PATH}" type -P portageq) -[[ -n ${portageq} ]] || die "could not find 'portageq'; aborting" + if ${keep} && [[ ! -w ${DISTDIR} ]] ; then + die "DISTDIR is not writable: ${DISTDIR}" + fi -eval "$("${portageq}" envvar -v DISTDIR EPREFIX FEATURES \ - FETCHCOMMAND GENTOO_MIRRORS \ - PORTAGE_BIN_PATH PORTAGE_CONFIGROOT PORTAGE_GPG_DIR \ - PORTAGE_NICENESS PORTAGE_REPOSITORIES PORTAGE_RSYNC_EXTRA_OPTS \ - PORTAGE_RSYNC_OPTS PORTAGE_TEMP_GPG_DIR PORTAGE_TMPDIR \ - PORTAGE_USERNAME PORTAGE_GRPNAME \ - USERLAND http_proxy https_proxy ftp_proxy)" -export http_proxy https_proxy ftp_proxy + # This is a sanity check to help prevent people like funtoo users + # from accidentally wiping out their git tree. + if [[ -n ${repo_sync_type} && ${repo_sync_type} != rsync && ${repo_sync_type} != webrsync ]] ; then + eerror "The current sync-type attribute of repository 'gentoo' is not set to 'rsync' or 'webrsync':" + eerror + eerror " sync-type=${repo_sync_type}" + eerror + eerror "If you intend to use emerge-webrsync then please" + eerror "adjust sync-type and sync-uri attributes to refer to rsync." + eerror "emerge-webrsync exiting due to abnormal sync-type setting." + die + fi -source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1 + [[ ${do_debug} -eq 1 ]] && set -x -repo_name=gentoo -repo_location=$(__repo_attr "${repo_name}" location) -if [[ -z ${repo_location} ]]; then - die "Repository '${repo_name}' not found" -fi -repo_sync_type=$(__repo_attr "${repo_name}" sync-type) + if [[ -n ${revert_date} ]] ; then + emaint revisions --purgerepos="${repo_name}" + do_snapshot 1 "${revert_date}" + else + do_latest_snapshot + fi +} -# If PORTAGE_NICENESS is overriden via the env then it will -# still pass through the portageq call and override properly. -if [[ -n "${PORTAGE_NICENESS}" ]]; then - renice "${PORTAGE_NICENESS}" $$ > /dev/null -fi +usage() { + cat <<-EOF + Usage: $0 [options] -do_debug=0 -keep=false + Options: + --revert=yyyymmdd Revert to snapshot + --no-pgp-verify Disable PGP verification of snapshot + -k, --keep Keep snapshots in DISTDIR (don't delete) + -q, --quiet Only output errors + -v, --verbose Enable verbose output (no-op) + -x, --debug Enable debug output + -h, --help This help screen (duh!) + EOF + if [[ -n $* ]] ; then + printf "\nError: %s\n" "$*" 1>&2 + exit 1 + else + exit 0 + fi +} handle_pgp_setup() { if [[ ${no_pgp_verify} ]]; then @@ -608,95 +617,86 @@ do_latest_snapshot() { done } -usage() { - cat <<-EOF - Usage: $0 [options] +# Opportunistically use gentoo-functions for nicer output +functions_script="${EPREFIX}/lib/gentoo/functions.sh" +source "${functions_script}" || { + echo "${argv0}: Could not source ${functions_script}!" 1>&2 - Options: - --revert=yyyymmdd Revert to snapshot - --no-pgp-verify Disable PGP verification of snapshot - -k, --keep Keep snapshots in DISTDIR (don't delete) - -q, --quiet Only output errors - -v, --verbose Enable verbose output (no-op) - -x, --debug Enable debug output - -h, --help This help screen (duh!) - EOF - if [[ -n $* ]] ; then - printf "\nError: %s\n" "$*" 1>&2 - exit 1 - else - exit 0 - fi -} + ebegin() { + printf '%s*%s %s ... ' "${GOOD}" "${NORMAL}" "$*" + } -main() { - local revert_date arg v + eend() { + local r=${1:-0} + shift - for arg in "$@" ; do - v=${arg#*=} - case ${arg} in - -h|--help) usage ;; - -k|--keep) keep=true ;; - -q|--quiet) PORTAGE_QUIET=1 ;; - -v|--verbose) unset PORTAGE_QUIET ;; - -x|--debug) do_debug=1 ;; - --revert=*) revert_date=${v} ;; - --no-pgp-verify) no_pgp_verify=1 ;; - *) usage "Invalid option '${arg}'" ;; - esac - done + if [[ $r -eq 0 ]] ; then + printf '[ %sok%s ]\n' "${GOOD}" "${NORMAL}" + else + printf '%s [ %s!!%s ]\n' "$*" "${BAD}" "${NORMAL}" + fi + return "${r}" + } - handle_pgp_setup + einfo() { + echo "${argv0##*/}: $*" + } - if [[ ! -d ${repo_location} ]]; then - mkdir -p "${repo_location}" || die + ewarn() { + echo "${argv0##*/}: warning: $*" 1>&2 + } - if contains_word usersync "${FEATURES}"; then - chown "${PORTAGE_USERNAME}":"${PORTAGE_GRPNAME}" "${repo_location}" || die - fi - fi + eerror() { + echo "${argv0##*/}: error: $*" 1>&2 + } - if [[ ! -w ${repo_location} ]] ; then - die "Repository '${repo_name}' is not writable: ${repo_location}" - fi +} - [[ -d ${PORTAGE_TMPDIR}/portage ]] || mkdir -p "${PORTAGE_TMPDIR}/portage" +# Only echo if in normal mode +vvecho() { [[ ${PORTAGE_QUIET} != 1 ]] && echo "$@" ; } +# Only echo if in quiet mode +nvecho() { [[ ${PORTAGE_QUIET} == 1 ]] && echo "$@" ; } - # Create a temporary directory whose subsequent removal is guaranteed. - tmpdir= - trap 'rm -rf -- "${tmpdir}"' EXIT - tmpdir=$(mktemp -d -- "${PORTAGE_TMPDIR}/portage/webrsync.XXXXXX") \ - && cd -- "${tmpdir}" \ - || exit +# Unfortunately, gentoo-functions doesn't yet have a die() (bug #878505) +die() { + eerror "$@" + exit 1 +} - ${keep} || DISTDIR=${tmpdir} - [[ ! -d "${DISTDIR}" ]] && mkdir -p "${DISTDIR}" +argv0=$0 - if ${keep} && [[ ! -w ${DISTDIR} ]] ; then - die "DISTDIR is not writable: ${DISTDIR}" - fi +# Use emerge and portageq from the same directory/prefix as the current script, +# so that we don't have to rely on PATH including the current EPREFIX. +emerge=$(PATH="${BASH_SOURCE[0]%/*}:${PATH}" type -P emerge) +[[ -n ${emerge} ]] || die "could not find 'emerge'; aborting" +portageq=$(PATH="${BASH_SOURCE[0]%/*}:${PATH}" type -P portageq) +[[ -n ${portageq} ]] || die "could not find 'portageq'; aborting" - # This is a sanity check to help prevent people like funtoo users - # from accidentally wiping out their git tree. - if [[ -n ${repo_sync_type} && ${repo_sync_type} != rsync && ${repo_sync_type} != webrsync ]] ; then - eerror "The current sync-type attribute of repository 'gentoo' is not set to 'rsync' or 'webrsync':" - eerror - eerror " sync-type=${repo_sync_type}" - eerror - eerror "If you intend to use emerge-webrsync then please" - eerror "adjust sync-type and sync-uri attributes to refer to rsync." - eerror "emerge-webrsync exiting due to abnormal sync-type setting." - die - fi +eval "$("${portageq}" envvar -v DISTDIR EPREFIX FEATURES \ + FETCHCOMMAND GENTOO_MIRRORS \ + PORTAGE_BIN_PATH PORTAGE_CONFIGROOT PORTAGE_GPG_DIR \ + PORTAGE_NICENESS PORTAGE_REPOSITORIES PORTAGE_RSYNC_EXTRA_OPTS \ + PORTAGE_RSYNC_OPTS PORTAGE_TEMP_GPG_DIR PORTAGE_TMPDIR \ + PORTAGE_USERNAME PORTAGE_GRPNAME \ + USERLAND http_proxy https_proxy ftp_proxy)" +export http_proxy https_proxy ftp_proxy - [[ ${do_debug} -eq 1 ]] && set -x +source "${PORTAGE_BIN_PATH}"/isolated-functions.sh || exit 1 - if [[ -n ${revert_date} ]] ; then - emaint revisions --purgerepos="${repo_name}" - do_snapshot 1 "${revert_date}" - else - do_latest_snapshot - fi -} +repo_name=gentoo +repo_location=$(__repo_attr "${repo_name}" location) +if [[ -z ${repo_location} ]]; then + die "Repository '${repo_name}' not found" +fi +repo_sync_type=$(__repo_attr "${repo_name}" sync-type) + +# If PORTAGE_NICENESS is overriden via the env then it will +# still pass through the portageq call and override properly. +if [[ -n "${PORTAGE_NICENESS}" ]]; then + renice "${PORTAGE_NICENESS}" $$ > /dev/null +fi + +do_debug=0 +keep=false main "$@"