From 87b641814f794ffb927c81e04e7727389541270e Mon Sep 17 00:00:00 2001 From: lare Date: Tue, 19 Mar 2024 10:03:16 +0100 Subject: [PATCH] run shellcheck on helper scripts fmt-my-stuff: #3595 squash-my-commits: __future__ fix shellcheck warnings on fmt-my-stuff and squash-my-commits --- check-pol | 4 ++-- check-pol2 | 4 ++-- fmt-my-stuff | 5 ++++- squash-my-commits | 14 +++++--------- .../fix-infrastructure-objects | 8 ++++---- 5 files changed, 17 insertions(+), 18 deletions(-) rename fix-infrastructure-objects => utils/fix-infrastructure-objects (87%) diff --git a/check-pol b/check-pol index f76fc8a74..7768ad374 100755 --- a/check-pol +++ b/check-pol @@ -11,8 +11,8 @@ BASE="$(readlink -f "$0" 2>/dev/null || python -c 'import os,sys;print(os.path.r BASE="$(dirname "$BASE")" cd "$BASE" || exit 1 -git diff --name-only $1 | while IFS='/' read -ra LINE; do +git diff --name-only "$1" | while IFS='/' read -ra LINE; do if [[ "${LINE[0]}" = "data" && -n "${LINE[2]}" ]]; then - utils/schema-check/dn42-schema.py -v policy ${LINE[1]} ${LINE[2]} $2 + utils/schema-check/dn42-schema.py -v policy "${LINE[1]}" "${LINE[2]}" "$2" fi done diff --git a/check-pol2 b/check-pol2 index b34804b6e..fe1e62cc4 100755 --- a/check-pol2 +++ b/check-pol2 @@ -11,8 +11,8 @@ BASE="$(readlink -f "$0" 2>/dev/null || python -c 'import os,sys;print(os.path.r BASE="$(dirname "$BASE")" cd "$BASE" || exit 1 -git diff --name-only $1 | while IFS='/' read -ra LINE; do +git diff --name-only "$1" | while IFS='/' read -ra LINE; do if [[ "${LINE[0]}" = "data" && -n "${LINE[2]}" ]]; then - utils/schema-check/dn42_schema_local.py -v policy ${LINE[1]} ${LINE[2]} $2 + utils/schema-check/dn42_schema_local.py -v policy "${LINE[1]}" "${LINE[2]}" "$2" fi done diff --git a/fmt-my-stuff b/fmt-my-stuff index a7b44ac1b..5942d8deb 100755 --- a/fmt-my-stuff +++ b/fmt-my-stuff @@ -9,4 +9,7 @@ fi BASE="$(readlink -f "$0" 2>/dev/null || python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' "$0")" BASE="$(dirname "$BASE")" -grep -lrE "(\s|:)$1(\s|\$)" "$BASE/data/" | while read line; do utils/schema-check/dn42-schema.py fmt -i "$line"; done +grep -lrE "(\s|:)$1(\s|\$)" "$BASE/data/" | while read -r line; do + utils/schema-check/dn42-schema.py fmt -i "$line" +done + diff --git a/squash-my-commits b/squash-my-commits index 93384dc8b..4ccd57c27 100755 --- a/squash-my-commits +++ b/squash-my-commits @@ -68,8 +68,7 @@ done ########################################################################## # check for dn42registry remote, and add if missing -git remote -v | grep dn42registry > /dev/null 2>&1 -if [ "$?" -ne 0 ] +if ! git remote -v | grep dn42registry > /dev/null 2>&1 then # was the URL specified directly ? @@ -81,8 +80,7 @@ then if [ -z "$reg_proto" ] then # if the proto wasn't forced, try to guess it - git remote -v | grep 'https' > /dev/null 2>&1 - if [ $? -eq 0 ] + if git remote -v | grep 'https' > /dev/null 2>&1 then reg_proto='https' else @@ -112,8 +110,7 @@ fi # ensure the local branch is up to date echo "Fetching dn42registry master" -git fetch dn42registry master -if [ $? -ne 0 ] +if ! git fetch dn42registry master then echo 'ERROR: Failed to fetch registry master branch' echo 'Hint: you can use --ssh/--https to force use of ssh or https' @@ -123,8 +120,7 @@ then fi # find number of local commits -count=$(git rev-list --count HEAD ^dn42registry/master) -if [ $? -ne 0 ] +if ! count=$(git rev-list --count HEAD ^dn42registry/master) then echo "ERROR: Failed to find the number of local commits" echo "Please report this as a bug to the registry maintainters" @@ -160,7 +156,7 @@ $(git log --oneline HEAD ^dn42registry/master)" # and finally squash git reset --soft dn42registry/master -git commit $do_sign -m "$comment" +git commit "$do_sign" -m "$comment" # show what happened echo '---' diff --git a/fix-infrastructure-objects b/utils/fix-infrastructure-objects similarity index 87% rename from fix-infrastructure-objects rename to utils/fix-infrastructure-objects index 6d0f765bd..e8810a172 100755 --- a/fix-infrastructure-objects +++ b/utils/fix-infrastructure-objects @@ -14,8 +14,8 @@ fix_dns() { { set -e echo "domain: ${DST}" - cat "${TMP}" | grep -E '^(remarks):' || true - cat "data/dns/${SRC}" | grep '^nserver:' | tr -s " " | cut -d' ' -f2 | sort | uniq | xargs -i echo 'nserver: {}' + grep -E '^(remarks):' "${TMP}" || true + grep '^nserver:' "data/dns/${SRC}" | tr -s " " | cut -d' ' -f2 | sort | uniq | xargs -I{} echo 'nserver: {}' drill -t "${DST}" "@${DS_NSERVER}" DNSKEY -s | grep sha256 | cut -d: -f2 | sed -E 's/^ [^\t ]+\t900\tIN\tDS\t/ds-rdata: /g' | grep -E "${KSK_PATTERN}" echo 'org: ORG-DN42' echo 'mnt-by: DN42-MNT' @@ -35,7 +35,7 @@ fix_inetnum() { sed -r -i '/^(nserver|ds-rdata|status|org|policy|mnt-by|source|admin-c|tech-c):.*$/d' "data/${CLASS}/${DST}" { set -e - cat "data/dns/${SRC}" | grep '^nserver:' | tr -s " " | cut -d' ' -f2 | sort | uniq | xargs -i echo 'nserver: {}' + grep '^nserver:' "data/dns/${SRC}" | tr -s " " | cut -d' ' -f2 | sort | uniq | xargs -I{} echo 'nserver: {}' drill -t "${DNS_NAME}" "@${DS_NSERVER}" DNSKEY -s | grep sha256 | cut -d: -f2 | sed -E 's/^ [^\t ]+\t900\tIN\tDS\t/ds-rdata: /g' | grep -E "${KSK_PATTERN}" echo 'status: ALLOCATED' echo "policy: ${POLICY}" @@ -54,7 +54,7 @@ fix_dns_ds_only() { { set -e echo "domain: ${DST}" - cat "${TMP}" | grep -E '^(nserver|remarks):' || true + grep -E '^(nserver|remarks):' "${TMP}" || true drill -t "${DST}" "@${DS_NSERVER}" DNSKEY -s | grep sha256 | cut -d: -f2 | sed -E 's/^ [^\t ]+\t900\tIN\tDS\t/ds-rdata: /g' | grep -E "${KSK_PATTERN}" echo 'org: ORG-DN42' echo 'mnt-by: DN42-MNT'