diff --git a/autouser.sh b/autouser.sh index aba8752..9620746 100755 --- a/autouser.sh +++ b/autouser.sh @@ -90,25 +90,27 @@ createUser() { } deleteGroup() { - if [[ "$DRYRUN" == true ]]; then - read -p "Enter group name: " GROUPNAME - echo "groupadd $GROUPNAME" - else + COMMAND="" + if [[ "$DRYRUN" == false ]]; then rootCheck - read -p "Enter group name: " GROUPNAME - groupadd $GROUPNAME + COMMAND="groupdel" + else + COMMAND="echo groupdel" fi + read -p "Enter group name: " GROUPNAME + $COMMAND $GROUPNAME } deleteUser() { - if [[ "$DRYRUN" == true ]]; then - read -p "Enter username: " USERNAME - echo "userdel -r $USERNAME" - else + COMMAND="" + if [[ "$DRYRUN" == false ]]; then rootCheck - read -p "Enter username: " USERNAME - userdel -r $USERNAME + COMMAND="userdel" + else + COMMAND="echo userdel" fi + read -p "Enter username: " USERNAME + $COMMAND -r $USERNAME } rootCheck () @@ -238,25 +240,20 @@ createUsers () deleteUsers () { checkFile + COMMAND="" if [[ "$DRYRUN" == false ]]; then rootCheck - USERADDER="useradd" - CHFNER="chfn" + USERDELER="userdel" + GROUPDELER="groupdel" else - USERADDER="echo useradd" - CHFNER="echo chfn" - USERMOD="echo usermod" + USERDELER="echo userdel" + GROUPDELER="echo groupdel" fi while read line; do USERNAME=$(turnLowercase $(cutter "${line}" "$COL_USERNAME")) echo "[+] Deleting user $USERNAME..." - if [[ "$DRYRUN" == true ]]; then - echo "userdel -r $USERNAME" - echo "groupdel $USERNAME" - else - userdel -r $USERNAME 2>/dev/null - groupdel $USERNAME 2>/dev/null - fi + $USERDELER -r $USERNAME 2>/dev/null + $GROUPDELER $USERNAME 2>/dev/null done <<< "$FILE_CONTENTS" } @@ -295,6 +292,11 @@ do fi done +if [[ "$ACTION_TO_TAKE" == "" ]]; then + usage + exit +fi + case "$ACTION_TO_TAKE" in create-groups) createGroups @@ -320,10 +322,16 @@ case "$ACTION_TO_TAKE" in createUser exit ;; + delete-group) + deleteGroup + exit + ;; + delete-user) + deleteUser + exit + ;; *) echo "Invalid parameter! Exiting..." exit ;; esac - -usage