From 010959de403660e13eca54c6ef306ef5df24b436 Mon Sep 17 00:00:00 2001 From: Jim Rollenhagen Date: Tue, 18 Feb 2014 13:17:58 -0600 Subject: [PATCH] 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 --- tools/create-stack-user.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/create-stack-user.sh b/tools/create-stack-user.sh index 50f6592a3a..9c29ecd901 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 @@ source $TOP_DIR/functions # 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