From ec5746f71887493637bd14bb3f98a3c0a65972a7 Mon Sep 17 00:00:00 2001 From: Max Hacking Date: Thu, 13 Feb 2020 14:13:42 +0000 Subject: [PATCH] Fix shellcheck warnings. --- sbin/mount.rbd | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/sbin/mount.rbd b/sbin/mount.rbd index 3e30650..58ab4ec 100755 --- a/sbin/mount.rbd +++ b/sbin/mount.rbd @@ -2,18 +2,8 @@ function versioninfo { - VERSION="$Revision$" - VERSION="${VERSION%\ \$}"; VERSION="${VERSION#\:}"; VERSION="${VERSION##\ }" - VERSION="(CVS revision $VERSION)" - - NAME="$Name$" - NAME="${NAME%\ \$}"; NAME="${NAME#\:}"; NAME="${NAME##\ }"; NAME="${NAME##release-}"; NAME="${NAME//-/.}" - [[ -n $NAME ]] && NAME="Version $NAME " - - echo ${CMDNAME} - echo ${NAME}${VERSION} - - echo -e "\nCopyright (C) 2013 Hacking Networked Solutions" + echo "$(basename "${0}") - version 1.0.0" + echo -e "\nCopyright (C) 2013-2020 Hacking Networked Solutions" echo "License GPLv3+: GNU GPL version 3 or later ." echo "This is free software: you are free to change and redistribute it." echo "There is NO WARRANTY, to the extent permitted by law." @@ -21,7 +11,7 @@ function versioninfo function helpscreen { - echo "Usage: ${CMDNAME} -o " + echo "Usage: $(basename "${0}") -o " echo "Mounts the Rados Block Device (RBD) specified by at the mount point" echo "specified by using the mount options specified in " echo @@ -36,9 +26,16 @@ function helpscreen function error_exit { - echo $1 - echo - exit $2 + local msg ev + msg="ERROR: ${1}" + ev="${2}" + + if [[ -z "${ev}" ]] || (( ev < 1 )); then + ev=1 + fi + + echo "${msg}" >&2 + exit "${ev}" } function wait_for_device @@ -60,27 +57,28 @@ function wait_for_device # Validate our inputs. [[ $1 == /* ]] && error_exit "RBD specifiers do NOT start with a /" +# shellcheck disable=SC2206 rbd_info=(${1//\// }) [[ ${#rbd_info[@]} != 2 ]] && error_exit "RBD should be specified as pool/device" [[ ! -d $2 ]] && error_exit "Mount point [$4] does not exist!" # If the RBD is not mapped already (we can't unmap in on unmount so it could be)... -if [[ ! -e /dev/rbd/${rbd_info[0]}/${rbd_info[1]} ]]; then +if [[ ! -e "/dev/rbd/${rbd_info[0]}/${rbd_info[1]}" ]]; then # Try to map the RBD. - rbd map ${rbd_info[1]} --pool ${rbd_info[0]} || \ + rbd map "${rbd_info[1]}" --pool "${rbd_info[0]}" || \ error_exit "Unable to mount RBD device \"${rbd_info[1]}\" from pool \"${rbd_info[0]}\"" # We need to wait for UDEV to settle. - wait_for_device /dev/rbd/${rbd_info[0]}/${rbd_info[1]} + wait_for_device "/dev/rbd/${rbd_info[0]}/${rbd_info[1]}" fi # Try to run fsck on the device as the init script won't! -fsck -M -C -T /dev/rbd/${rbd_info[0]}/${rbd_info[1]} -- -a || \ +fsck -M -C -T "/dev/rbd/${rbd_info[0]}/${rbd_info[1]}" -- -a || \ echo "fsck of /dev/rbd/${rbd_info[0]}/${rbd_info[1]} returned with $?!" # Try to mount the device, if it fails then unmap it and bail. -if ! mount /dev/rbd/${rbd_info[0]}/${rbd_info[1]} $2 -o $4; then - rbd unmap /dev/rbd/${rbd_info[0]}/${rbd_info[1]} +if ! mount "/dev/rbd/${rbd_info[0]}/${rbd_info[1]}" "$2" -o "$4"; then + rbd unmap "/dev/rbd/${rbd_info[0]}/${rbd_info[1]}" error_exit "Mounting device /dev/rbd/${rbd_info[0]}/${rbd_info[1]} at $2 failed!" fi