From f688f0c9dde9cb944f2b276230cdb3328bcb9ed8 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Mon, 30 Sep 2024 00:17:46 +0200 Subject: [PATCH] even more + `,,` --- core/tabs/system-setup/arch/server-setup.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/tabs/system-setup/arch/server-setup.sh b/core/tabs/system-setup/arch/server-setup.sh index 4ae0afd6..0650db38 100755 --- a/core/tabs/system-setup/arch/server-setup.sh +++ b/core/tabs/system-setup/arch/server-setup.sh @@ -242,7 +242,7 @@ userinfo () { while true do read -r -p "Please enter username: " username - if [[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] + if echo "$username" | grep -qE '^[a-z_][a-z0-9_-]{0,31}(\$)?$' then break fi @@ -267,20 +267,23 @@ userinfo () { # Loop through user input until the user gives a valid hostname, but allow the user to force save while true do - read -r -p "Please name your machine: " name_of_machine - # hostname regex (!!couldn't find spec for computer name!!) - if [[ "${name_of_machine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]] + printf "%b" "Please name your machine: " + read -r machine_name + + lower_machine_name=$(echo "$machine_name" | tr '[:upper:]' '[:lower:]') + if echo "$lower_machine_name" | grep -q '^[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 -r -p "Hostname doesn't seem correct. Do you still want to save it? (y/n)" force - if [[ "${force,,}" = "y" ]] + printf "%b" "Hostname doesn't seem correct. Do you still want to save it? (y/N) " + read -r force + if [[ "$force" == "y" || "$force" == "Y" ]] then break fi done - export NAME_OF_MACHINE=$name_of_machine + export NAME_OF_MACHINE=$lower_machine_name } # Starting functions @@ -376,7 +379,7 @@ subvolumesetup () { mountallsubvol } -if [[ "${DISK}" =~ "nvme" ]]; then +if echo "$DISK" | grep -q "nvme"; then partition2=${DISK}p2 partition3=${DISK}p3 else @@ -670,4 +673,4 @@ sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL/# %wheel ALL=(ALL:ALL) NOPASSWD: A # Add sudo rights sed -i 's/^# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers -EOF \ No newline at end of file +EOF