# This is not the first line
# The problem here is at prompting for passwords
# After agreeing to reenter password, it auto-agree the next reenter
# It doesn't happen with reentering username
#!/bin/bash
#if [[ $EUID -ne 0 ]]; then
# echo "This script must be run as root"
# exit 1
#fi
username=""
group=""
passworda="a"
passwordb="b"
echo "This script is only for creating an account"
echo ""
echo "Creating a user for Samba"
until [ "$username" != "" ]; do
read -p "Username: " username
if getent passwd $username > /dev/null; then
echo ""
echo "That username has been taken"
echo -e "Would you like to reenter another username? [y/n] "
until [[ $REPLY =~ ^[Yy]$ || $REPLY =~ ^[Nn]$ ]]; do
read -rs -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
username=""
elif [[ $REPLY =~ ^[Nn]$ ]]; then
exit 1
fi
done
fi
done
until [ "$passworda" == "$passwordb" ]; do
read -s -p "Password: " passworda
echo ""
read -s -p "Retype password: " passwordb
echo ""
if [ "$passworda" != "$passwordb" ]; then
echo ""
echo "Password mismatched"
echo -e "Would you like to reenter your password? [y/n] "
until [[ $REPLY =~ ^[Yy]$ || $REPLY =~ ^[Nn]$ ]]; do
read -rs -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
unset $REPLY
elif [[ $REPLY =~ ^[Nn]$ ]]; then
exit 1
fi
done
fi
done
echo ""
echo ""
echo "Username entered $username"
echo "Password entered $passworda"
echo "Password entered $passwordb"