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

73
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])
[Nn]* ) exit 1;; exit 1
* ) echo "Please answer Y or N.";; ;;
esac * )
done echo "Please answer Y or N."
;;
esac
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 case $yn in
read -rp "Do you want to delete $2 user account? [Y/n]:" yn [Yy])
case $yn in ;;
[Yy]* ) *)
userdel -rRZ "$2"; exit 1
echo "$2 user account deleted successfully"; ;;
break;; esac
[Nn]* ) exit 1;; read -rp "This DELETES $2's data, are you sure? [y/N]:" yn
* ) echo "Please answer yes or no.";; case $yn in
esac [Yy])
done userdel -rRZ "$2";
echo "$2 user account deleted successfully"
;;
[Nn])
exit 1
;;
* )
echo "Please answer Y or N."
;;
esac
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
;; ;;