Compare commits

4 Commits

Author SHA1 Message Date
Phani Pavan K
0d0b3477cd lowercase usernames
All checks were successful
/ Lint Check Shellscripts (push) Successful in 16s
/ Lint Check Shellscripts (pull_request) Successful in 12s
2026-01-13 20:32:34 +05:30
Phani Pavan K
e1f056a294 run only as root, remove read loop, add double question for deluser
All checks were successful
/ Lint Check Shellscripts (push) Successful in 28s
/ Lint Check Shellscripts (pull_request) Successful in 11s
2026-01-13 19:32:19 +05:30
e4f761b133 lint fixed
All checks were successful
/ Lint Check Shellscripts (push) Successful in 12s
/ Lint Check Shellscripts (pull_request) Successful in 11s
2026-01-12 09:20:20 +05:30
aa297095b0 lint error corrected
Some checks failed
/ Lint Check Shellscripts (push) Failing after 16s
/ Lint Check Shellscripts (pull_request) Failing after 11s
2026-01-12 09:19:32 +05:30

88
jconf Normal file → Executable file
View File

@@ -39,59 +39,73 @@ 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)
USER=$(echo "$2" | tr "[:upper:]" "[:lower:]")
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="$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 if [ "$exist" -eq 1 ]; then
echo "$2 user already exists" echo "$USER user already exists"
else else
while true; do read -rp "Do you want to create an user account $USER [y/N]:" yn
read -p "Do you want to create an user account $2 [Y/n]:" yn case $yn in
case $yn in [Yy])
[Yy]* ) useradd "$USER"
useradd $2; echo "Enter the password for $USER"
echo "Enter the password for $2:"; passwd "$USER"
passwd $2 echo "$USER 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)
USER=$(echo "$2" | tr "[:upper:]" "[:lower:]")
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="$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 if [ "$exist" -eq 0 ]; then
echo "$2 user doesn't exist" echo "$USER user doesn't exist"
exit 1 exit 1
else else
read -rp "Do you want to delete $USER user account? [y/N]:" yn
while true; do case $yn in
read -p "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 $USER's data, are you sure? [y/N]:" yn
* ) echo "Please answer yes or no.";; case $yn in
esac [Yy])
done userdel -rRZ "$USER";
echo "$USER 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
;; ;;