Exercise 3, lab 7 done
This commit is contained in:
parent
a93b4c469b
commit
84d32a7900
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
# Binaries
|
# Binaries
|
||||||
Chpasswd="/usr/sbin/chpasswd"
|
Chpasswd="/usr/sbin/chpasswd"
|
||||||
|
Useradd="/usr/sbin/useradd"
|
||||||
Dialog="/usr/bin/dialog"
|
Dialog="/usr/bin/dialog"
|
||||||
Grep="/bin/grep"
|
Grep="/bin/grep"
|
||||||
Cat="/bin/cat"
|
Cat="/bin/cat"
|
||||||
@ -16,7 +17,7 @@ Cat="/bin/cat"
|
|||||||
ask()
|
ask()
|
||||||
{
|
{
|
||||||
$Dialog --backtitle "Create new user" --inputbox "$1" 10 60\
|
$Dialog --backtitle "Create new user" --inputbox "$1" 10 60\
|
||||||
>> /tmp/createuser
|
2> /tmp/createuser
|
||||||
Input=`$Cat /tmp/createuser`
|
Input=`$Cat /tmp/createuser`
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Aborting, something went wrong..."
|
echo "Aborting, something went wrong..."
|
||||||
@ -27,12 +28,6 @@ ask()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
list_shells()
|
|
||||||
{
|
|
||||||
for Shell in `$Cat /etc/shells | $Grep /bin`; do
|
|
||||||
echo "$Shell '$Shell'"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
if [ $EUID -ne 0 ]; then
|
if [ $EUID -ne 0 ]; then
|
||||||
@ -40,7 +35,7 @@ if [ $EUID -ne 0 ]; then
|
|||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for bin in $Chpasswd $Dialog; do
|
for bin in $Chpasswd $Useradd $Dialog $Grep $Cat; do
|
||||||
if [ ! -x $bin ]; then
|
if [ ! -x $bin ]; then
|
||||||
echo "Can't execute $bin"
|
echo "Can't execute $bin"
|
||||||
exit 2
|
exit 2
|
||||||
@ -51,5 +46,23 @@ done
|
|||||||
ask "Enter username of the new user"
|
ask "Enter username of the new user"
|
||||||
Username=$Input
|
Username=$Input
|
||||||
|
|
||||||
|
# Get a list of all avaliable shells on the system
|
||||||
|
Shell=`$Cat /etc/shells | $Grep /bin`
|
||||||
|
ShellList=`printf "$Shell" | sed 's/ / shell /g' | sed 's/$/ shell/'`
|
||||||
|
|
||||||
|
HowMany=`echo $Shell | wc -w` # How many shells are avaliable?
|
||||||
|
|
||||||
$Dialog --backtitle "Create new user"\
|
$Dialog --backtitle "Create new user"\
|
||||||
--menu "Choose a shell for your new user" 10 60 list_shells
|
--menu "Choose a shell for your new user" 14 60 $HowMany $ShellList\
|
||||||
|
2> /tmp/createuser
|
||||||
|
Input=`$Cat /tmp/createuser`
|
||||||
|
UserShell=$Input
|
||||||
|
|
||||||
|
ask "Enter a password for the new user"
|
||||||
|
Password=$Input
|
||||||
|
|
||||||
|
# Create the user and set the password
|
||||||
|
$Useradd -m -s $UserShell $Username
|
||||||
|
echo "${Username}:${Password}" | $Chpasswd
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user