Skip to content

Commit

Permalink
Fix shellcheck warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
HackingM committed Feb 13, 2020
1 parent 2e0c216 commit ec5746f
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions sbin/mount.rbd
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@

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 <http://gnu.org/licenses/gpl.html>."
echo "This is free software: you are free to change and redistribute it."
echo "There is NO WARRANTY, to the extent permitted by law."
}

function helpscreen
{
echo "Usage: ${CMDNAME} <src> <dst> -o <opt>"
echo "Usage: $(basename "${0}") <src> <dst> -o <opt>"
echo "Mounts the Rados Block Device (RBD) specified by <src> at the mount point"
echo "specified by <dst> using the mount options specified in <opt>"
echo
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit ec5746f

Please sign in to comment.