From 2c543a2ffd13aa41572f896f6374f858000f45b7 Mon Sep 17 00:00:00 2001 From: Jane Doe Date: Tue, 11 Jun 2024 20:03:05 +0000 Subject: [PATCH] A new mechanism has been added, that scans the partitions on the installation disk and if more than one of each type {root/EFI/home/swap} are detected, it Auto-Assigns the 1st partition of each type, to be used by systemd's automation in the installation (as the 'Discoverable Partitions Specifications' dictate). Of course comes with its own menu/prompts, for user interaction. --- Amelia.sh | 284 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 256 insertions(+), 28 deletions(-) diff --git a/Amelia.sh b/Amelia.sh index f7d2270..04965f7 100644 --- a/Amelia.sh +++ b/Amelia.sh @@ -1,7 +1,7 @@ #!/bin/bash # Amelia Installer -# Version: 5.1 +# Version: 5.2 set -euo pipefail trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR @@ -153,7 +153,6 @@ unmount (){ ${magenta}###${nc}-----------------------------------${magenta}[ ${bwhite}Unmount Filesystems${nc} ${magenta}]${nc}-----------------------------------${magenta}###${nc} " if umount -R /mnt > /dev/null 2>&1 ; then - swapoff "${swap_dev}" > /dev/null 2>&1 sleep 0.3 NC " @@ -256,7 +255,7 @@ arch (){ cnfg (){ line3 YELLOWBGBL "------------------------------------------------------------------------------------------------- " - YELLOWBGBL " ### Configuring... ### " + YELLOWBGBL " ### Configuring... ### " YELLOWBGBL "------------------------------------------------------------------------------------------------- " echo sleep 0.3 @@ -2396,11 +2395,197 @@ sanity_check (){ ${magenta}###${nc}--------------------------------------${magenta}[ ${bwhite}Sanity Check${nc} ${magenta}]${nc}--------------------------------------${magenta}###${nc} " - root_dev="$(fdisk -l "${instl_drive}" | grep 'root' | awk "{print \$1}")" - boot_dev="$(fdisk -l "${instl_drive}" | grep 'EFI' | awk "{print \$1}")" - home_dev="$(fdisk -l "${instl_drive}" | grep 'home' | awk "{print \$1}")" - swap_dev="$(fdisk -l "${instl_drive}" | grep 'swap' | awk "{print \$1}")" + rootcount="$(fdisk -l "${instl_drive}" | grep -E -c 'root' | awk "{print \$1}")" + root_dev="$(fdisk -l "${instl_drive}" | grep -E 'root' | awk "{print \$1}")" + multi_root="$(fdisk -l "${instl_drive}" | grep -E 'root' | awk "{print \$1}" | cat --number)" + root_comply="$(fdisk -l "${instl_drive}" | grep -E 'root' | awk "{print \$1}" | cat --number | grep -E '1[[:blank:]]' | awk "{print \$2}")" + bootcount="$(fdisk -l "${instl_drive}" | grep -E -c 'EFI' | awk "{print \$1}")" + boot_dev="$(fdisk -l "${instl_drive}" | grep -E 'EFI' | awk "{print \$1}")" + multi_boot="$(fdisk -l "${instl_drive}" | grep -E 'EFI' | awk "{print \$1}" | cat --number)" + boot_comply="$(fdisk -l "${instl_drive}" | grep -E 'EFI' | awk "{print \$1}" | cat --number | grep -E '1[[:blank:]]' | awk "{print \$2}")" + homecount="$(fdisk -l "${instl_drive}" | grep -E -c 'home' | awk "{print \$1}")" + home_dev="$(fdisk -l "${instl_drive}" | grep -E 'home' | awk "{print \$1}")" + multi_home="$(fdisk -l "${instl_drive}" | grep -E 'home' | awk "{print \$1}" | cat --number)" + home_comply="$(fdisk -l "${instl_drive}" | grep -E 'home' | awk "{print \$1}" | cat --number | grep -E '1[[:blank:]]' | awk "{print \$2}")" + swapcount="$(fdisk -l "${instl_drive}" | grep -E -c 'swap' | awk "{print \$1}")" + swap_dev="$(fdisk -l "${instl_drive}" | grep -E 'swap' | awk "{print \$1}")" + multi_swap="$(fdisk -l "${instl_drive}" | grep -E 'swap' | awk "{print \$1}" | cat --number)" + swap_comply="$(fdisk -l "${instl_drive}" | grep -E 'swap' | awk "{print \$1}" | cat --number | grep -E '1[[:blank:]]' | awk "{print \$2}")" + + if [[ "${rootcount}" -gt "1" ]]; then + local prompt="Confirm /Root Partition" + local stage_prompt="Partition" + sleep 0.3 + RED " + [!] WARNING: Multiple Linux x86-64 /Root Partitions have been detected + + " + NC " + Linux x86-64 /Root Partitions: + + ------------------------------ +${multi_root} + ------------------------------ + " + YELLOW " + + ### Only the 1st Linux x86-64 /Root partition on a selected disk can be auto-assigned as a valid /Root partition + + + ### Partition ${nc}${root_comply} ${yellow}is auto-assigned as such and will be ${red}[!] FORMATTED [!] + " + BLUE " + + + > Proceed ? [y/n]" + read -r -p " +==> " autoroot + + if [[ "${autoroot}" == "y" ]]; then + root_dev="${root_comply}" + multiroot_opts="root=PARTUUID=$(blkid -s PARTUUID -o value "${root_dev}") " + ok + line2 + elif [[ "${autoroot}" == "n" ]]; then + stage_fail + else + invalid + echo + return 1 + fi + fi + + if [[ "${bootcount}" -gt "1" ]]; then + local prompt="Confirm /Boot Partition" + local stage_prompt="Partition" + sleep 0.3 + RED " + + [!] WARNING: Multiple EFI Partitions have been detected + + " + NC " + Linux EFI System Partitions: + + ---------------------------- +${multi_boot} + ---------------------------- + " + YELLOW " + + ### Only the 1st EFI partition on a selected disk can be auto-assigned as a valid EFI partition + + + ### Partition ${nc}${boot_comply} ${yellow}is auto-assigned as such and will be ${red}[!] FORMATTED [!] + " + BLUE " + + + > Proceed ? [y/n]" + read -r -p " +==> " autoboot + + if [[ "${autoboot}" == "y" ]]; then + boot_dev="${boot_comply}" + ok + line2 + elif [[ "${autoboot}" == "n" ]]; then + stage_fail + else + invalid + echo + return 1 + fi + fi + + if [[ "${homecount}" -gt "1" ]]; then + local prompt="Confirm /Home Partition" + local stage_prompt="Partition" + sleep 0.3 + RED " + + [!] WARNING: Multiple Linux /Home Partitions have been detected + + " + NC " + Linux /Home Partitions: + + ----------------------- +${multi_home} + ----------------------- + " + YELLOW " + + ### Only the 1st Linux /Home partition on a selected disk can be auto-assigned as a valid /Home partition + + + ### Partition ${nc}${home_comply} ${yellow}is auto-assigned as such and will be ${red}[!] FORMATTED [!] + " + BLUE " + + + > Proceed ? [y/n]" + read -r -p " +==> " autohome + + if [[ "${autohome}" == "y" ]]; then + home_dev="${home_comply}" + ok + line2 + elif [[ "${autohome}" == "n" ]]; then + stage_fail + else + invalid + echo + return 1 + fi + fi + + if [[ "${swapcount}" -gt "1" ]]; then + local prompt="Confirm /Swap Partition" + local stage_prompt="Partition" + sleep 0.3 + RED " + + [!] WARNING: Multiple Linux /Swap Partitions have been detected + + " + NC " + Linux /Swap Partitions: + + ------------------------ +${multi_swap} + ------------------------ + " + YELLOW " + + ### Only the 1st Linux /Swap partition on a selected disk can be auto-assigned as a valid /Swap partition + + + ### Partition ${nc}${swap_comply} ${yellow}is auto-assigned as such and will be ${red}[!] FORMATTED [!] + " + BLUE " + + + > Proceed ? [y/n]" + read -r -p " +==> " autoswap + + if [[ "${autoswap}" == "y" ]]; then + swap_dev="${swap_comply}" + ok + line2 + echo + elif [[ "${autoswap}" == "n" ]]; then + stage_fail + else + invalid + echo + return 1 + fi + fi + local prompt="Installation Disk" if [[ ! -e "${root_dev}" && ! -e "${boot_dev}" ]]; then sanity="no" sleep 0.3 @@ -2475,29 +2660,37 @@ ${magenta}###${nc}--------------------------------------${magenta}[ ${bwhite}San return 0 elif [[ -e "${root_dev}" && -e "${boot_dev}" ]]; then sanity="ok" - sleep 0.3 - NC " - -==> [Linux x86-64 /Root ${green}OK${nc}] " - sleep 0.3 - NC " - -==> [EFI System Partition ${green}OK${nc}] " - - if [[ -e "${home_dev}" ]]; then + if [[ "${autoroot}" != "y" ]]; then sleep 0.3 NC " +==> [Linux x86-64 /Root ${green}OK${nc}] " + fi + if [[ "${autoboot}" != "y" ]]; then + sleep 0.3 + NC " + +==> [EFI System Partition ${green}OK${nc}] " + fi + + if [[ -e "${home_dev}" ]]; then + if [[ "${autohome}" != "y" ]]; then + sleep 0.3 + NC " + ==> [Linux /Home ${green}OK${nc}] " + fi fi if [[ "${swapmode}" == "1" ]]; then if [[ -e "${swap_dev}" ]]; then - sanity="ok" - sleep 0.3 - NC " + if [[ "${autoswap}" != "y" ]]; then + sanity="ok" + sleep 0.3 + NC " ==> [Linux /Swap ${green}OK${nc}] " + fi else sanity="no" sleep 0.3 @@ -2756,16 +2949,36 @@ swappart (){ ${magenta}###${nc}----------------------------------${magenta}[ ${bwhite}Swap Partition Setup${nc} ${magenta}]${nc}----------------------------------${magenta}###${nc} " if mkswap "${swap_dev}" > /dev/null 2>&1 ; then - swapon "${swap_dev}" > /dev/null 2>&1 || stage_fail stage_ok else - swapoff "${swap_dev}" > /dev/null 2>&1 stage_fail fi } ################################################################################################### set_mode (){ + if [[ "${rootcount}" -gt "1" || "${bootcount}" -gt "1" || "${homecount}" -gt "1" || "${swapcount}" -gt "1" ]]; then + line2 + until auto_mode; do : ; done + sleep 0.3 + NC " + +==> [${green}Filesystems OK${nc}] + " + sleep 0.3 + YELLOW " +###---------------------------------------------[ FILESYSTEM OVERVIEW ]---------------------------------------------### + + " + lsblk -f|GREP_COLORS='mt=01;36' grep -E --color=always 'vfat|$'|GREP_COLORS='mt=01;32' grep -E --color=always 'ext4|$'|GREP_COLORS='mt=01;35' grep -E --color=always 'btrfs|$'|GREP_COLORS='mt=01;31' grep -E --color=always 'ntfs|$'|GREP_COLORS='mt=01;33' grep -E --color=always 'swap|$' + YELLOW " + +###-----------------------------------------------------------------------------------------------------------------###" + echo + sleep 1 + return 0 + fi + sleep 0.3 NC " @@ -2823,6 +3036,10 @@ Enter a Mode number: " ################################################################################################### auto_mode (){ + sleep 0.3 + NC " +${magenta}###${nc}----------------------------------------${magenta}[ ${bwhite}Auto Mode${nc} ${magenta}]${nc}----------------------------------------${magenta}###${nc} + " sleep 0.3 YELLOW " @@ -4186,8 +4403,15 @@ ${magenta}###${nc}--------------------------------${magenta}[ ${bwhite}Chroot & mkinitcpio_mods="MODULES=()" fi fi - ### Kernel Boot Options (No Encryption) - boot_opts="${swap_bootopts}${vga_bootopts}${cust_bootopts}${btrfs_bootopts}" + + if [[ "${autoroot}" == "y" ]]; then + ### Kernel Boot Options [Multi-Root Disk] (No Encryption) + boot_opts="${multiroot_opts}${swap_bootopts}${vga_bootopts}${cust_bootopts}${btrfs_bootopts}" + else + ### Kernel Boot Options [Single Root Disk] (No Encryption) + boot_opts="${swap_bootopts}${vga_bootopts}${cust_bootopts}${btrfs_bootopts}" + fi + fi #-------------------------------------------------------------------------------------------------- # NOTE: All Vanilla Desktops Basic Configuration: @@ -4268,10 +4492,10 @@ SLICK options rw ${boot_opts}" | tee /boot/loader/entries/arch.conf || exit systemctl enable systemd-boot-update || exit BOOTCTL - stage_ok - else - stage_fail - fi + stage_ok + else + stage_fail + fi elif [[ "${bootloader}" == "2" ]]; then cnfg stage_prompt="Grub" @@ -4851,6 +5075,10 @@ NVIDIA_HOOK vga_slct="" nvidia_services="" nvidia_suspend="" + autoroot="" + autoboot="" + autohome="" + autoswap="" clear first_check