commit: 63e1382127d5448f39771e22d0ab0a4e2f8b6d38 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Wed Mar 29 20:11:24 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun Apr 9 06:51:34 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=63e13821
emerge-webrsync: use bash tests; expand conditionals We're using bash, so let's use proper bash tests with all of the behaviour we know & love. Expand conditionals too to make things a bit easier to read. Signed-off-by: Sam James <sam <AT> gentoo.org> bin/emerge-webrsync | 63 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync index 7fb98900d..4b982a1c1 100755 --- a/bin/emerge-webrsync +++ b/bin/emerge-webrsync @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 1999-2014 Gentoo Foundation +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # Author: Karl Trygve Kalleberg <[email protected]> # Rewritten from the old, Perl-based emerge-webrsync script @@ -38,7 +38,7 @@ argv0=$0 # Use portageq from the same directory/prefix as the current script, so # that we don't have to rely on PATH including the current EPREFIX. scriptpath=${BASH_SOURCE[0]} -if [ -x "${scriptpath%/*}/portageq" ]; then +if [[ -x "${scriptpath%/*}/portageq" ]]; then portageq=${scriptpath%/*}/portageq elif type -P portageq > /dev/null ; then portageq=portageq @@ -67,7 +67,7 @@ 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 +if [[ -n "${PORTAGE_NICENESS}" ]]; then renice ${PORTAGE_NICENESS} $$ > /dev/null fi @@ -81,10 +81,11 @@ if [[ ${webrsync_gpg} -eq 1 ]]; then wecho "FEATURES=webrsync-gpg is deprecated, see the make.conf(5) man page." fi -if [[ -n ${PORTAGE_TEMP_GPG_DIR} ]] || - has $(__repo_attr "${repo_name}" sync-webrsync-verify-signature | - LC_ALL=C tr '[:upper:]' '[:lower:]') true yes; then +repo_has_webrsync_verify=$( + has $(__repo_attr "${repo_name}" sync-webrsync-verify-signature | LC_ALL=C tr '[:upper:]' '[:lower:]') true yes +) +if [[ -n ${PORTAGE_TEMP_GPG_DIR} ]] || [[ ${repo_has_webrsync_verify} -eq 1 ]]; then # If FEATURES=webrsync-gpg is enabled then allow direct emerge-webrsync # calls for backward compatibility (this triggers a deprecation warning # above). Since direct emerge-webrsync calls do not use gemato for secure @@ -103,8 +104,8 @@ else fi [[ -n ${PORTAGE_TEMP_GPG_DIR} ]] && PORTAGE_GPG_DIR=${PORTAGE_TEMP_GPG_DIR} -if [ ${WEBSYNC_VERIFY_SIGNATURE} != 0 -a -z "${PORTAGE_GPG_DIR}" ]; then - eecho "please set PORTAGE_GPG_DIR in make.conf" +if [[ ${WEBSYNC_VERIFY_SIGNATURE} != 0 && -z "${PORTAGE_GPG_DIR}" ]]; then + eecho "Please set PORTAGE_GPG_DIR in make.conf!" exit 1 fi @@ -154,7 +155,7 @@ get_utc_second_from_string() { get_portage_timestamp() { local portage_current_timestamp=0 - if [ -f "${repo_location}/metadata/timestamp.x" ]; then + if [[ -f "${repo_location}/metadata/timestamp.x" ]]; then portage_current_timestamp=$(cut -f 1 -d " " "${repo_location}/metadata/timestamp.x" ) fi @@ -166,9 +167,9 @@ fetch_file() { local FILE="$2" local opts - if [ "${FETCHCOMMAND/wget/}" != "${FETCHCOMMAND}" ]; then + if [[ "${FETCHCOMMAND/wget/}" != "${FETCHCOMMAND}" ]]; then opts="--continue $(nvecho -q)" - elif [ "${FETCHCOMMAND/curl/}" != "${FETCHCOMMAND}" ]; then + elif [[ "${FETCHCOMMAND/curl/}" != "${FETCHCOMMAND}" ]]; then opts="--continue-at - $(nvecho -s -f)" else rm -f "${DISTDIR}/${FILE}" @@ -196,9 +197,9 @@ check_file_digest() { if type -P md5sum > /dev/null; then local md5sum_output=$(md5sum "${file}") local digest_content=$(< "${digest}") - [ "${md5sum_output%%[[:space:]]*}" = "${digest_content%%[[:space:]]*}" ] && r=0 + [[ "${md5sum_output%%[[:space:]]*}" = "${digest_content%%[[:space:]]*}" ]] && r=0 elif type -P md5 > /dev/null; then - [ "$(md5 -q "${file}")" == "$(cut -d ' ' -f 1 "${digest}")" ] && r=0 + [[ "$(md5 -q "${file}")" == "$(cut -d ' ' -f 1 "${digest}")" ]] && r=0 else eecho "cannot check digest: no suitable md5/md5sum binaries found" fi @@ -212,7 +213,7 @@ check_file_signature() { local r=1 local gnupg_status line - if [ ${WEBSYNC_VERIFY_SIGNATURE} != 0 ]; then + if [[ ${WEBSYNC_VERIFY_SIGNATURE} != 0 ]]; then __vecho "Checking signature ..." if type -P gpg > /dev/null; then @@ -304,7 +305,7 @@ sync_local() { fi local post_sync=${PORTAGE_CONFIGROOT}etc/portage/bin/post_sync - [ -x "${post_sync}" ] && "${post_sync}" + [[ -x "${post_sync}" ]] && "${post_sync}" # --quiet suppresses output if there are no relevant news items has news ${FEATURES} && emerge --check-news --quiet @@ -344,13 +345,13 @@ do_snapshot() { local digest="${file}.md5sum" local signature="${file}.gpgsig" - if [ -s "${DISTDIR}/${file}" -a -s "${DISTDIR}/${digest}" -a -s "${DISTDIR}/${signature}" ] ; then + if [[ -s "${DISTDIR}/${file}" && -s "${DISTDIR}/${digest}" && -s "${DISTDIR}/${signature}" ]] ; then check_file_digest "${DISTDIR}/${digest}" "${DISTDIR}/${file}" && \ check_file_signature "${DISTDIR}/${signature}" "${DISTDIR}/${file}" && \ have_files=1 fi - if [ ${have_files} -eq 0 ] ; then + if [[ ${have_files} -eq 0 ]] ; then fetch_file "${mirror}/snapshots/${digest}" "${digest}" && \ fetch_file "${mirror}/snapshots/${signature}" "${signature}" && \ fetch_file "${mirror}/snapshots/${file}" "${file}" && \ @@ -364,12 +365,12 @@ do_snapshot() { # we want to try and retrieve # from a different mirror # - if [ ${have_files} -eq 1 ]; then + if [[ ${have_files} -eq 1 ]]; then __vecho "Getting snapshot timestamp ..." local snapshot_timestamp=$(get_snapshot_timestamp "${DISTDIR}/${file}") - if [ ${ignore_timestamp} == 0 ]; then - if [ ${snapshot_timestamp} -lt $(get_portage_timestamp) ]; then + if [[ ${ignore_timestamp} == 0 ]]; then + if [[ ${snapshot_timestamp} -lt $(get_portage_timestamp) ]]; then wecho "portage is newer than snapshot" have_files=0 fi @@ -380,8 +381,8 @@ do_snapshot() { # Check that this snapshot # is what it claims to be ... # - if [ ${snapshot_timestamp} -lt ${utc_seconds} ] || \ - [ ${snapshot_timestamp} -gt $((${utc_seconds}+ 2*86400)) ]; then + if [[ ${snapshot_timestamp} -lt ${utc_seconds} || \ + ${snapshot_timestamp} -gt $((${utc_seconds}+ 2*86400)) ]]; then wecho "snapshot timestamp is not in acceptable period" have_files=0 @@ -389,7 +390,7 @@ do_snapshot() { fi fi - if [ ${have_files} -eq 1 ]; then + if [[ ${have_files} -eq 1 ]]; then break else # @@ -399,10 +400,10 @@ do_snapshot() { fi done - [ ${have_files} -eq 1 ] && break + [[ ${have_files} -eq 1 ]] && break done - if [ ${have_files} -eq 1 ]; then + if [[ ${have_files} -eq 1 ]]; then sync_local "${DISTDIR}/${file}" && r=0 else __vecho "${date} snapshot was not found" @@ -437,7 +438,7 @@ do_latest_snapshot() { # Daily snapshots are created at 00:45 and are not # available until after 01:00. Don't waste time trying # to fetch a snapshot before it's been created. - if [ ${start_hour} -lt 1 ] ; then + if [[ ${start_hour} -lt 1 ]] ; then (( start_time -= 86400 )) fi local snapshot_date=$(get_date_part ${start_time} "%Y%m%d") @@ -453,15 +454,15 @@ do_latest_snapshot() { snapshot_date=$(get_date_part ${snapshot_date_seconds} "%Y%m%d") timestamp_problem="" - if [ ${timestamp_difference} -eq 0 ]; then + if [[ ${timestamp_difference} -eq 0 ]]; then timestamp_problem="is identical to" - elif [ ${timestamp_difference} -lt ${min_time_diff} ]; then + elif [[ ${timestamp_difference} -lt ${min_time_diff} ]]; then timestamp_problem="is possibly identical to" - elif [ ${approx_snapshot_time} -lt ${existing_timestamp} ] ; then + elif [[ ${approx_snapshot_time} -lt ${existing_timestamp} ]] ; then timestamp_problem="is newer than" fi - if [ -n "${timestamp_problem}" ]; then + if [[ -n "${timestamp_problem}" ]]; then ewarn "Latest snapshot date: ${snapshot_date}" ewarn ewarn "Approximate snapshot timestamp: ${approx_snapshot_time}" @@ -543,7 +544,7 @@ main() { cd "${TMPDIR}" || exit 1 ${keep} || DISTDIR=${TMPDIR} - [ ! -d "${DISTDIR}" ] && mkdir -p "${DISTDIR}" + [[ ! -d "${DISTDIR}" ]] && mkdir -p "${DISTDIR}" if ${keep} && [[ ! -w ${DISTDIR} ]] ; then eecho "DISTDIR is not writable: ${DISTDIR}"
