From 697a1f6618f97c0ad2d39ace6d683adad2154314 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Thu, 19 Sep 2024 12:29:54 +0000 Subject: [PATCH] Cleanup transform_binary.sh Adhere to shellcheck's recommendations and refactor duplicate code. --- transform_binary.sh | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/transform_binary.sh b/transform_binary.sh index e7e23d3..85ca71f 100755 --- a/transform_binary.sh +++ b/transform_binary.sh @@ -25,28 +25,22 @@ do if [[ ${OUTPUT} =~ ${pat1} ]]; then BOTTLE_NAME=${BASH_REMATCH[1]} - BOTTLE_NAME+="tar.gz" - - tar -xzf "${BOTTLE_NAME}" - mv cbmc cbmc@"${VERSION}" - sed -iu "s/class Cbmc/class ${FORMULA_VERSION}/g" "cbmc@${VERSION}/${VERSION}/.brew/cbmc.rb" - tar czf "cbmc@${VERSION}-${VERSION}.${TAG}.bottle.tar.gz" cbmc@"${VERSION}" - rm -rf cbmc@"${VERSION}" - SHA=$(shasum -a 256 "cbmc@${VERSION}-${VERSION}.$TAG.bottle.tar.gz" | awk '{print $1}') - LINE=" sha256 cellar: :any_skip_relocation, $TAG: \"${SHA}\"" - echo "${LINE}" elif [[ ${OUTPUT} =~ ${pat2} ]]; then BOTTLE_NAME=${BASH_REMATCH[1]} - BOTTLE_NAME+="tar.gz" - - tar -xzf "${BOTTLE_NAME}" - mv cbmc cbmc@"${VERSION}" - sed -iu "s/class Cbmc/class $FORMULA_VERSION/g" "cbmc@${VERSION}/${VERSION}/.brew/cbmc.rb" - tar czf "cbmc@${VERSION}-${VERSION}.${TAG}.bottle.tar.gz" cbmc@"${VERSION}" - rm -rf cbmc@"${VERSION}" - SHA=$(shasum -a 256 "cbmc@${VERSION}-${VERSION}.$TAG.bottle.tar.gz" | awk '{print $1}') - LINE=" sha256 cellar: :any_skip_relocation, $TAG: \"${SHA}\"" - echo "${LINE}" + else + continue fi + + BOTTLE_NAME+="tar.gz" + + tar -xzf "${BOTTLE_NAME}" + mv cbmc cbmc@"${VERSION}" + sed -iu "s/class Cbmc/class ${FORMULA_VERSION}/g" "cbmc@${VERSION}/${VERSION}/.brew/cbmc.rb" + tar czf "cbmc@${VERSION}-${VERSION}.${TAG}.bottle.tar.gz" cbmc@"${VERSION}" + rm -rf cbmc@"${VERSION}" + SHA=$(shasum -a 256 "cbmc@${VERSION}-${VERSION}.${TAG}.bottle.tar.gz") + TAG_SPACED=$(printf "%-60s" " sha256 cellar: :any_skip_relocation, ${TAG}:") + LINE="${TAG_SPACED}\"${SHA%%[[:space:]]*}\"" + echo "${LINE}" done echo end