Update easy-arch.sh

mainly changed functions with user input (except password-related ones since i don't know how to apply it to those) to use a different method for repeating questions to fix the issue of commands repeating if incorrect answers were given before a correct one (this is the reason why the password selection functions use while loops for incorrect answers instead of re-running the function). the method used is described in this StackExchange answer: https://unix.stackexchange.com/a/268769
This commit is contained in:
i-c-u-p 2022-04-28 07:27:56 +00:00
parent 93f2caeb3b
commit f281da1821
No known key found for this signature in database
GPG key ID: ABB80C12170FC0D1

View file

@ -3,9 +3,23 @@
# Cleaning the TTY. # Cleaning the TTY.
clear clear
# Colors/formatting for echo
BOLD='\e[1m'
UNDERLINE='\e[4m'
RESET='\e[0m' # Reset text to default appearance
# High intensity colors:
BRED='\e[91m'
BGREEN='\e[92m'
BYELLOW='\e[93m'
BPURPLE='\e[95m'
# Pretty print (function). # Pretty print (function).
print () { print () {
echo -e "\e[1m\e[93m[ \e[92m•\e[93m ] \e[4m$1\e[0m" echo -e "${BOLD}${BYELLOW}[ ${BGREEN}${BYELLOW} ] ${UNDERLINE}$1${RESET}"
}
# Alert user of bad input (function).
incEcho () {
echo -e "${BPURPLE}$1${RESET}"
} }
# Virtualization check (function). # Virtualization check (function).
@ -53,15 +67,15 @@ kernel_selector () {
read -r -p "Insert the number of the corresponding kernel: " kernel_choice read -r -p "Insert the number of the corresponding kernel: " kernel_choice
case $kernel_choice in case $kernel_choice in
1 ) kernel="linux" 1 ) kernel="linux"
;; return 0;;
2 ) kernel="linux-hardened" 2 ) kernel="linux-hardened"
;; return 0;;
3 ) kernel="linux-lts" 3 ) kernel="linux-lts"
;; return 0;;
4 ) kernel="linux-zen" 4 ) kernel="linux-zen"
;; return 0;;
* ) print "You did not enter a valid selection." * ) incecho "You did not enter a valid selection."
kernel_selector return 1
esac esac
} }
@ -75,12 +89,12 @@ network_selector () {
print "5) I will do this on my own (only advanced users)" print "5) I will do this on my own (only advanced users)"
read -r -p "Insert the number of the corresponding networking utility: " network_choice read -r -p "Insert the number of the corresponding networking utility: " network_choice
if ! ((1 <= network_choice <= 5)); then if ! ((1 <= network_choice <= 5)); then
print "You did not enter a valid selection." incEcho "You did not enter a valid selection."
network_selector return 1
fi fi
} }
# Installing the chosen networking method to the system. # Installing the chosen networking method to the system (function).
network_installer () { network_installer () {
case $network_choice in case $network_choice in
1 ) print "Installing IWD." 1 ) print "Installing IWD."
@ -112,7 +126,7 @@ lukspass_selector () {
read -r -s -p "Insert password for the LUKS container (you're not going to see the password): " password read -r -s -p "Insert password for the LUKS container (you're not going to see the password): " password
while [ -z "$password" ]; do while [ -z "$password" ]; do
echo echo
print "You need to enter a password for the LUKS Container in order to continue." incEcho "You need to enter a password for the LUKS Container in order to continue."
read -r -s -p "Insert password for the LUKS container (you're not going to see the password): " password read -r -s -p "Insert password for the LUKS container (you're not going to see the password): " password
[ -n "$password" ] && break [ -n "$password" ] && break
done done
@ -120,7 +134,7 @@ lukspass_selector () {
read -r -s -p "Password (again): " password2 read -r -s -p "Password (again): " password2
echo echo
[ "$password" = "$password2" ] && break [ "$password" = "$password2" ] && break
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done done
} }
@ -130,7 +144,7 @@ userpass_selector () {
read -r -s -p "Set a user password for $username: " userpass read -r -s -p "Set a user password for $username: " userpass
while [ -z "$userpass" ]; do while [ -z "$userpass" ]; do
echo echo
print "You need to enter a password for $username." incEcho "You need to enter a password for $username."
read -r -s -p "Set a user password for $username: " userpass read -r -s -p "Set a user password for $username: " userpass
[ -n "$userpass" ] && break [ -n "$userpass" ] && break
done done
@ -138,7 +152,7 @@ userpass_selector () {
read -r -s -p "Insert password again: " userpass2 read -r -s -p "Insert password again: " userpass2
echo echo
[ "$userpass" = "$userpass2" ] && break [ "$userpass" = "$userpass2" ] && break
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done done
} }
@ -148,7 +162,7 @@ rootpass_selector () {
read -r -s -p "Set a root password: " rootpass read -r -s -p "Set a root password: " rootpass
while [ -z "$rootpass" ]; do while [ -z "$rootpass" ]; do
echo echo
print "You need to enter a root password." incEcho "You need to enter a root password."
read -r -s -p "Set a root password: " rootpass read -r -s -p "Set a root password: " rootpass
[ -n "$rootpass" ] && break [ -n "$rootpass" ] && break
done done
@ -156,7 +170,7 @@ rootpass_selector () {
read -r -s -p "Password (again): " rootpass2 read -r -s -p "Password (again): " rootpass2
echo echo
[ "$rootpass" = "$rootpass2" ] && break [ "$rootpass" = "$rootpass2" ] && break
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done done
} }
@ -172,14 +186,14 @@ microcode_detector () {
fi fi
} }
# Setting up the hostname (function). # User chooses the hostname (function).
hostname_selector () { hostname_selector () {
read -r -p "Please enter the hostname: " hostname read -r -p "Please enter the hostname: " hostname
if [ -z "$hostname" ]; then if [ -z "$hostname" ]; then
print "You need to enter a hostname in order to continue." incEcho "You need to enter a hostname in order to continue."
hostname_selector return 1
fi fi
echo "$hostname" > /mnt/etc/hostname return 0
} }
# Setting up the locale (function). # Setting up the locale (function).
@ -190,12 +204,13 @@ locale_selector () {
locale="en_US.UTF-8";; locale="en_US.UTF-8";;
'/') sed -E '/^# +|^#$/d;s/^#| *$//g;s/ .*/ (Charset:&)/' /etc/locale.gen | less -M '/') sed -E '/^# +|^#$/d;s/^#| *$//g;s/ .*/ (Charset:&)/' /etc/locale.gen | less -M
clear clear
locale_selector;; return 1;;
*) if ! grep -Fxq $locale /etc/locale.gen; then *) if ! grep -Fxq $locale /etc/locale.gen; then
print "The specified locale doesn't exist or isn't supported." incEcho "The specified locale doesn't exist or isn't supported."
locale_selector return 1
fi fi
sed -i "$locale/s/^#//" /etc/locale.gen sed -i "$locale/s/^#//" /etc/locale.gen
return 0
esac esac
} }
@ -204,16 +219,18 @@ keyboard_selector () {
read -r -p "Please insert the keyboard layout you use (enter empty to use US keyboard layout, or enter "/" to search avaliable layouts): " kblayout read -r -p "Please insert the keyboard layout you use (enter empty to use US keyboard layout, or enter "/" to search avaliable layouts): " kblayout
case $kblayout in case $kblayout in
'') print "US keyboard layout will be used by default." '') print "US keyboard layout will be used by default."
kblayout="us";; kblayout="us"
return 0;;
'/') localectl list-keymaps '/') localectl list-keymaps
clear clear
keyboard_selector;; return 1;;
*) if ! $(localectl list-keymaps | grep -Fxq $kblayout); then *) if ! $(localectl list-keymaps | grep -Fxq $kblayout); then
print "The specified keymap doesn't exist." incEcho "The specified keymap doesn't exist."
keyboard_selector return 1
fi fi
print "Changing layout to $kblayout." print "Changing layout to $kblayout."
loadkeys $kblayout loadkeys $kblayout
return 0
esac esac
} }
@ -222,7 +239,7 @@ keyboard_selector () {
print "Welcome to easy-arch, a script made in order to simplify the process of installing Arch Linux." print "Welcome to easy-arch, a script made in order to simplify the process of installing Arch Linux."
# Setting up keyboard layout. # Setting up keyboard layout.
keyboard_selector until keyboard_selector; do : ; done
PS3="Please select the disk NUMBER e.g. 1 where Arch Linux is going to be installed: " PS3="Please select the disk NUMBER e.g. 1 where Arch Linux is going to be installed: "
select ENTRY in $(lsblk -dpnoNAME|grep -P "/dev/sd|nvme|vd"); select ENTRY in $(lsblk -dpnoNAME|grep -P "/dev/sd|nvme|vd");
@ -233,7 +250,8 @@ do
done done
# Warn user about deletion of old partition scheme. # Warn user about deletion of old partition scheme.
read -r -p "This will delete the current partition table on $DISK once installation starts. Do you agree [y/N]? " disk_response echo -en "${BOLD}${UNDERLINE}${BRED}This will delete the current partition table on $DISK once installation starts. Do you agree [y/N]?${RESET} "
read -r disk_response
disk_response=${disk_response,,} disk_response=${disk_response,,}
if ! [[ "$disk_response" =~ ^(yes|y)$ ]]; then if ! [[ "$disk_response" =~ ^(yes|y)$ ]]; then
print "Quitting." print "Quitting."
@ -244,18 +262,18 @@ fi
lukspass_selector lukspass_selector
# Setting up the kernel. # Setting up the kernel.
kernel_selector until kernel_selector; do : ; done
# User choses the network. # User choses the network.
network_selector until network_selector; do : ; done
# Setting up the locale. # User choses the locale.
locale_selector until locale_selector; do : ; done
# Setting up the hostname. # User choses the hostname.
hostname_selector until hostname_selector; do : ; done
# Setting username. # User chooses username.
read -r -p "Please enter name for a user account (enter empty to not create one): " username read -r -p "Please enter name for a user account (enter empty to not create one): " username
userpass_selector userpass_selector
rootpass_selector rootpass_selector
@ -324,6 +342,9 @@ echo "LANG=$locale" > /mnt/etc/locale.conf
print "Installing the base system (it may take a while)." print "Installing the base system (it may take a while)."
pacstrap /mnt --needed base $kernel $microcode linux-firmware $kernel-headers btrfs-progs grub grub-btrfs rsync efibootmgr snapper reflector base-devel snap-pac zram-generator >/dev/null pacstrap /mnt --needed base $kernel $microcode linux-firmware $kernel-headers btrfs-progs grub grub-btrfs rsync efibootmgr snapper reflector base-devel snap-pac zram-generator >/dev/null
# Setting up the hostname.
echo "$hostname" > /mnt/etc/hostname
# Generating /etc/fstab. # Generating /etc/fstab.
print "Generating a new fstab." print "Generating a new fstab."
genfstab -U /mnt >> /mnt/etc/fstab genfstab -U /mnt >> /mnt/etc/fstab
@ -342,7 +363,7 @@ microcode_detector
# Virtualization check. # Virtualization check.
virt_check virt_check
# Set up the network. # Setting up the network.
network_installer network_installer
# Configuring /etc/mkinitcpio.conf. # Configuring /etc/mkinitcpio.conf.