From fe05598c545053d0490dc98edc1c61bf6743046f Mon Sep 17 00:00:00 2001 From: "David.Houck" Date: Mon, 8 Apr 2024 22:35:47 -0400 Subject: [PATCH] Fix shellcheck error & warnings --- .../02_dac_deploy.sh | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/viya4-deployment-darksite/deployment-machine-assets/02_dac_deploy.sh b/viya4-deployment-darksite/deployment-machine-assets/02_dac_deploy.sh index 01fff311..f432163a 100755 --- a/viya4-deployment-darksite/deployment-machine-assets/02_dac_deploy.sh +++ b/viya4-deployment-darksite/deployment-machine-assets/02_dac_deploy.sh @@ -11,15 +11,15 @@ function docker_run() { echo "starting $tags job..." docker run --rm \ --group-add root \ - --user $(id -u):$(id -g) \ - --volume $(pwd)/infrastructure/ssh/id_rsa:/config/jump_svr_private_key \ - --volume $(pwd)/infrastructure/terraform.tfstate:/config/tfstate \ + --user "$(id -u)":"$(id -g)" \ + --volume "$(pwd)"/infrastructure/ssh/id_rsa:/config/jump_svr_private_key \ + --volume "$(pwd)"/infrastructure/terraform.tfstate:/config/tfstate \ --volume /home/ec2-user/.kube/config:/.kube/config \ - --volume $(pwd)/software/deployments:/data \ - --volume $(pwd)/software/viya_order_assets:/viya_order_assets \ - --volume $(pwd)/software/ansible-vars-iac.yaml:/config/config \ - --volume $(pwd)/software/ingress:/ingress \ - --volume $(pwd)/software/sitedefault.yaml:/sitedefault/sitedefault.yaml \ + --volume "$(pwd)"/software/deployments:/data \ + --volume "$(pwd)"/software/viya_order_assets:/viya_order_assets \ + --volume "$(pwd)"/software/ansible-vars-iac.yaml:/config/config \ + --volume "$(pwd)"/software/ingress:/ingress \ + --volume "$(pwd)"/software/sitedefault.yaml:/sitedefault/sitedefault.yaml \ viya4-deployment:$DOCKER_TAG --tags "$tags" } @@ -64,7 +64,7 @@ done # check if provided tasks are valid for i in "${clean[@]}"; do - inarray=$(echo ${TASKS[@]} | grep -ow "$i" | wc -w) + inarray=$(echo "${TASKS[@]}" | grep -ow "$i" | wc -w) if [ $inarray == 0 ]; then echo $i "is not a valid input." exit 0 @@ -109,12 +109,20 @@ if [ "$last" == "uninstall" ]; then fi # all checks passed so build the tags string -tags=$(join_by , ${clean[*]}) +tags=$(join_by , "${clean[@]}") # run the function docker_run # remove downloaded assets -if [ -f software/deployments/darksite-lab-eks/viya/SASViyaV4*.tgz ]; then - rm software/deployments/darksite-lab-eks/viya/SASViyaV4*.tgz -fi +for f in software/deployments/darksite-lab-eks/viya/SASViyaV4*.tgz; do + ## Check if the glob gets expanded to existing files. + ## If not, f here will be exactly the pattern above + ## and the exists test will evaluate to false. + [ -f "$f" ] && rm software/deployments/darksite-lab-eks/viya/SASViyaV4*.tgz || echo "SASViyaV4.tgz files do not exist" + + ## If one more files exist, they are all removed at once, so we can break after the first iteration + break +done + +