diff --git a/install.sh b/install.sh index 271a1f3..8531511 100755 --- a/install.sh +++ b/install.sh @@ -55,26 +55,93 @@ setup_partitions() { # Create filesystems mkfs.fat -F32 -n "BOOT" ${DISK}1 - mkswap ${DISK}3 - mkfs.ext4 -L "ROOT" ${DISK}3 + mkswap -f ${DISK}3 + mkfs.ext4 -F -L "ROOT" ${DISK}3 # Mount mount ${DISK}3 /mnt if [ $? -ne 0 ]; then echo "Failed to mount the ROOT partition." - return 1 # Exit if mounting ROOT partition fails + exit 2 # Exit if mounting ROOT partition fails fi mount --mkdir ${DISK}1 /mnt/boot if [ $? -ne 0 ]; then echo "Failed to mount the BOOT partition." - return 1 # Exit if mounting BOOT partition fails + exit 2 # Exit if mounting BOOT partition fails fi swapon ${DISK}2 } -# Main execution flow -get_drive +# Setup systemdboot as the bootloader +setup_bootloader() { + bootctl install -# cat /usr/share/systemd/bootctl/arch.conf | sed "s/^options.*/options root=PARTUUID=$(blkid | grep vda3 | awk -F= '{print $NF}' | tr -d '\"') rw splash/" >/boot/loader/entries/arch.conf + BOOTLOADER_ENTRY="/boot/loader/entries/arch.conf" + ARCH_ENTRY_TEMPLATE="/usr/share/systemd/bootctl/arch.conf" + + # Get PARTUUID for the root partition + PARTUUID=$(blkid | grep "${DISK}3" | awk -F= '{print $NF}' | tr -d '\"') + + if [ -z "$PARTUUID" ]; then + echo "Error: Unable to find PARTUUID for ${DISK}3." + exit 3 + fi + + # Create a new entry based on the template and PARTUUID + echo "Creating bootloader entry with PARTUUID=$PARTUUID" + + sed "s/^options.*/options root=PARTUUID=$PARTUUID rw splash/" "$ARCH_ENTRY_TEMPLATE" >"$BOOTLOADER_ENTRY" + + if [ $? -eq 0 ]; then + echo "Successfully created bootloader entry: $BOOTLOADER_ENTRY" + else + echo "Error: Failed to create the bootloader entry." + exit 3 + fi +} + +# Main execution flow +case $1 in +"install" | "") + # Ask for the drive to install on + get_drive + + # Partition, create filesystems and mount + setup_partitions + + # Then install the kernel and some required packages + pacstrap -K /mnt base linux linux-firmware networkmanager + + genfstab -U /mnt >>/mnt/etc/fstab + + # Copy the script to the new environment for the chroot part + cp ./install.sh /mnt/tmp/ + echo "DISK=${DISK}" >/mnt/etc/install-script-variables.conf + + arch-chroot /mnt /bin/bash -c "/tmp/install.sh chroot" + + umount -A -R /mnt # Unmount everything for safety + printf "\n==> Installation finished, you can now reboot.\n" + ;; + +"chroot") + echo "Running the chroot side" + + . /tmp/install-script-variables.conf + + # Setup base locales + ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime + locale-gen + echo LANG=en_US.UTF-8 >/etc/locale.conf + echo hostname >/etc/hostname + + echo "root:password" | chpasswd + + systemctl enable NetworkManager + + setup_bootloader + + ;; +esac