jbomb-automate #4

Merged
phanipavank merged 9 commits from jbomb-automate into master 2026-01-13 15:03:35 +00:00
Showing only changes of commit e1f056a294 - Show all commits

63
jconf
View File

@@ -39,31 +39,37 @@ 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)
exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd) exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
if [ "$exist" -eq 1 ]; then if [ "$exist" -eq 1 ]; then
echo "$2 user already exists" echo "$2 user already exists"
else else
while true; do read -rp "Do you want to create an user account $2 [y/N]:" yn
read -rp "Do you want to create an user account $2 [Y/n]:" yn
case $yn in case $yn in
[Yy]* ) [Yy])
useradd "$2"; useradd "$2"
echo "Enter the password for $2:"; echo "Enter the password for $2"
passwd "$2" passwd "$2"
echo "$2 user account created successfully"; echo "$2 user account created successfully"
break;; ;;
[Nn]* ) exit 1;; [Nn])
* ) echo "Please answer Y or N.";; exit 1
;;
* )
echo "Please answer Y or N."
;;
esac esac
done
fi fi
exit 1 exit 1
;; ;;
deluser) deluser)
exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd) exist=$(awk -F: -v username="$2" '{if ($1 == username && $3 >= 1000 && $1 != "nobody") {print 1; found=1; exit}} END {if (!found) print 0}' /etc/passwd)
@@ -71,27 +77,34 @@ case "$cmd" in
echo "$2 user doesn't exist" echo "$2 user doesn't exist"
exit 1 exit 1
else else
read -rp "Do you want to delete $2 user account? [y/N]:" yn
while true; do
read -rp "Do you want to delete $2 user account? [Y/n]:" yn
case $yn in case $yn in
[Yy]* ) [Yy])
userdel -rRZ "$2"; ;;
echo "$2 user account deleted successfully"; *)
break;; exit 1
[Nn]* ) exit 1;; ;;
* ) echo "Please answer yes or no.";; esac
read -rp "This DELETES $2's data, are you sure? [y/N]:" yn
case $yn in
[Yy])
userdel -rRZ "$2";
echo "$2 user account deleted successfully"
;;
[Nn])
exit 1
;;
* )
echo "Please answer Y or N."
;;
esac esac
done
fi fi
exit 1 exit 1
;; ;;
listusers|ls)
listusers)
husers=$(awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd) husers=$(awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd)
echo "$husers" echo "$husers"
;; ;;
start) start)
echo echo
;; ;;