From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0D70915ACFB for ; Sun, 9 Apr 2023 06:52:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0AB44E0843; Sun, 9 Apr 2023 06:52:11 +0000 (UTC) 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) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C7531E0843 for ; Sun, 9 Apr 2023 06:52:10 +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 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A0A4C3410CA for ; Sun, 9 Apr 2023 06:52:09 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C3780A35 for ; Sun, 9 Apr 2023 06:52:07 +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: <1681023094.63e1382127d5448f39771e22d0ab0a4e2f8b6d38.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: 63e1382127d5448f39771e22d0ab0a4e2f8b6d38 X-VCS-Branch: master Date: Sun, 9 Apr 2023 06:52:07 +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: b3cc80aa-35df-414f-bc1a-d9c11c348881 X-Archives-Hash: 972a1e36be6a1674a6244083d5ec7e00 commit: 63e1382127d5448f39771e22d0ab0a4e2f8b6d38 Author: Sam James gentoo org> AuthorDate: Wed Mar 29 20:11:24 2023 +0000 Commit: Sam James gentoo 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 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 # 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}"