Minor improvements and fixes

Was missing a few forgotten variables
This commit is contained in:
raul 2024-12-16 10:33:56 +01:00
parent bb6dd68dd2
commit 0eb08ba8c0
Signed by: raul
GPG Key ID: C1AA797073F17129
1 changed files with 34 additions and 26 deletions

View File

@ -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