From a1e8a03f6085715e7365808e37a445bea12625b3 Mon Sep 17 00:00:00 2001 From: Kanish R Date: Thu, 1 Jan 2026 02:14:17 +0530 Subject: [PATCH 1/7] user management commands automated --- jconf | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/jconf b/jconf index e9afd77..0128324 100644 --- a/jconf +++ b/jconf @@ -42,14 +42,60 @@ fi cmd=$1 case "$cmd" in adduser) - echo + + 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 + # Source - https://stackoverflow.com/a + # Posted by Myrddin Emrys, modified by community. See post 'Timeline' for change history + # Retrieved 2026-01-01, License - CC BY-SA 4.0 + + while true; do + read -p "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 yes or no.";; + esac + done + fi + exit 1 ;; + deluser) - echo + + 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 0 ]; then + echo "$2 user doesn't exist" + exit 1 + else + + while true; do + read -p "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 + fi + exit 1 ;; + listusers) - echo + husers= awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd + echo $husers ;; + start) echo ;; -- 2.49.1 From 3ea86d7e350fcb200dbce99aa0285ce0b1c85eb2 Mon Sep 17 00:00:00 2001 From: Kanish R Date: Thu, 1 Jan 2026 02:15:59 +0530 Subject: [PATCH 2/7] user management commands automated --- jconf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jconf b/jconf index 0128324..1521755 100644 --- a/jconf +++ b/jconf @@ -47,10 +47,6 @@ case "$cmd" in if [ "$exist" -eq 1 ]; then echo "$2 user already exists" else - # Source - https://stackoverflow.com/a - # Posted by Myrddin Emrys, modified by community. See post 'Timeline' for change history - # Retrieved 2026-01-01, License - CC BY-SA 4.0 - while true; do read -p "Do you want to create an user account $2 [Y/n]:" yn case $yn in -- 2.49.1 From 9e3a36aa0e317a1c1efac7ec86a211480901c015 Mon Sep 17 00:00:00 2001 From: Kanish R Date: Fri, 2 Jan 2026 17:58:00 +0530 Subject: [PATCH 3/7] user management commands automated --- jconf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jconf b/jconf index 1521755..4fc3bf8 100644 --- a/jconf +++ b/jconf @@ -57,7 +57,7 @@ case "$cmd" in echo "$2 user account created successfully"; break;; [Nn]* ) exit 1;; - * ) echo "Please answer yes or no.";; + * ) echo "Please answer Y or N.";; esac done fi -- 2.49.1 From aa297095b08a153b2d97f21954033c0a98e6654c Mon Sep 17 00:00:00 2001 From: Kanish R Date: Mon, 12 Jan 2026 09:19:32 +0530 Subject: [PATCH 4/7] lint error corrected --- jconf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) mode change 100644 => 100755 jconf diff --git a/jconf b/jconf old mode 100644 new mode 100755 index 4fc3bf8..1e9548b --- a/jconf +++ b/jconf @@ -48,12 +48,12 @@ case "$cmd" in echo "$2 user already exists" else while true; do - read -p "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 [Yy]* ) - useradd $2; + useradd "$2"; echo "Enter the password for $2:"; - passwd $2 + passwd "$2" echo "$2 user account created successfully"; break;; [Nn]* ) exit 1;; @@ -73,10 +73,10 @@ case "$cmd" in else while true; do - read -p "Do you want to delete $2 user account? [Y/n]:" yn + read -rp "Do you want to delete $2 user account? [Y/n]:" yn case $yn in [Yy]* ) - userdel -rRZ $2; + userdel -rRZ "$2"; echo "$2 user account deleted successfully"; break;; [Nn]* ) exit 1;; @@ -88,7 +88,7 @@ case "$cmd" in ;; 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 ;; -- 2.49.1 From e4f761b13355bdcd9fadd558f9af3193ca2de46a Mon Sep 17 00:00:00 2001 From: Kanish R Date: Mon, 12 Jan 2026 09:20:20 +0530 Subject: [PATCH 5/7] lint fixed --- jconf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jconf b/jconf index 1e9548b..3734744 100755 --- a/jconf +++ b/jconf @@ -89,7 +89,7 @@ case "$cmd" in listusers) husers=$(awk -F: '{ if ($3 >= 1000 && $1 != "nobody" ) {print $1}}' /etc/passwd) - echo $husers + echo "$husers" ;; start) -- 2.49.1 From e1f056a294ab620763bc0c96a9fc73bbf975577b Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Tue, 13 Jan 2026 19:32:19 +0530 Subject: [PATCH 6/7] run only as root, remove read loop, add double question for deluser --- jconf | 73 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/jconf b/jconf index 3734744..0c539b4 100755 --- a/jconf +++ b/jconf @@ -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 ;; -- 2.49.1 From 0d0b3477cdbbc956b27e08c3726f89a2c46bbdf8 Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Tue, 13 Jan 2026 20:32:34 +0530 Subject: [PATCH 7/7] lowercase usernames --- jconf | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/jconf b/jconf index 0c539b4..015de93 100755 --- a/jconf +++ b/jconf @@ -48,17 +48,18 @@ 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) + 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 "$2 user already exists" + echo "$USER user already exists" else - read -rp "Do you want to create an user account $2 [y/N]:" yn + read -rp "Do you want to create an user account $USER [y/N]:" yn case $yn in [Yy]) - useradd "$2" - echo "Enter the password for $2" - passwd "$2" - echo "$2 user account created successfully" + useradd "$USER" + echo "Enter the password for $USER" + passwd "$USER" + echo "$USER user account created successfully" ;; [Nn]) exit 1 @@ -71,13 +72,13 @@ case "$cmd" in 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) + 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 "$2 user doesn't exist" + echo "$USER user doesn't exist" exit 1 else - read -rp "Do you want to delete $2 user account? [y/N]:" yn + read -rp "Do you want to delete $USER user account? [y/N]:" yn case $yn in [Yy]) ;; @@ -85,11 +86,11 @@ case "$cmd" in exit 1 ;; esac - read -rp "This DELETES $2's data, are you sure? [y/N]:" yn + read -rp "This DELETES $USER's data, are you sure? [y/N]:" yn case $yn in [Yy]) - userdel -rRZ "$2"; - echo "$2 user account deleted successfully" + userdel -rRZ "$USER"; + echo "$USER user account deleted successfully" ;; [Nn]) exit 1 -- 2.49.1