47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
#!/bin/bash
|
|
. ./lib
|
|
|
|
options=()
|
|
options+=("Add User" "")
|
|
options+=("List Users" "")
|
|
options+=("Delete User" "")
|
|
|
|
defaultitem=""
|
|
sel=$(dialog --backtitle "$apptitle" --title "Users Menu :" --default-item "$defaultitem" --cancel-button "Back" --menu "" 0 0 0 \
|
|
"${options[@]}" \
|
|
3>&1 1>&2 2>&3)
|
|
if [ ! "$?" = "0" ]; then
|
|
exit 1
|
|
fi
|
|
sed -i "/^defaultitem=/c\defaultitem=\"$sel\"" $0
|
|
|
|
case $sel in
|
|
'List Users')
|
|
clear
|
|
awk -F: '{if ($3 >= 1000 && $3 <= 5000) { print $1 } }' /etc/passwd
|
|
read -n1 -p "press a key to continue"
|
|
;;
|
|
'Add User')
|
|
username=$(dialog --backtitle "$apptitle" --title "Add User" --inputbox "Enter the new user name :" 0 0 3>&1 1>&2 2>&3)
|
|
if [ "$?" = "0" ]; then
|
|
useradd -d /home/$username -s /bin/bash -m -N $username
|
|
clear
|
|
echo "User $username created."
|
|
echo ""
|
|
echo "Choose a password for $username :"
|
|
echo ""
|
|
passwd $username
|
|
grpck
|
|
pressanykey
|
|
fi
|
|
;;
|
|
'Delete User')
|
|
username=$(dialog --backtitle "$apptitle" --title "Delete User" --inputbox "Enter the user name to delete :" 0 0 3>&1 1>&2 2>&3)
|
|
if [ "$?" = "0" ]; then
|
|
userdel -r -f $username
|
|
grpck
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|