Perform safety checks in create-stack-user.sh
This adds some safety checks to the stack user creation script.
This includes:
- Using set -o errexit to exit early on errors
- Make sure STACK_USER is set before doing anything with it
Change-Id: If027daddd03e32c5ba3c2ebb05ad5b27d2868b0a
diff --git a/tools/create-stack-user.sh b/tools/create-stack-user.sh
index 50f6592..9c29ecd 100755
--- a/tools/create-stack-user.sh
+++ b/tools/create-stack-user.sh
@@ -15,6 +15,7 @@
# and it was time for this nonsense to stop. Run this script as root to create
# the user and configure sudo.
+set -o errexit
# Keep track of the devstack directory
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
@@ -27,12 +28,14 @@
# and ``DISTRO``
GetDistro
-# Needed to get ``ENABLED_SERVICES``
+# Needed to get ``ENABLED_SERVICES`` and ``STACK_USER``
source $TOP_DIR/stackrc
# Give the non-root user the ability to run as **root** via ``sudo``
is_package_installed sudo || install_package sudo
+[[ -z "$STACK_USER" ]] && die "STACK_USER is not set. Exiting."
+
if ! getent group $STACK_USER >/dev/null; then
echo "Creating a group called $STACK_USER"
groupadd $STACK_USER