#!/bin/bash
# Lab 8

#CST8102
#myScript

selection=
while [ "$selection" != q ] && [ "$selection" != "Q" ] ; do #how to || "q"?
echo "A) Create a user account"
echo "B) Delete a user account"
echo "C) Change supplementary group for a user account"
echo "D) Change initial group for a user account"
echo "E) Change the default login shell for a user account"
echo "F) Change the account expiration date"
echo "Q) Quit"
echo ""
echo -n "What would you like to do?: "
read choice
echo ""
if [ "$choice" = "A" ] || [ "$choice" = "a" ] ; then
echo "Enter the user name"
read username
echo "Enter the home directory"
read home
echo "Enter the login shell"
read shell
sudo useradd -d "$home" -m -s "$shell" "$username"
echo ""
fi
if [ "$choice" = "B" ] || [ "$choice" = "b" ] ; then
echo "Enter the user to delete"
read username
sudo userdel -r "$username"
echo ""
fi
if [ "$choice" = "C" ] || [ "$choice" = "c" ] ; then
echo "Enter the user to modify"
read username
echo "Enter the group's name"
read group
sudo groupadd $group
sudo usermod -G "$group" "$username"
echo ""
fi
if [ "$choice" = "D" ] || [ "$choice" = "d" ] ; then
echo "Enter the user to modify"
read username
echo "Enter the group's name"
read group
sudo groupadd $group
sudo usermod -g "$group" "$username"
echo ""
fi
if [ "$choice" = "E" ] || [ "$choice" = "e" ] ; then
echo "Enter the user to modify"
read username
echo "Enter the new shell"
read shell
sudo usermod -s "$shell" "$username"
echo ""
fi
if [ "$choice" = "F" ] || [ "$choice" = "f" ] ; then
echo "Enter the user to modify"
read username
echo "Enter the new expiration date"
read exp
sudo usermod -e "$exp" "$username"
echo ""
fi
sleep 3
done