Merge pull request #47 from i-c-u-p/patch-3

Improvements from icup 🍡
This commit is contained in:
Tommaso Chiti 2022-05-08 10:44:09 +02:00 committed by GitHub
commit 2666b24d10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,9 +3,22 @@
# Cleaning the TTY. # Cleaning the TTY.
clear clear
# Colors/formatting for echo
BOLD='\e[1m'
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} ] $1${RESET}"
}
# Alert user of bad input (function).
incEcho () {
echo -e "${BPURPLE}$1${RESET}"
} }
# Virtualization check (function). # Virtualization check (function).
@ -38,8 +51,6 @@ virt_check () {
systemctl enable hv_fcopy_daemon --root=/mnt &>/dev/null systemctl enable hv_fcopy_daemon --root=/mnt &>/dev/null
systemctl enable hv_kvp_daemon --root=/mnt &>/dev/null systemctl enable hv_kvp_daemon --root=/mnt &>/dev/null
systemctl enable hv_vss_daemon --root=/mnt &>/dev/null systemctl enable hv_vss_daemon --root=/mnt &>/dev/null
;;
* ) ;;
esac esac
} }
@ -50,18 +61,18 @@ kernel_selector () {
print "2) Hardened: A security-focused Linux kernel" print "2) Hardened: A security-focused Linux kernel"
print "3) LTS: Long-term support (LTS) Linux kernel" print "3) LTS: Long-term support (LTS) Linux kernel"
print "4) Zen: A Linux kernel optimized for desktop usage" print "4) Zen: A Linux kernel optimized for desktop usage"
read -r -p "Insert the number of the corresponding kernel: " choice read -r -p "Insert the number of the corresponding kernel: " kernel_choice
case $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
} }
@ -73,8 +84,17 @@ network_selector () {
print "3) wpa_supplicant: Cross-platform supplicant with support for WEP, WPA and WPA2 (WiFi-only, a DHCP client will be automatically installed as well)" print "3) wpa_supplicant: Cross-platform supplicant with support for WEP, WPA and WPA2 (WiFi-only, a DHCP client will be automatically installed as well)"
print "4) dhcpcd: Basic DHCP client (Ethernet only or VMs)" print "4) dhcpcd: Basic DHCP client (Ethernet only or VMs)"
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: " choice read -r -p "Insert the number of the corresponding networking utility: " network_choice
case $choice in if ! ((1 <= network_choice <= 5)); then
incEcho "You did not enter a valid selection."
return 1
fi
return 0
}
# Installing the chosen networking method to the system (function).
network_installer () {
case $network_choice in
1 ) print "Installing IWD." 1 ) print "Installing IWD."
pacstrap /mnt iwd >/dev/null pacstrap /mnt iwd >/dev/null
print "Enabling IWD." print "Enabling IWD."
@ -95,68 +115,58 @@ network_selector () {
pacstrap /mnt dhcpcd >/dev/null pacstrap /mnt dhcpcd >/dev/null
print "Enabling dhcpcd." print "Enabling dhcpcd."
systemctl enable dhcpcd --root=/mnt &>/dev/null systemctl enable dhcpcd --root=/mnt &>/dev/null
;;
5 ) ;;
* ) print "You did not enter a valid selection."
network_selector
esac esac
} }
# Setting up a password for the LUKS Container (function). # User enters a password for the LUKS Container (function).
lukspass_selector () { lukspass_selector () {
while true; do
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 if [ -z "$password" ]; then
echo incEcho "\nYou need to enter a password for the LUKS Container in order to continue."
print "You need to enter a password for the LUKS Container in order to continue." return 1
read -r -s -p "Insert password for the LUKS container (you're not going to see the password): " password fi
[ -n "$password" ] && break
done
echo echo
read -r -s -p "Password (again): " password2 read -r -s -p "Password (again): " password2
echo echo
[ "$password" = "$password2" ] && break if [ "$password" != "$password2" ]; then
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done return 1
echo -n "$password" | cryptsetup luksFormat "$CRYPTROOT" -d - fi
echo -n "$password" | cryptsetup open "$CRYPTROOT" cryptroot -d - return 0
BTRFS="/dev/mapper/cryptroot"
} }
# Setting up a password for the user account (function). # User enters a password for the user account (function).
userpass_selector () { userpass_selector () {
while true; do
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 if [ -z "$userpass" ]; then
echo incEcho "\nYou need to enter a password for $username."
print "You need to enter a password for $username." return 1
read -r -s -p "Set a user password for $username: " userpass fi
[ -n "$userpass" ] && break
done
echo echo
read -r -s -p "Insert password again: " userpass2 read -r -s -p "Insert password again: " userpass2
echo echo
[ "$userpass" = "$userpass2" ] && break if [ "$userpass" != "$userpass2" ]; then
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done return 1
fi
return 0
} }
# Setting up a password for the root account (function). # User enters a password for the root account (function).
rootpass_selector () { rootpass_selector () {
while true; do
read -r -s -p "Set a root password: " rootpass read -r -s -p "Set a root password: " rootpass
while [ -z "$rootpass" ]; do if [ -z "$rootpass" ]; then
echo incEcho "\nYou need to enter a root password."
print "You need to enter a root password." return 1
read -r -s -p "Set a root password: " rootpass fi
[ -n "$rootpass" ] && break
done
echo echo
read -r -s -p "Password (again): " rootpass2 read -r -s -p "Password (again): " rootpass2
echo echo
[ "$rootpass" = "$rootpass2" ] && break if [ "$rootpass" != "$rootpass2" ]; then
echo "Passwords don't match, try again." incEcho "Passwords don't match, try again."
done return 1
fi
return 0
} }
# Microcode detector (function). # Microcode detector (function).
@ -171,59 +181,102 @@ microcode_detector () {
fi fi
} }
# Setting up the hostname (function). # User enters a 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). # User chooses the locale (function).
locale_selector () { locale_selector () {
read -r -p "Please insert the locale you use (format: xx_XX or enter empty to use en_US): " locale read -r -p "Please insert the locale you use (format: xx_XX. Enter empty to use en_US, or \"/\" to search locales): " locale
if [ -z "$locale" ]; then case $locale in
print "en_US will be used as default locale." '') locale="en_US.UTF-8"
locale="en_US" print "$locale will be the default locale."
return 0;;
'/') sed -E '/^# +|^#$/d;s/^#| *$//g;s/ .*/ (Charset:&)/' /etc/locale.gen | less -M
clear
return 1;;
*) if ! grep -q "^#\?$(sed 's/[].*[]/\\&/g' <<< $locale) " /etc/locale.gen; then
incEcho "The specified locale doesn't exist or isn't supported."
return 1
fi fi
echo "$locale.UTF-8 UTF-8" > /mnt/etc/locale.gen return 0
echo "LANG=$locale.UTF-8" > /mnt/etc/locale.conf esac
} }
# Setting up the keyboard layout (function). # User chooses the console keyboard layout (function).
keyboard_selector () { keyboard_selector () {
read -r -p "Please insert the keyboard layout you use (enter empty to use US keyboard layout): " kblayout read -r -p "Please insert the keyboard keymap/layout to use in console (enter empty to use us, or \"/\" to search keymaps): " kblayout
if [ -z "$kblayout" ]; then case $kblayout in
print "US keyboard layout will be used by default." '') kblayout="us"
kblayout="us" print "$kblayout will be the default console keymap."
return 0;;
'/') localectl list-keymaps
clear
return 1;;
*) if ! localectl list-keymaps | grep -Fxq $kblayout; then
incEcho "The specified keymap doesn't exist."
return 1
fi fi
echo "KEYMAP=$kblayout" > /mnt/etc/vconsole.conf print "Changing console layout to $kblayout."
loadkeys $kblayout
return 0
esac
} }
# Selecting the target for the installation. # Selecting the target for the installation.
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."
PS3="Please select the disk NUMBER e.g. 1 where Arch Linux is going to be installed: "
# Setting up keyboard layout.
until keyboard_selector; do : ; done
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");
do do
DISK=$ENTRY DISK=$ENTRY
print "Installing Arch Linux on $DISK." print "Arch Linux will be installed to $DISK."
break break
done done
# Deleting old partition scheme. # Warn user about deletion of old partition scheme.
read -r -p "This will delete the current partition table on $DISK. Do you agree [y/N]? " response echo -en "${BOLD}${BRED}This will delete the current partition table on $DISK once installation starts. Do you agree [y/N]?:${RESET} "
response=${response,,} read -r disk_response
if [[ "$response" =~ ^(yes|y)$ ]]; then if ! [[ "${disk_response,,}" =~ ^(yes|y)$ ]]; then
print "Wiping $DISK."
wipefs -af "$DISK" &>/dev/null
sgdisk -Zo "$DISK" &>/dev/null
else
print "Quitting." print "Quitting."
exit exit
fi fi
# Setting up LUKS password.
until lukspass_selector; do : ; done
# Setting up the kernel.
until kernel_selector; do : ; done
# User choses the network.
until network_selector; do : ; done
# User choses the locale.
until locale_selector; do : ; done
# User choses the hostname.
until hostname_selector; do : ; done
# User chooses username.
read -r -p "Please enter name for a user account (enter empty to not create one): " username
until userpass_selector; do : ; done
until rootpass_selector; do : ; done
# Deleting old partition scheme.
print "Wiping $DISK."
wipefs -af "$DISK" &>/dev/null
sgdisk -Zo "$DISK" &>/dev/null
# Creating a new partition scheme. # Creating a new partition scheme.
print "Creating the partitions on $DISK." print "Creating the partitions on $DISK."
parted -s "$DISK" \ parted -s "$DISK" \
@ -245,7 +298,9 @@ mkfs.fat -F 32 $ESP &>/dev/null
# Creating a LUKS Container for the root partition. # Creating a LUKS Container for the root partition.
print "Creating LUKS Container for the root partition." print "Creating LUKS Container for the root partition."
lukspass_selector echo -n "$password" | cryptsetup luksFormat "$CRYPTROOT" -d -
echo -n "$password" | cryptsetup open "$CRYPTROOT" cryptroot -d -
BTRFS="/dev/mapper/cryptroot"
# Formatting the LUKS Container as BTRFS. # Formatting the LUKS Container as BTRFS.
print "Formatting the LUKS container as BTRFS." print "Formatting the LUKS container as BTRFS."
@ -254,58 +309,41 @@ mount $BTRFS /mnt
# Creating BTRFS subvolumes. # Creating BTRFS subvolumes.
print "Creating BTRFS subvolumes." print "Creating BTRFS subvolumes."
for volume in @ @home @root @srv @snapshots @var_log @var_pkgs subvols=(snapshots var_pkgs var_log home root srv)
do for subvol in '' "${subvols[@]}"; do
btrfs su cr /mnt/$volume btrfs su cr /mnt/@"$subvol"
done done
# Mounting the newly created subvolumes. # Mounting the newly created subvolumes.
umount /mnt umount /mnt
print "Mounting the newly created subvolumes." print "Mounting the newly created subvolumes."
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@ $BTRFS /mnt mountopts="ssd,noatime,compress-force=zstd:3,discard=async"
mkdir -p /mnt/{home,root,srv,.snapshots,/var/log,/var/cache/pacman/pkg,boot} mount -o $mountopts,subvol=@ $BTRFS /mnt
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@home $BTRFS /mnt/home mkdir -p /mnt/{home,root,srv,.snapshots,var/{log,cache/pacman/pkg},boot}
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@root $BTRFS /mnt/root for subvol in "${subvols[@]:2}"; do # ":2" excludes first two subvols (@snapshots and @var_pkgs) from loop
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@srv $BTRFS /mnt/srv mount -o "$mountopts",subvol=@"$subvol" "$BTRFS" /mnt/"${subvol//_//}"
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@snapshots $BTRFS /mnt/.snapshots done
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@var_log $BTRFS /mnt/var/log chmod 750 /mnt/root
mount -o ssd,noatime,compress-force=zstd:3,discard=async,subvol=@var_pkgs $BTRFS /mnt/var/cache/pacman/pkg mount -o $mountopts,subvol=@snapshots $BTRFS /mnt/.snapshots
mount -o $mountopts,subvol=@var_pkgs $BTRFS /mnt/var/cache/pacman/pkg
chattr +C /mnt/var/log chattr +C /mnt/var/log
mount $ESP /mnt/boot/ mount $ESP /mnt/boot/
# Setting up the kernel.
kernel_selector
# Checking the microcode to install.
microcode_detector
# Virtualization check.
virt_check
# Setting up the network.
network_selector
# Pacstrap (setting up a base sytem onto the new root). # Pacstrap (setting up a base sytem onto the new root).
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. # Setting up the hostname.
hostname_selector 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
# Setting username. # Configure selected locale and console keymap
read -r -p "Please enter name for a user account (enter empty to not create one): " username sed -i "/^#$locale/s/^#//" /mnt/etc/locale.gen
userpass_selector echo "LANG=$locale" > /mnt/etc/locale.conf
rootpass_selector echo "KEYMAP=$kblayout" > /mnt/etc/vconsole.conf
# Setting up the locale.
locale_selector
# Setting up keyboard layout.
keyboard_selector
# Setting hosts file. # Setting hosts file.
print "Setting hosts file." print "Setting hosts file."
@ -315,6 +353,15 @@ cat > /mnt/etc/hosts <<EOF
127.0.1.1 $hostname.localdomain $hostname 127.0.1.1 $hostname.localdomain $hostname
EOF EOF
# Checking the microcode to install.
microcode_detector
# Virtualization check.
virt_check
# Setting up the network.
network_installer
# Configuring /etc/mkinitcpio.conf. # Configuring /etc/mkinitcpio.conf.
print "Configuring /etc/mkinitcpio.conf." print "Configuring /etc/mkinitcpio.conf."
cat > /mnt/etc/mkinitcpio.conf <<EOF cat > /mnt/etc/mkinitcpio.conf <<EOF
@ -325,7 +372,7 @@ EOF
# Setting up LUKS2 encryption in grub. # Setting up LUKS2 encryption in grub.
print "Setting up grub config." print "Setting up grub config."
UUID=$(blkid -s UUID -o value $CRYPTROOT) UUID=$(blkid -s UUID -o value $CRYPTROOT)
sed -i "s,^GRUB_CMDLINE_LINUX=\"\",GRUB_CMDLINE_LINUX=\"rd.luks.name=$UUID=cryptroot root=$BTRFS\",g" /mnt/etc/default/grub sed -i "\,^GRUB_CMDLINE_LINUX=\"\",s,\",&rd.luks.name=$UUID=cryptroot root=$BTRFS," /mnt/etc/default/grub
# Configuring the system. # Configuring the system.
arch-chroot /mnt /bin/bash -e <<EOF arch-chroot /mnt /bin/bash -e <<EOF
@ -374,7 +421,7 @@ echo "root:$rootpass" | arch-chroot /mnt chpasswd
if [ -n "$username" ]; then if [ -n "$username" ]; then
print "Adding the user $username to the system with root privilege." print "Adding the user $username to the system with root privilege."
arch-chroot /mnt useradd -m -G wheel -s /bin/bash "$username" arch-chroot /mnt useradd -m -G wheel -s /bin/bash "$username"
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers sed -i '/^# %wheel ALL=(ALL) ALL/s/^# //' /mnt/etc/sudoers
print "Setting user password for $username." print "Setting user password for $username."
echo "$username:$userpass" | arch-chroot /mnt chpasswd echo "$username:$userpass" | arch-chroot /mnt chpasswd
fi fi
@ -406,7 +453,7 @@ EOF
# Pacman eye-candy features. # Pacman eye-candy features.
print "Enabling colours, animations, and parallel in pacman." print "Enabling colours, animations, and parallel in pacman."
sed -i 's/#Color/Color\nILoveCandy/;s/^#ParallelDownloads.*$/ParallelDownloads = 10/' /mnt/etc/pacman.conf sed -Ei 's/^#(Color)$/\1\nILoveCandy/;s/^#(ParallelDownloads).*/\1 = 10/' /mnt/etc/pacman.conf
# Enabling various services. # Enabling various services.
print "Enabling Reflector, automatic snapshots, BTRFS scrubbing and systemd-oomd." print "Enabling Reflector, automatic snapshots, BTRFS scrubbing and systemd-oomd."