contrib: shellcheck lint

Signed-off-by: Vincent Batts <vbatts@kinvolk.io>
This commit is contained in:
Vincent Batts 2020-09-01 17:14:10 -04:00
parent b8360e2c20
commit acac817ea1
No known key found for this signature in database
GPG Key ID: 524F155275DF0C3E

View File

@ -65,16 +65,16 @@ do
done done
# root user forbidden # root user forbidden
if [ $(id -u) -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
echo "$0: This script should not be run as root." >&2 echo "$0: This script should not be run as root." >&2
exit 1 exit 1
fi fi
# mkisofs/genisoimage tool check # mkisofs/genisoimage tool check
if which mkisofs &>/dev/null; then if command -v mkisofs &>/dev/null; then
mkisofs=$(which mkisofs) mkisofs=$(command -v mkisofs)
elif which genisoimage &>/dev/null; then elif command -v genisoimage &>/dev/null; then
mkisofs=$(which genisoimage) mkisofs=$(command -v genisoimage)
else else
echo "$0: mkisofs or genisoimage tool is required to create image." >&2 echo "$0: mkisofs or genisoimage tool is required to create image." >&2
exit 1 exit 1
@ -95,12 +95,12 @@ if [[ ! -r "$SSH_FILE" ]]; then
exit 1 exit 1
fi fi
if [ $(cat "$SSH_FILE" | wc -l) -eq 0 ]; then if [ "$(wc -l < "$SSH_FILE")" -eq 0 ]; then
echo "$0: The SSH file (${SSH_FILE}) is empty." >&2 echo "$0: The SSH file (${SSH_FILE}) is empty." >&2
exit 1 exit 1
fi fi
if [ $(grep -v -E "$REGEX_SSH_FILE" "$SSH_FILE" | wc -l) -gt 0 ]; then if [ "$(grep -c -v -E "$REGEX_SSH_FILE" "$SSH_FILE")" -gt 0 ]; then
echo "$0: The SSH file (${SSH_FILE}) content is invalid." >&2 echo "$0: The SSH file (${SSH_FILE}) content is invalid." >&2
exit 1 exit 1
fi fi
@ -114,12 +114,12 @@ if [[ ! -d "$DEST" ]]; then
exit 1 exit 1
fi fi
if [ ! -z "$ETCD_DISCOVERY" ] && [ ! -z "$TOKEN" ]; then if [ -n "$ETCD_DISCOVERY" ] && [ -n "$TOKEN" ]; then
echo "$0: You cannot specify both discovery token and discovery URL." >&2 echo "$0: You cannot specify both discovery token and discovery URL." >&2
exit 1 exit 1
fi fi
if [ ! -z "$TOKEN" ]; then if [ -n "$TOKEN" ]; then
ETCD_DISCOVERY="${DEFAULT_ETCD_DISCOVERY//TOKEN/$TOKEN}" ETCD_DISCOVERY="${DEFAULT_ETCD_DISCOVERY//TOKEN/$TOKEN}"
fi fi
@ -148,12 +148,12 @@ if [ -z "$ETCD_LISTEN_CLIENT_URLS" ]; then
fi fi
if [ -n "${CLOUD_CONFIG_FILE}" ]; then if [ -n "${CLOUD_CONFIG_FILE}" ]; then
CLOUD_CONFIG="$(cat ${CLOUD_CONFIG_FILE})" CLOUD_CONFIG="$(cat "${CLOUD_CONFIG_FILE}")"
fi fi
WORKDIR="${DEST}/tmp.${RANDOM}" WORKDIR="${DEST}/tmp.${RANDOM}"
mkdir "$WORKDIR" mkdir "$WORKDIR"
trap "rm -rf '${WORKDIR}'" EXIT trap 'rm -rf "${WORKDIR}"' EXIT
CONFIG_DIR="${WORKDIR}/openstack/latest" CONFIG_DIR="${WORKDIR}/openstack/latest"
CONFIG_FILE="${CONFIG_DIR}/user_data" CONFIG_FILE="${CONFIG_DIR}/user_data"
@ -161,7 +161,7 @@ CONFIGDRIVE_FILE="${DEST}/${HNAME}.iso"
mkdir -p "$CONFIG_DIR" mkdir -p "$CONFIG_DIR"
while read l; do while read -r l; do
if [ -z "$SSH_KEY" ]; then if [ -z "$SSH_KEY" ]; then
SSH_KEY="$l" SSH_KEY="$l"
else else
@ -182,8 +182,8 @@ CLOUD_CONFIG="${CLOUD_CONFIG/<HOSTNAME>/${HNAME}}"
echo "$CLOUD_CONFIG" > "$CONFIG_FILE" echo "$CLOUD_CONFIG" > "$CONFIG_FILE"
$mkisofs -R -V config-2 -o "$CONFIGDRIVE_FILE" "$WORKDIR" $mkisofs -R -V config-2 -o "$CONFIGDRIVE_FILE" "$WORKDIR"
ret="$?"
if [ "$?" -eq 0 ] ; then if [ "${ret}" -eq 0 ] ; then
echo echo
echo echo
echo "Success! The config-drive image was created on ${CONFIGDRIVE_FILE}" echo "Success! The config-drive image was created on ${CONFIGDRIVE_FILE}"