From 0b87fad0ab0a84a4f02a0f6ec0688cf4811c51ef Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 12 May 2024 09:52:27 -0500 Subject: [PATCH] (maint) shellcheck task scripts --- tasks/install_pe.sh | 21 +++++++++------------ tasks/install_puppetserver.sh | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/tasks/install_pe.sh b/tasks/install_pe.sh index a489ffa5..832c1a7d 100644 --- a/tasks/install_pe.sh +++ b/tasks/install_pe.sh @@ -7,34 +7,31 @@ else PE_RELEASE=$PT_version fi -PE_LATEST=$(curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/${PE_RELEASE}/ci-ready/LATEST) +PE_LATEST=$(curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/"${PE_RELEASE}"/ci-ready/LATEST) PE_FILE_NAME=puppet-enterprise-${PE_LATEST}-el-7-x86_64 TAR_FILE=${PE_FILE_NAME}.tar DOWNLOAD_URL=https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/${PE_RELEASE}/ci-ready/${TAR_FILE} ## Download PE -curl -o ${TAR_FILE} ${DOWNLOAD_URL} -if [[ $? -ne 0 ]];then - echo “Error: wget failed to download [${DOWNLOAD_URL}]” +if ! curl -o "${TAR_FILE}" "${DOWNLOAD_URL}" ; then + echo "Error: failed to download [${DOWNLOAD_URL}]" exit 2 fi ## Install PE -tar xvf ${TAR_FILE} -if [[ $? -ne 0 ]];then - echo “Error: Failed to untar [${TAR_FILE}]” +if ! tar xvf "${TAR_FILE}" ; then + echo "Error: Failed to untar [${TAR_FILE}]" exit 2 fi -cd ${PE_FILE_NAME} -DISABLE_ANALYTICS=1 ./puppet-enterprise-installer -y -c ./conf.d/pe.conf -if [[ $? -ne 0 ]];then - echo “Error: Failed to install Puppet Enterprise. Please check the logs and call Bryan.x ” +cd "${PE_FILE_NAME}" || exit 1 +if ! DISABLE_ANALYTICS=1 ./puppet-enterprise-installer -y -c ./conf.d/pe.conf ; then + echo "Error: Failed to install Puppet Enterprise. Please check the logs and call Bryan.x" exit 2 fi ## Finalize configuration -echo “Finalize PE install” +echo "Finalize PE install" puppet agent -t # if [[ $? -ne 0 ]];then # echo “Error: Agent run failed. Check the logs above...” diff --git a/tasks/install_puppetserver.sh b/tasks/install_puppetserver.sh index 40b96b12..43620702 100644 --- a/tasks/install_puppetserver.sh +++ b/tasks/install_puppetserver.sh @@ -21,7 +21,7 @@ fi parse_platform() { data=() - for x in $(echo $1 | tr "[/|-|-|:]" "\n") + for x in $(echo "$1" | tr "/|-|-|:" "\n") do data+=("$x") done @@ -59,9 +59,8 @@ fetch_osfamily() { } fetch_collection() { - data=$(echo $1 | tr "-" "\n") myarr=() - for x in $(echo $1 | tr "-" "\n") + for x in $(echo "$1" | tr "-" "\n") do myarr+=("$x") done @@ -100,14 +99,14 @@ fetch_codename() { } run_cmd() { - eval $1 + eval "$1" rc=$? if test $rc -ne 0; then attempt_number=0 - while test $attempt_number -lt $retry; do + while test $attempt_number -lt "$retry"; do echo "Retrying... [$((attempt_number + 1))/$retry]" - eval $1 + eval "$1" rc=$? if test $rc -eq 0; then @@ -133,10 +132,10 @@ if [[ "$platform" == "null" || "$collection" == "null" ]]; then exit 1 fi -osname=$(parse_platform $platform "osname") -major_version=$(parse_platform $platform "majorversion") -osfamily=$(fetch_osfamily $osname) -collection=$(fetch_collection $collection) +osname=$(parse_platform "$platform" "osname") +major_version=$(parse_platform "$platform" "majorversion") +osfamily=$(fetch_osfamily "$osname") +collection=$(fetch_collection "$collection") if [[ "$collection" == "puppet5" ]]; then echo "puppet5 eol!" @@ -149,7 +148,7 @@ if [[ "$osfamily" == "unsupported" ]]; then fi if [[ "$osfamily" == "debian" ]]; then - codename=$(fetch_codename $collection $major_version) + codename=$(fetch_codename "$collection $major_version") if [[ "$codename" == "unsupported" ]]; then echo "No builds for $platform" exit 1