Merge pull request #128 from marvinroman/validate-username

Validate the username and hostname before proceeding further
This commit is contained in:
Chris Titus 2021-12-31 10:14:38 -06:00 committed by GitHub
commit 0f1f32aded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 0 deletions

View File

@ -103,6 +103,48 @@ elif lspci | grep -E "Radeon"; then
elif lspci | grep -E "Integrated Graphics Controller"; then
pacman -S libva-intel-driver libvdpau-va-gl lib32-vulkan-intel vulkan-intel libva-intel-driver libva-utils --needed --noconfirm
fi
if ! source install.conf; then
# Loop through user input until the user gives a valid username
while true
do
read -p "Please enter username:" username
# username regex per response here https://unix.stackexchange.com/questions/157426/what-is-the-regex-to-validate-linux-users
# lowercase the username to test regex
if [[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]
then
break
fi
echo "Incorrect username."
done
# convert name to lowercase before saving to install.conf
echo "username=${username,,}" >> ${HOME}/${SCRIPTHOME}/install.conf
fi
if [ $(whoami) = "root" ];
then
useradd -m -G wheel,libvirt -s /bin/bash $username
passwd $username
cp -R ${HOME}/${SCRIPTHOME} /home/${username}/
chown -R ${username}: /home/${username}/${SCRIPTHOME}
# Loop through user input until the user gives a valid hostname, but allow the user to force save
while true
do
read -p "Please name your machine:" nameofmachine
# hostname regex (!!couldn't find spec for computer name!!)
if [[ "${nameofmachine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]]
then
break
fi
# if validation fails allow the user to force saving of the hostname
read -p "Username doesn't seem correct. Do you still want to save it? (y/n)" force
if [[ "${force,,}" = "y" ]]
then
break
fi
done
echo ${nameofmachine} > /etc/hostname
echo -ne "
-------------------------------------------------------------------------
Adding User