added support for more drive partition prefix formats (e.g. nvmen1p1), and added status banners throughout the execution

This commit is contained in:
2025-05-28 21:25:13 +02:00
parent 0edde669df
commit 59f6eb5867
+39 -9
View File
@@ -6,7 +6,18 @@ ROOT_PASSWORD=""
USERNAME="" USERNAME=""
USER_PASSWORD="" USER_PASSWORD=""
send_status_message() {
term_width=$(tput cols 2>/dev/null || echo 80)
msg="$1"
edge=$(printf '%*s' "$term_width" '' | tr ' ' '=')
printf "\n%s\n" "$edge"
printf "%*s\n" $(((${#msg} + term_width) / 2)) "$msg"
printf "%s\n\n" "$edge"
}
get_config_inputs() { get_config_inputs() {
send_status_message "CONFIGURATION: Getting user inputs"
while [ -z "$HOSTNAME" ]; do while [ -z "$HOSTNAME" ]; do
printf "Enter hostname: " printf "Enter hostname: "
read HOSTNAME read HOSTNAME
@@ -67,8 +78,10 @@ get_config_inputs() {
# Function to get drive name # Function to get drive name
DISK="" DISK=""
get_drive() { get_drive() {
send_status_message "DRIVE SETUP: Selecting and confirming target drive"
lsblk lsblk
printf "\nEnter the drive name (e.g., sda, sdb, vda): " printf "\nEnter the drive name (e.g., sda, sdb, vda, nvme0n1): "
read DISK read DISK
if [ -z "${DISK}" ]; then if [ -z "${DISK}" ]; then
echo "No drive name entered. Exiting." echo "No drive name entered. Exiting."
@@ -76,6 +89,11 @@ get_drive() {
fi fi
DISK="/dev/${DISK}" DISK="/dev/${DISK}"
PART_PREFIX="$DISK"
case "$DISK" in
*nvme*n*) PART_PREFIX="${DISK}p" ;; # nvme devices need a 'p' before partition number
*) PART_PREFIX="${DISK}" ;;
esac
printf "WARNING: All data on %s will be erased. Are you sure? [Y/n] " "${DISK}" printf "WARNING: All data on %s will be erased. Are you sure? [Y/n] " "${DISK}"
read CONFIRMATION read CONFIRMATION
@@ -103,6 +121,8 @@ get_drive() {
} }
setup_partitions() { setup_partitions() {
send_status_message "PARTITIONING: Creating partitions and filesystems"
if [ ! -d "/sys/firmware/efi" ]; then # Checking for BIOS system if [ ! -d "/sys/firmware/efi" ]; then # Checking for BIOS system
echo "BIOS systems are not supported." echo "BIOS systems are not supported."
fi fi
@@ -118,28 +138,30 @@ setup_partitions() {
partprobe ${DISK} # reread partition table to ensure it is correct partprobe ${DISK} # reread partition table to ensure it is correct
# Create filesystems # Create filesystems
mkfs.fat -F32 -n "BOOT" ${DISK}1 mkfs.fat -F32 -n "BOOT" ${PART_PREFIX}1
mkswap -f ${DISK}2 mkswap -f ${PART_PREFIX}2
mkfs.ext4 -F -L "ROOT" ${DISK}3 mkfs.ext4 -F -L "ROOT" ${PART_PREFIX}3
# Mount # Mount
mount ${DISK}3 /mnt mount ${PART_PREFIX}3 /mnt
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to mount the ROOT partition." echo "Failed to mount the ROOT partition."
exit 2 # Exit if mounting ROOT partition fails exit 2 # Exit if mounting ROOT partition fails
fi fi
mount --mkdir ${DISK}1 /mnt/boot mount --mkdir ${PART_PREFIX}1 /mnt/boot
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to mount the BOOT partition." echo "Failed to mount the BOOT partition."
exit 2 # Exit if mounting BOOT partition fails exit 2 # Exit if mounting BOOT partition fails
fi fi
swapon ${DISK}2 swapon ${PART_PREFIX}2
} }
# Setup systemdboot as the bootloader # Setup systemdboot as the bootloader
setup_bootloader() { setup_bootloader() {
send_status_message "BOOTLOADER: Installing and configuring systemd-boot"
# Run bootctl inside chroot # Run bootctl inside chroot
arch-chroot /mnt bootctl install arch-chroot /mnt bootctl install
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -151,7 +173,7 @@ setup_bootloader() {
ARCH_ENTRY_TEMPLATE="/mnt/usr/share/systemd/bootctl/arch.conf" ARCH_ENTRY_TEMPLATE="/mnt/usr/share/systemd/bootctl/arch.conf"
# Get PARTUUID for the root partition # Get PARTUUID for the root partition
PARTUUID=$(blkid | grep "${DISK}3" | awk -F= '{print $NF}' | tr -d '\"') PARTUUID=$(blkid | grep "${PART_PREFIX}3" | awk -F= '{print $NF}' | tr -d '\"')
if [ -z "$PARTUUID" ]; then if [ -z "$PARTUUID" ]; then
echo "Error: Unable to find PARTUUID for ${DISK}3." echo "Error: Unable to find PARTUUID for ${DISK}3."
@@ -185,21 +207,25 @@ echo ""
setup_partitions setup_partitions
# Then install the kernel and some required packages # Then install the kernel and some required packages
send_status_message "BASE INSTALLATION: Installing base system with pacstrap"
pacstrap -K /mnt base linux linux-firmware networkmanager lemurs sudo pacstrap -K /mnt base linux linux-firmware networkmanager lemurs sudo
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: Failed to install base system." echo "Error: Failed to install base system."
exit 4 exit 4
fi fi
send_status_message "SYSTEM CONFIG: Generating fstab"
genfstab -U /mnt >>/mnt/etc/fstab genfstab -U /mnt >>/mnt/etc/fstab
# Setup base locales # Setup base locales
send_status_message "SYSTEM CONFIG: Setting timezone, locales, and hostname"
ln -sf /usr/share/zoneinfo/Europe/Paris /mnt/etc/localtime ln -sf /usr/share/zoneinfo/Europe/Paris /mnt/etc/localtime
echo 'en_US.UTF-8 UTF-8' >>/mnt/etc/locale.gen echo 'en_US.UTF-8 UTF-8' >>/mnt/etc/locale.gen
arch-chroot /mnt locale-gen arch-chroot /mnt locale-gen
echo LANG=en_US.UTF-8 >/mnt/etc/locale.conf echo LANG=en_US.UTF-8 >/mnt/etc/locale.conf
echo $HOSTNAME >/mnt/etc/hostname echo $HOSTNAME >/mnt/etc/hostname
send_status_message "USER SETUP: Creating user and setting passwords"
# Set root password # Set root password
arch-chroot /mnt bash -c "echo 'root:$ROOT_PASSWORD' | chpasswd" arch-chroot /mnt bash -c "echo 'root:$ROOT_PASSWORD' | chpasswd"
@@ -211,9 +237,13 @@ arch-chroot /mnt bash -c "echo '$USERNAME:$USER_PASSWORD' | chpasswd"
arch-chroot /mnt usermod -aG wheel $USERNAME arch-chroot /mnt usermod -aG wheel $USERNAME
arch-chroot /mnt bash -c "echo '%wheel ALL=(ALL) ALL' | EDITOR='tee -a' visudo" arch-chroot /mnt bash -c "echo '%wheel ALL=(ALL) ALL' | EDITOR='tee -a' visudo"
send_status_message "SERVICES: Enabling NetworkManager and lemurs"
# Setup services and display manager # Setup services and display manager
arch-chroot /mnt systemctl enable NetworkManager lemurs arch-chroot /mnt systemctl enable NetworkManager lemurs
setup_bootloader setup_bootloader
send_status_message "CLEANUP: Unmounting all filesystems"
umount -A -R /mnt # Unmount everything for safety umount -A -R /mnt # Unmount everything for safety
printf "\n\n\n==> Installation finished, you can now reboot.\n"
send_status_message "Installation finished. Reboot now."