From 02ba8361a97287747812658a61d3685ced10cb7f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 5 May 2022 09:42:16 -0400 Subject: [PATCH] Build: Extract function exit_if_user_doesnt_exist() --- .../appimage/install-infection-monkey-service.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build_scripts/appimage/install-infection-monkey-service.sh b/build_scripts/appimage/install-infection-monkey-service.sh index 114ca5651..8baffc735 100755 --- a/build_scripts/appimage/install-infection-monkey-service.sh +++ b/build_scripts/appimage/install-infection-monkey-service.sh @@ -77,6 +77,13 @@ user_exists() { id -u "$1" &>/dev/null } +exit_if_user_doesnt_exist() { + if ! user_exists "$1" ; then + echo "Error: User '$1' does not exist" + exit 1 + fi +} + has_sudo() { # 0 true, 1 false sudo -nv > /dev/null 2>&1 @@ -99,6 +106,7 @@ while (( "$#" )); do case "$1" in --user) exit_if_missing_argument "$1" "$2" + exit_if_user_doesnt_exist "$2" username=$2 shift 2 ;; @@ -143,11 +151,6 @@ if $do_uninstall ; then fi if $do_install ; then - if ! user_exists "$username" ; then - echo "Error: User '$username' does not exist" - exit 1 - fi - install_service "$username" exit 0 fi