From bf1be8a2f801832fdf9d3784e98e1d4367d80828 Mon Sep 17 00:00:00 2001 From: Jan Ulferts Date: Tue, 22 Aug 2023 22:35:53 +0200 Subject: [PATCH] improved shell scripts --- scripts/common/clean_authorized_keys.sh | 2 +- scripts/common/cloudinit_from_source.sh | 13 ++++++------- scripts/el/rhn_add_subscription.sh | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/common/clean_authorized_keys.sh b/scripts/common/clean_authorized_keys.sh index 6d29f51..f1aaf2a 100644 --- a/scripts/common/clean_authorized_keys.sh +++ b/scripts/common/clean_authorized_keys.sh @@ -7,4 +7,4 @@ cloud-init --version test -n "${BASE_IMAGE_SSH_USER}" # echo "Cleaning authorized_keys for ${BASE_IMAGE_SSH_USER}" -echo "" > /home/$BASE_IMAGE_SSH_USER/.ssh/authorized_keys +echo "" > "/home/$BASE_IMAGE_SSH_USER/.ssh/authorized_keys" diff --git a/scripts/common/cloudinit_from_source.sh b/scripts/common/cloudinit_from_source.sh index a33ea12..b239676 100644 --- a/scripts/common/cloudinit_from_source.sh +++ b/scripts/common/cloudinit_from_source.sh @@ -14,8 +14,7 @@ else fi function fatal { - msg=$1 - echo $1 >2 + echo "$1" >&2 exit 1 } @@ -24,9 +23,9 @@ function download { filename=$2 if [ -x "$(which wget)" ] ; then - wget -q $url -O $2 + wget -q "$url" -O "$filename" elif [ -x "$(which curl)" ]; then - curl -o $2 -sfL $url + curl -o "$filename" -sfL "$url" else echo "Could not find curl or wget, please install one." >&2 exit 1 @@ -37,12 +36,12 @@ function download { type ${PYTHON_CMD} || fatal "${PYTHON_CMD} not found" type ${PIP_CMD} || fatal "${PIP_CMD} not found" -download https://github.com/canonical/cloud-init/archive/refs/tags/${CLOUDINIT_VERSION}.tar.gz ${CLOUDINIT_DOWNLOADFILE} +download "https://github.com/canonical/cloud-init/archive/refs/tags/${CLOUDINIT_VERSION}.tar.gz" ${CLOUDINIT_DOWNLOADFILE} mkdir -p ${CLOUDINIT_EXTRACT_FOLDER} tar xzf ${CLOUDINIT_DOWNLOADFILE} -C ${CLOUDINIT_EXTRACT_FOLDER} -${PIP_CMD} install -r ${CLOUDINIT_EXTRACT_FOLDER}/cloud-init-${CLOUDINIT_VERSION}/requirements.txt -( cd ${CLOUDINIT_EXTRACT_FOLDER}/cloud-init-${CLOUDINIT_VERSION} +${PIP_CMD} install -r "${CLOUDINIT_EXTRACT_FOLDER}/cloud-init-${CLOUDINIT_VERSION}/requirements.txt" +( cd "${CLOUDINIT_EXTRACT_FOLDER}/cloud-init-${CLOUDINIT_VERSION}" || exit 1 ${PYTHON_CMD} setup.py build ${PYTHON_CMD} setup.py install -O1 --skip-build --init-system systemd --install-scripts /usr/bin ) diff --git a/scripts/el/rhn_add_subscription.sh b/scripts/el/rhn_add_subscription.sh index 9c2d7c9..7a7b3ff 100644 --- a/scripts/el/rhn_add_subscription.sh +++ b/scripts/el/rhn_add_subscription.sh @@ -1,7 +1,7 @@ -#!/bin/sh -eu +#!/bin/bash -eu if [[ "${RHN_SUBSCRIPTION_KEY}" != "" && "${RHN_SUBSCRIPTION_ORG}" != "" ]]; then - subscription-manager register --org=${RHN_SUBSCRIPTION_ORG} --activationkey=${RHN_SUBSCRIPTION_KEY} + subscription-manager register --org="${RHN_SUBSCRIPTION_ORG}" --activationkey="${RHN_SUBSCRIPTION_KEY}" exit 0 fi @@ -16,4 +16,4 @@ if [[ "${RHN_PASSWORD}" == "" ]]; then exit 1 fi -subscription-manager register --username $RHN_USERNAME --password $RHN_PASSWORD --auto-attach +subscription-manager register --username "$RHN_USERNAME" --password "$RHN_PASSWORD" --auto-attach