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