From ee1692eaf63404cadafabb407c709a2d2f5c071b Mon Sep 17 00:00:00 2001 From: davidovski Date: Thu, 19 Jan 2023 15:48:55 +0000 Subject: Fix bootstrap umounting efi --- iso/root/installer.sh | 229 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 183 insertions(+), 46 deletions(-) (limited to 'iso/root/installer.sh') diff --git a/iso/root/installer.sh b/iso/root/installer.sh index bed9ce8..de06852 100755 --- a/iso/root/installer.sh +++ b/iso/root/installer.sh @@ -4,10 +4,37 @@ . /usr/lib/glyphs.sh . /usr/lib/colors.sh +DEBUG_MODE=false + logfile="installer.log" -default_packages="base linux xipkg dracut grub mksh sudo neofetch vim tzdata" +default_packages="base xipkg dracut grub doas neofetch vim tzdata mksh" additional_services="networkmanager xorg iwd" +OPT_KERNEL="linux-libre" +OPT_BOOTSYSTEM="efi" +OPT_ENCRYPTION="none" + +welcome_splash () { + t_radio "Welcome to the xilinux installer" "install xilinux" "network configuration" "exit to shell" + + case "$T_RESULT" in + "network configuration") + t_clean + nmtui + t_init + welcome_splash + ;; + "install xilinux") + return 0 + ;; + *) + t_clean + exit 0 + ;; + esac +} + + list_disks () { lsblk -r | while read -r line; do set - $line @@ -24,42 +51,89 @@ list_partitions () { partition_disk () { t_msg "Partitioning $1..." - export EFI_PART=$11 - export SYS_PART=$12 + + # if is efi, create an efi partition + efi= + [ "$OPT_BOOTSYSTEM" = "efi" ] && { + export EFI_PART=$11 + export SYS_PART=$12 + efi="type=ef, start=2048, size=210000" + } || { + export SYS_PART=$11 + } + export SWAP_PART=none + echo " unit: sectors sector-size: 512 - type=ef, start=2048, size=210000 + $efi type=83 - " | sfdisk $1 >$logfile && + " | sfdisk $1 >>$logfile && t_msg "Partitioned $1!" } -welcome_splash () { - t_radio "welcome to the xilinux installer" "continue" "exit to shell" - [ "$T_RESULT" != "continue" ] && { - t_clean - exit 0 +detect_efi () { + [ -d "/sys/firmware/efi" ] \ + && OPT_BOOTSYSTEM="efi" \ + || OPT_BOOTSYSTEM="bios" + + t_yesno "Detected boot system as '$OPT_BOOTSYSTEM', is this correct?" || { + [ $OPT_BOOTSYSTEM = "efi" ] \ + && OPT_BOOTSYSTEM="bios" \ + || OPT_BOOTSYSTEM="efi" } + return 0 } +encrypt_disk () { + #t_yesno "${LIGHT_RED}Warning this will ${RED}irreversibly ${LIGHT_RED} erase all data.\n${BLUE}continue?" || { + #partition_disks + #return 1 + #} + #t_msg "Wiping disk $ROOT_DISK..." + #printf "YES\n" | cryptsetup open --type plain -d /dev/urandom $ROOT_DISK to_be_wiped >> $logfile + #dd if=/dev/zero of=/dev/mapper/to_be_wiped >> $logfile + #cryptsetup close to_be_wiped >> $logfile + + partition_disk $ROOT_DISK + enter_password "disk encryption password" + t_msg "Encrypting $ROOT_DISK.." + printf "$passwd" | cryptsetup luksFormat $SYS_PART -d ->> $logfile + + printf "$passwd" | cryptsetup luksOpen $SYS_PART cryptlvm -d - >> $logfile + + pvcreate /dev/mapper/cryptlvm >> $logfile + vgcreate xilinux /dev/mapper/cryptlvm >> $logfile + + lvcreate -l 100%FREE xilinux -n root >> $logfile + + export SYS_PART=/dev/xilinux/root + return 0 +} partition_disks () { # need to use eval to work with spaces in line names eval "t_radio 'Select install disk' $(list_disks)" local selected=$(echo $T_RESULT | cut -d' ' -f1) + export ROOT_DISK=$selected - t_yesno "${BLUE}Auto-partition $selected disk?\n${RED}(Warning: existing data will be overwritten)" && { + t_yesno "${BLUE}Use full disk encryption?" && { + export OPT_ENCRYPTION="lvm-luks" + encrypt_disk $ROOT_DISK + return 0 + } || t_yesno "${BLUE}Auto-partition $selected disk?\n${RED}(Warning: existing data will be overwritten)" && { partition_disk $selected || return 1 } || { cfdisk $selected && { t_radio 'Select primary system partition' $(list_partitions $selected) export SYS_PART=$T_RESULT - t_radio 'Select efi system partition' $(list_partitions $selected) - export EFI_PART=$T_RESULT + [ $OPT_BOOTSYSTEM = "efi" ] && { + t_radio 'Select efi system partition' $(list_partitions $selected) + export EFI_PART=$T_RESULT + } t_radio 'Select swap partition' $(list_partitions $selected) export SWAP_PART=$T_RESULT @@ -74,26 +148,26 @@ ${TABCHAR}EFI Partition " - [ -b "$SYS_PART" ] && mkfs.ext4 $SYS_PART > $logfile + [ -b "$SYS_PART" ] && mkfs.ext4 $SYS_PART >> $logfile t_msg "Formatting partitions... ${GREEN}${TABCHAR}System partition ${CHECKMARK} (ext4) ${TABCHAR}EFI Partition " - [ -b "$EFI_PART" ] && mkfs.fat -F 32 $EFI_PART > $logfile + [ -b "$EFI_PART" ] && mkfs.fat -F 32 $EFI_PART >> $logfile t_msg "Formatting partitions... ${GREEN}${TABCHAR}System partition ${CHECKMARK} (ext4) ${GREEN}${TABCHAR}EFI Partition ${CHECKMARK} (fat32) " - [ -b "$SWAP_PART" ] && mkswap $SWAP_PART > $logfile + [ -b "$SWAP_PART" ] && mkswap $SWAP_PART >> $logfile return 0 } mount_disks () { t_msg "Mounting disks..." export sysroot=/xilinux.mnt - export efi_mntpoint=/xilinux.mnt/boot/efi + export efi_mntpoint=/xilinux.mnt/boot [ ! -f "$sysroot" ] && mkdir -p $sysroot @@ -104,6 +178,7 @@ mount_disks () { return 1 } + echo "[efi] mounting $EFI_PART to $efi_mntpoint" >> $logfile [ -b "$EFI_PART" ] && { mkdir -p $efi_mntpoint mount $EFI_PART $efi_mntpoint @@ -113,15 +188,25 @@ mount_disks () { return 0 } +prompt_kernel () { + t_radio "Select which kernel you would like to use:" "linux-libre" "linux" + OPT_KERNEL=$T_RESULT +} + bootstrap_system () { t_msg "Creating directories..." - xi -vy -r $sysroot bootstrap >> $logfile + xi -qvy -r $sysroot bootstrap >> $logfile } install_base () { - t_msg "Installing packages..." - xi -vy -r $sysroot sync >> $logfile - xi -vy -r $sysroot install $default_packages >> $logfile + { + t_msg "Syncing repos..." + xi -qvy -r $sysroot sync >> $logfile + for pkg in $default_packages $OPT_KERNEL; do + t_msg "${BLUE}Installing packages...${RESET}$pkg" + xi -qlvy -r $sysroot install $pkg >> $logfile + done + } } copy_resolvconf () { @@ -140,46 +225,63 @@ generate_fstab () { } build_initramfs () { - t_msg "Build initramfs" - - kernel_version=$(ls $SYSROOT/usr/lib/modules | tail -1) mkdir -p $sysroot/var/tmp - xichroot $sysroot dracut --kver $kernel_version 2>&1 >> $logfile + for kernel_version in $(ls $sysroot/usr/lib/modules); do + t_msg "Building initramfs for $kernel_version..." + xichroot $sysroot dracut --kver $kernel_version 2>&1 >> $logfile + done } install_grub () { t_yesno "Install grub?" && { - target="x86_64-efi" - opts="--target=$target --efi-directory=$efi_mntpoint" - - t_yesno "Install as removable system?" && opts="$opts --removable" + [ "$OPT_BOOTSYSTEM" = "efi" ] && { + target="x86_64-efi" + opts="--target=$target --efi-directory=$efi_mntpoint" + t_yesno "Install as removable system?" && opts="--removable $opts " || true + } || { + target="i386-pc" + opts="--target=$target $ROOT_DISK" + } t_msg "Installing grub for target $target..." - xichrooot $sysroot grub-install $opts >> $logfile + xichroot $sysroot grub-install $opts >> $logfile t_msg "Creating grub configuration..." - xichrooot $sysroot grub-mkconfig -o /boot/grub/grub.cfg + xichroot $sysroot grub-mkconfig -o /boot/grub/grub.cfg + + t_prompt "Installed grub for $target" } || return 0 } +configure_hostname () { + t_input "Enter hostname:" + local hostname=$T_RESULT + echo $hostname > $sysroot/etc/hostname + + cat > $sysroot/etc/hosts << EOF +127.0.0.1 localhost +::1 localhost +127.0.1.1 $hostname.local $hostname +EOF +} + enter_password () { + local label=${1:-password} export passwd="" - t_input_hidden "Enter Password:" + t_input_hidden "Enter $label:" passwd=$T_RESULT - t_input_hidden "Confirm Password:" + t_input_hidden "Confirm $label" local cpasswd=$T_RESULT [ "$passwd" = "$cpasswd" ] || { t_prompt "Passwords do not match!" - enter_password + enter_password $* } } configure_users () { - t_input_cmd "xichroot $sysroot passwd" "Enter root password" - t_input "Enter username:" local username=$T_RESULT enter_password @@ -188,8 +290,9 @@ configure_users () { xichroot $sysroot useradd -s /bin/mksh -m $username printf "$passwd\n$passwd\n" | xichroot $sysroot passwd $username - t_yesno "Allow this user to use sudo?" && { - echo "$username ALL=(ALL:ALL) ALL" >> $sysroot/etc/sudoers + t_yesno "Allow this user to use doas?" && { + mkdir -p $sysroot/etc/doas.d/ + echo "permit persist david" >> $sysroot/etc/doas.d/doas.conf } t_yesno "Set a password for the root user?" && { @@ -244,7 +347,7 @@ select_timezone () { install_additional () { t_check "Install and configure additional services: " $additional_services - local services=$T_RESULT + local services="$T_RESULT" for service in $services; do service_$service @@ -254,7 +357,7 @@ install_additional () { service_networkmanager () { t_msg "Installing NetworkManager..." { - xi -ly -r $sysroot install networkmanager + xi -qvly -r $sysroot install networkmanager xichroot $sysroot rc-update add networkmanager } >> $logfile } @@ -262,48 +365,83 @@ service_networkmanager () { service_iwd () { t_msg "Installing iwd..." { - xi -ly -r $sysroot install iwd + xi -qvly -r $sysroot install iwd xichroot $sysroot rc-update add iwd } >> $logfile } service_xorg () { t_msg "Installing xorg..." - xi -r $sysroot install base-xorg base-fonts >> $logfile - t_check "Select video drivers:" $(xi search xd86-video- | cut -f2 -d/) - [ "${#T_RESULT}" != "0" ] && xi -r $sysroot install $T_RESULT + xi -qvly -r $sysroot install base-xorg base-fonts >> $logfile + t_check "Select video drivers:" $(xi search xf86-video- | cut -f2 -d/) + [ "${#T_RESULT}" != "0" ] && xi -r $sysroot install $T_RESULT >> $logfile t_prompt "Installed basic xorg functionality TODO: preconfigured window managers, for now you need to configure them yourself" } +prompt_shell () { + t_yesno "Would you like to drop into the shell of your new system before rebooting?" && { + t_clean + xichroot $sysroot /bin/mksh -l + t_init + t_no_cur + t_cls_ptrn + } + return 0 +} umount_disks () { + t_msg "Unmounting disks..." umount -R $sysroot [ -b "$SWAP_PART" ] && swapoff $SWAP_PART + [ "$OPT_ENCRYPTION" = "lvm-luks"] && cryptsetup close cryptlvm return 0 } +prompt_reboot () { + t_yesno "Install complete, reboot?" && { + t_clean + reboot & exit 0 + } +} + t_init t_no_cur checkroot steps="welcome_splash +detect_efi partition_disks format_disks mount_disks +prompt_kernel bootstrap_system install_base copy_resolvconf +configure_hostname +select_timezone sync_system generate_fstab build_initramfs +install_grub configure_users fix_permissions -select_timezone install_additional +prompt_shell umount_disks +prompt_reboot " +$DEBUG_MODE && { + echo > $logfile + + { + tail -f $logfile | while read -r line; do + t_tail $logfile + done + } & +} + for step in $steps; do t_cls_ptrn $step 2>> $logfile || { @@ -313,5 +451,4 @@ for step in $steps; do } done t_prompt "Completed install!" - t_clean -- cgit v1.2.1