From 9f63f860e0b902627305810ef3f715396c332a1c Mon Sep 17 00:00:00 2001 From: cmckee786 Date: Sat, 30 Aug 2025 17:19:27 -0400 Subject: [PATCH 1/5] general housekeeping and light refactors in logic --- scripts/binary-validation | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/binary-validation b/scripts/binary-validation index 08835d1..0cc3d81 100755 --- a/scripts/binary-validation +++ b/scripts/binary-validation @@ -1,19 +1,17 @@ #!/bin/bash -# binary-validator.sh v1.1.0 +# binary-validator.sh v1.2.0 # # Authored by: # github.com/cmckee786 # github.com/Kolkhis # # Targeting mdBook version v0.4.52 as of Aug, 2025 -# Only requests 5 latest release records, remove ?per_page=5 to -# fetch all from logic to request all records +# Only requests 5 latest release records, remove ?per_page=5 +# from API request (json-setup()) to fetch all records # # Requires mdBook semantic version input from command line -# For example 'binary-validation.sh v0.1.15' - -set -eo pipefail +# For example 'binary-validation.sh 0.1.15' declare MDBOOK_VERSION declare SKIP_DIGEST=0 @@ -42,9 +40,9 @@ usage() { the script when it is known the version does not support the digest check. Practical for testing or debug purposes. - -i Should be used when the mdBook version has an unknown/null digest check value. This option will - prompt the user whether to continue the download if it does not detect the sha digest. Practical - for local dev purposes. + -i Should be used to test whether the mdBook version has an unknown/null digest check value. + This option will prompt the user whether to continue the download if it does not detect the + sha digest. Practical for debug or local dev purposes. -h Display this help message. " @@ -69,7 +67,7 @@ if [ "$OPTIND" -gt "$#" ]; then exit 1 fi -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) if [[ -n "$1" && "$1" =~ $reg_pattern ]]; then MDBOOK_VERSION="$1" elif [[ ! "$1" =~ $reg_pattern ]]; then @@ -77,7 +75,7 @@ elif [[ ! "$1" =~ $reg_pattern ]]; then exit 1 fi -# If the mdbook version is pre-digest version (<0.4.52), ask for user validation +# If the mdbook version is pre-digest API version (<0.4.52), will ask for user validation interactive-download() { if [[ $INTERACTIVE -gt 0 ]]; then local -l choice @@ -86,7 +84,7 @@ interactive-download() { choice=${choice:-N} case $choice in y*) - printf "Proceeding with download.\n" + printf "Proceeding with extraction...\n" EXTRACT=1 ;; n*) @@ -99,7 +97,6 @@ interactive-download() { done else printf "Non-interactive download, proceeding...\n" - return 0 fi } @@ -148,6 +145,7 @@ binary_fetch() { fi } +# Designed such that any cases that function return 1 will still remove tar.gz if it was downloaded validation-decision() { local api_digest local zip_digest @@ -160,18 +158,18 @@ validation-decision() { printf "%2s %s\n" "ZIP:" "$zip" "API_DIGEST:" "$api_digest" printf "ZIP_DIGEST: %s\n\n" "$zip_digest" - if [[ $SKIP_DIGEST -eq 1 ]]; then + if [[ $SKIP_DIGEST == 1 ]]; then EXTRACT=1 - printf "Skipping digest check, fetching binary...\n" - elif [[ "$api_digest" == 'null' && $INTERACTIVE -eq 1 ]]; then + printf "Skipping digest check, extracting binary...\n" + elif [[ "$api_digest" == 'null' && $INTERACTIVE == 1 ]]; then printf "This version of mdBook (%s) pre-dates the SHA digest feature of the GitHub API and cannot be validated.\n" "$MDBOOK_VERSION" interactive-download || { - printf >&2 "Could not proceed with download.\n" + printf >&2 "Interactive-download function failed, could not proceed with download.\n" } - elif [[ "$api_digest" == "$zip_digest" && $INTERACTIVE -eq 1 ]]; then + elif [[ "$api_digest" == "$zip_digest" && $INTERACTIVE == 1 ]]; then printf "The mdBook binary has been successfully validated.\n" interactive-download || { - printf >&2 "Could not proceed with download.\n" + printf >&2 "Interactive-download function failed, could not proceed with download.\n" } elif [[ "$api_digest" == 'null' ]]; then printf "Digest could not be gathered from the API, likely an older version (<0.4.52).\nExiting..." @@ -185,9 +183,11 @@ validation-decision() { echo "$json" | jq '.' fi - if [[ $EXTRACT -eq 1 ]]; then + if [[ $EXTRACT -eq 1 && -e "$zip" ]]; then tar xfz "$zip" printf "Extracting binary for use...\nBinary is ready for use!" + else + printf "mdBook tar does not appear to exist...\nCleaning up..." fi [[ -e $zip ]] && rm -f "$zip" } From 3eeef46df86784594d4d509c88da81930021158d Mon Sep 17 00:00:00 2001 From: cmckee786 Date: Sat, 30 Aug 2025 17:20:54 -0400 Subject: [PATCH 2/5] fix: formatting --- scripts/binary-validation | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/binary-validation b/scripts/binary-validation index 0cc3d81..c6295f0 100755 --- a/scripts/binary-validation +++ b/scripts/binary-validation @@ -41,8 +41,8 @@ usage() { testing or debug purposes. -i Should be used to test whether the mdBook version has an unknown/null digest check value. - This option will prompt the user whether to continue the download if it does not detect the - sha digest. Practical for debug or local dev purposes. + This option will prompt the user whether to continue the download. Practical for debug or + local dev purposes. -h Display this help message. " @@ -54,7 +54,8 @@ while getopts "sih" option; do i) INTERACTIVE=1 ;; h) usage - exit;; + exit + ;; \?) printf >&2 "Unknown argument!\n./binary-validation.sh \$version [options] [-s][-i][-h]" exit 1 @@ -201,4 +202,3 @@ if [[ -n "$MDBOOK_VERSION" ]]; then else printf >&2 "MDBOOK_VERSION appears to be empty! Script requires a semantic version, for example: 0.4.52\n" fi - From 5f65e953ae378aaf092ab7195481797b1e642bc2 Mon Sep 17 00:00:00 2001 From: cmckee786 Date: Sat, 30 Aug 2025 17:23:04 -0400 Subject: [PATCH 3/5] fix: woopsie --- scripts/binary-validation | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/binary-validation b/scripts/binary-validation index c6295f0..e8834e6 100755 --- a/scripts/binary-validation +++ b/scripts/binary-validation @@ -1,6 +1,6 @@ #!/bin/bash -# binary-validator.sh v1.2.0 +# binary-validator v1.2.0 # # Authored by: # github.com/cmckee786 @@ -184,11 +184,11 @@ validation-decision() { echo "$json" | jq '.' fi - if [[ $EXTRACT -eq 1 && -e "$zip" ]]; then + if [[ $EXTRACT == 1 && -e "$zip" ]]; then tar xfz "$zip" printf "Extracting binary for use...\nBinary is ready for use!" else - printf "mdBook tar does not appear to exist...\nCleaning up..." + printf "mdBook tar does not appear to exist...\nCleaning up...\nExiting...\n" fi [[ -e $zip ]] && rm -f "$zip" } From 05cfb3b2d95ff0ecddef336661f596c2bb902d03 Mon Sep 17 00:00:00 2001 From: cmckee786 Date: Sat, 30 Aug 2025 17:46:18 -0400 Subject: [PATCH 4/5] fix: suffix removal --- scripts/binary-validation | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/binary-validation b/scripts/binary-validation index e8834e6..6aefd44 100755 --- a/scripts/binary-validation +++ b/scripts/binary-validation @@ -11,7 +11,7 @@ # from API request (json-setup()) to fetch all records # # Requires mdBook semantic version input from command line -# For example 'binary-validation.sh 0.1.15' +# For example 'binary-validation 0.1.15' declare MDBOOK_VERSION declare SKIP_DIGEST=0 @@ -33,7 +33,7 @@ usage() { USAGE - ./binary-validation.sh \$version [options] [-s][-i][-h] + ./binary-validation \$version [options] [-s][-i][-h] OPTIONS -s Skips GitHub API sha256 digest check logic, usually used with a non-interactive call of @@ -57,7 +57,7 @@ while getopts "sih" option; do exit ;; \?) - printf >&2 "Unknown argument!\n./binary-validation.sh \$version [options] [-s][-i][-h]" + printf >&2 "Unknown argument!\n./binary-validation \$version [options] [-s][-i][-h]" exit 1 ;; esac From 4c12d877ec12710eb70bfe8ef85bc30d4ef9fa3a Mon Sep 17 00:00:00 2001 From: cmckee786 Date: Sat, 30 Aug 2025 18:32:28 -0400 Subject: [PATCH 5/5] fix: remove redundant condtions, clarifications --- scripts/binary-validation | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/binary-validation b/scripts/binary-validation index 6aefd44..5e794e6 100755 --- a/scripts/binary-validation +++ b/scripts/binary-validation @@ -45,7 +45,7 @@ usage() { local dev purposes. -h Display this help message. - " + \n" } while getopts "sih" option; do @@ -57,14 +57,14 @@ while getopts "sih" option; do exit ;; \?) - printf >&2 "Unknown argument!\n./binary-validation \$version [options] [-s][-i][-h]" + printf >&2 "Unknown argument!\n./binary-validation \$version [options] [-s][-i][-h]\n" exit 1 ;; esac done if [ "$OPTIND" -gt "$#" ]; then - echo "Missing mdBook version!" + printf "Missing mdBook version!\n" exit 1 fi @@ -72,12 +72,12 @@ shift $((OPTIND - 1)) if [[ -n "$1" && "$1" =~ $reg_pattern ]]; then MDBOOK_VERSION="$1" elif [[ ! "$1" =~ $reg_pattern ]]; then - printf >&2 "Unrecognized mdBook version pattern, script accepts semantic version for example: 0.4.52" + printf >&2 "Unrecognized mdBook version pattern, script accepts semantic version for example: 0.4.52\n" exit 1 fi # If the mdbook version is pre-digest API version (<0.4.52), will ask for user validation -interactive-download() { +interactive() { if [[ $INTERACTIVE -gt 0 ]]; then local -l choice until [[ $choice =~ ^[Yy|nN]$ ]]; do @@ -96,8 +96,6 @@ interactive-download() { ;; esac done - else - printf "Non-interactive download, proceeding...\n" fi } @@ -121,7 +119,7 @@ json_setup() { jq "$jquery")" || { printf "Something went wrong with the GH API request. Consider adding set -x flag.\n" 1>&2 - return 1 + exit 1 } # TODO Implement GH TOKEN in the future? @@ -142,7 +140,7 @@ binary_fetch() { printf "\n" else printf "\nThe processed JSON record appears to be empty, queried version may not exist...\nExiting..." - return 1 + exit 1 fi } @@ -164,13 +162,13 @@ validation-decision() { printf "Skipping digest check, extracting binary...\n" elif [[ "$api_digest" == 'null' && $INTERACTIVE == 1 ]]; then printf "This version of mdBook (%s) pre-dates the SHA digest feature of the GitHub API and cannot be validated.\n" "$MDBOOK_VERSION" - interactive-download || { - printf >&2 "Interactive-download function failed, could not proceed with download.\n" + interactive || { + printf >&2 "Interactive function failed, could not proceed with extraction.\n" } elif [[ "$api_digest" == "$zip_digest" && $INTERACTIVE == 1 ]]; then printf "The mdBook binary has been successfully validated.\n" - interactive-download || { - printf >&2 "Interactive-download function failed, could not proceed with download.\n" + interactive || { + printf >&2 "Interactive function failed, could not proceed with extraction.\n" } elif [[ "$api_digest" == 'null' ]]; then printf "Digest could not be gathered from the API, likely an older version (<0.4.52).\nExiting..." @@ -186,9 +184,9 @@ validation-decision() { if [[ $EXTRACT == 1 && -e "$zip" ]]; then tar xfz "$zip" - printf "Extracting binary for use...\nBinary is ready for use!" + printf "Extracting binary for use...\nBinary is ready for use!\n" else - printf "mdBook tar does not appear to exist...\nCleaning up...\nExiting...\n" + printf "mdBook tar not found...\nCleaning up...\nExiting...\n" fi [[ -e $zip ]] && rm -f "$zip" }