jbomb-automate #4

Merged
phanipavank merged 9 commits from jbomb-automate into master 2026-01-13 15:03:35 +00:00

64
jconf Normal file → Executable file
View File

@@ -39,16 +39,72 @@ if [ "$#" -lt 1 ]; then
exit 1 exit 1
fi fi
if [[ "$EUID" -ne 0 ]]; then
echo "Run the script as root"
exit 2
fi
cmd=$1 cmd=$1
case "$cmd" in case "$cmd" in
adduser) adduser)
echo USER=$(echo "$2" | tr "[:upper:]" "[:lower:]")
exist=$(awk -F: -v username="$USER" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
if [ "$exist" -eq 1 ]; then
echo "$USER user already exists"
else
read -rp "Do you want to create an user account $USER [y/N]:" yn
case $yn in
[Yy])
useradd "$USER"
echo "Enter the password for $USER"
passwd "$USER"
echo "$USER user account created successfully"
;;
[Nn])
exit 1
;;
* )
echo "Please answer Y or N."
;;
esac
fi
exit 1
;; ;;
deluser) deluser)
echo USER=$(echo "$2" | tr "[:upper:]" "[:lower:]")
exist=$(awk -F: -v username="$USER" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
if [ "$exist" -eq 0 ]; then
echo "$USER user doesn't exist"
exit 1
else
read -rp "Do you want to delete $USER user account? [y/N]:" yn
case $yn in
[Yy])
;;
*)
exit 1
;;
esac
read -rp "This DELETES $USER's data, are you sure? [y/N]:" yn
case $yn in
[Yy])
userdel -rRZ "$USER";
echo "$USER user account deleted successfully"
;;
[Nn])
exit 1
;;
* )
echo "Please answer Y or N."
;;
esac
fi
exit 1
;; ;;
listusers) listusers|ls)
echo husers=$(awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd)
echo "$husers"
;; ;;
start) start)
echo echo