Fix the help output for tripleo-mount-image

This change does the following to fix the help output of
tripleo-mount-image and tripleo-unmount-image
- defer set -x until actual inside the actual mount/unmount functions
- add --help to the getopt long arguments so it actually works
- print help and exit if mandatory arguments -a, -m are missing

Blueprint: whole-disk-default
Change-Id: I6d16fd95c098559af9ec4e38b336819fc1663eef
This commit is contained in:
Steve Baker 2021-10-15 12:56:35 +13:00
parent 369b24bcf0
commit 6579b6858c
1 changed files with 10 additions and 3 deletions

View File

@ -19,10 +19,11 @@
#
set -eu
set -x
set -o pipefail
SCRIPT_NAME=$(basename $0)
NBD_DEVICE=/dev/nbd0
IMAGE_FILE=""
MOUNT_DIR=""
if [ ! -a "${NBD_DEVICE}" ]; then
modprobe nbd
fi
@ -167,7 +168,7 @@ unmount_image() {
if [ $SCRIPT_NAME == "tripleo-unmount-image" ]; then
TEMP=`getopt -o hm:n: -n $SCRIPT_NAME -- "$@"`
TEMP=`getopt -o hm:n: -l help -n $SCRIPT_NAME -- "$@"`
if [ $? != 0 ]; then
echo "Terminating..." >&2
exit 1
@ -183,9 +184,12 @@ if [ $SCRIPT_NAME == "tripleo-unmount-image" ]; then
*) echo "Error: unsupported option $1." ; exit 1;;
esac
done
if [ -z "${MOUNT_DIR}" ]; then
unmount_show_options 1
fi
unmount_image
else
TEMP=`getopt -o ha:m:n: -n $SCRIPT_NAME -- "$@"`
TEMP=`getopt -o ha:m:n: -l help -n $SCRIPT_NAME -- "$@"`
if [ $? != 0 ]; then
echo "Terminating..." >&2
exit 1
@ -203,5 +207,8 @@ else
*) echo "Error: unsupported option $1." ; exit 1;;
esac
done
if [ -z "${MOUNT_DIR}" ] || [ -z "${IMAGE_FILE}"]; then
mount_show_options 1
fi
mount_image
fi