From ef9edc0d62c3f2006e054eb6a31d3d0fbfd1ac36 Mon Sep 17 00:00:00 2001 From: natemaia Date: Tue, 12 May 2020 19:50:35 -0700 Subject: [PATCH] Initial work on mountless install --- archlabs-installer | 191 +++++++++++++++++++++++++++++++-------------- 1 file changed, 132 insertions(+), 59 deletions(-) diff --git a/archlabs-installer b/archlabs-installer index 0f89e37..4156874 100755 --- a/archlabs-installer +++ b/archlabs-installer @@ -7,7 +7,7 @@ # shellcheck disable=SC2086,SC2046,SC2254 -VER=2.1.47 +VER=2.1.48 # default values { @@ -370,47 +370,70 @@ _lvmerrlvsize="\nInvalid value Entered.\n\nMust be a numeric value with 'M' (meg main() { - # increment SEL every time we enter main() if we're not at the end of the menu - (( SEL < 13 )) && (( SEL++ )) + if [[ $NOMOUNT ]]; then + (( SEL < 8 )) && (( SEL++ )) + tput civis + dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Prepare " \ + --default-item $SEL --cancel-label 'Exit' --menu "$_prep" 0 0 0 \ + 1 "* Select bootloader" \ + 2 "* Username and password" \ + 3 "* System configuration" \ + 4 "Select window manager or desktop" \ + 5 "Select additional packages" \ + 6 "Run a command on the installed system" \ + 7 "View configuration and command selections" \ + 8 "* Confirm choices and finish installation" 2> "$ANS" - tput civis - dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Prepare " \ - --default-item $SEL --cancel-label 'Exit' --menu "$_prep" 0 0 0 \ - 1 "Show device tree" \ - 2 "Partitioning" \ - 3 "LUKS encryption" \ - 4 "Logical volume management" \ - 5 "* Mount partitions" \ - 6 "* Select bootloader" \ - 7 "* Username and password" \ - 8 "* System configuration" \ - 9 "Select window manager or desktop" \ - 10 "Select additional packages" \ - 11 "Run a command on the installed system" \ - 12 "View configuration and command selections" \ - 13 "* Confirm choices and start the installation" 2> "$ANS" + read -r SEL < "$ANS" + case $SEL in + 1) prechecks 0 && { select_bootldr || (( SEL-- )); } ;; + 2) prechecks 1 && { select_mkuser || (( SEL-- )); } ;; + 3) prechecks 2 && { select_config || (( SEL-- )); } ;; + 4) prechecks 3 && { select_sessions || (( SEL-- )); } ;; + 5) prechecks 3 && { select_packages || (( SEL-- )); } ;; + 6) prechecks 3 && select_usercmd ;; + 7) prechecks 3 && select_show ;; + 8) prechecks 3 && install_main ;; + *) yesno "Exit" "\nUnmount partitions (if any) and exit the installer?\n" && die 0 + esac + else + (( SEL < 13 )) && (( SEL++ )) + tput civis + dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Prepare " \ + --default-item $SEL --cancel-label 'Exit' --menu "$_prep" 0 0 0 \ + 1 "Device tree" \ + 2 "Partitioning" \ + 3 "LUKS encryption" \ + 4 "Logical volume management" \ + 5 "* Mount partitions" \ + 6 "* Select bootloader" \ + 7 "* Username and password" \ + 8 "* System configuration" \ + 9 "Select window manager or desktop" \ + 10 "Select additional packages" \ + 11 "Run a command on the installed system" \ + 12 "View configuration and command selections" \ + 13 "* Confirm choices and finish installation" 2> "$ANS" - read -r SEL < "$ANS" - [[ -z $WARN && $SEL =~ (2|5) ]] && { msg "Data Warning" "$_warn"; WARN=true; } - - # if the operation returns an error we decrement SEL, prechecks() will - # also set SEL to even further back based on what is needed to continue - case $SEL in - 1) part_show ;; - 2) part_menu || (( SEL-- )) ;; - 3) luks_menu || (( SEL-- )) ;; - 4) lvm_menu || (( SEL-- )) ;; - 5) mount_menu || (( SEL-- )) ;; - 6) prechecks 0 && { select_bootldr || (( SEL-- )); } ;; - 7) prechecks 1 && { select_mkuser || (( SEL-- )); } ;; - 8) prechecks 2 && { select_config || (( SEL-- )); } ;; - 9) prechecks 3 && { select_sessions || (( SEL-- )); } ;; - 10) prechecks 3 && { select_packages || (( SEL-- )); } ;; - 11) prechecks 3 && select_usercmd ;; - 12) prechecks 3 && select_show ;; - 13) prechecks 3 && install_main ;; - *) yesno "Exit" "\nUnmount partitions (if any) and exit the installer?\n" && die 0 - esac + read -r SEL < "$ANS" + [[ -z $WARN && $SEL =~ (2|5) ]] && { msg "Data Warning" "$_warn"; WARN=true; } + case $SEL in + 1) part_show ;; + 2) part_menu || (( SEL-- )) ;; + 3) luks_menu || (( SEL-- )) ;; + 4) lvm_menu || (( SEL-- )) ;; + 5) mount_menu || (( SEL-- )) ;; + 6) prechecks 0 && { select_bootldr || (( SEL-- )); } ;; + 7) prechecks 1 && { select_mkuser || (( SEL-- )); } ;; + 8) prechecks 2 && { select_config || (( SEL-- )); } ;; + 9) prechecks 3 && { select_sessions || (( SEL-- )); } ;; + 10) prechecks 3 && { select_packages || (( SEL-- )); } ;; + 11) prechecks 3 && select_usercmd ;; + 12) prechecks 3 && select_show ;; + 13) prechecks 3 && install_main ;; + *) yesno "Exit" "\nUnmount partitions (if any) and exit the installer?\n" && die 0 + esac + fi } select_show() @@ -1037,7 +1060,7 @@ part_pretty() [[ $dev && $size ]] || continue s=${size%%__*} size_t="${s: -1:1}" - isize=${s:0:-1} + isize=${s:0: -1} isize=${isize%.*} if [[ $dev = /dev/nvme* ]]; then model=$(lsblk -lno MODEL "${dev%p[1-9]}" | awk '{gsub(/ |\t/, "_"); print}') @@ -1160,8 +1183,8 @@ part_countdec() mount_menu() { - msg "Mount Menu" "\nGathering device and partition information.\n" 1 is_bg_install || return 0 + msg "Mount Menu" "\nGathering device and partition information.\n" 1 lvm_detect umount_dir "$MNT" part_find 'part|lvm|crypt' || { SEL=2; return 1; } @@ -1279,7 +1302,7 @@ select_root() while read -r dev size; do s=${size%%__*} size_t="${s: -1:1}" - isize=${s:0:-1} + isize=${s:0: -1} isize=${isize%.*} if ! [[ $size_t == 'M' || ($size_t == 'G' && $isize -lt 8) ]]; then pts+="$dev $size " @@ -1313,7 +1336,7 @@ select_swap() while read -r dev size; do # walk partition list and skip ones that are > 64G s=${size%%__*} size_t="${s: -1:1}" - isize=${s:0:-1} + isize=${s:0: -1} isize=${isize%.*} if ! [[ $size_t == 'T' || ($size_t == 'G' && $isize -gt 64) ]]; then pts+="$dev $size " @@ -2415,7 +2438,7 @@ lvm_mkgroup() VGROUP_MB=$SIZE fi - msg "$_lvmnew" "\nVolume group $VGROUP (${SIZE}$SIZE_UNIT) successfully created\n" + msg "$_lvmnew" "\nVolume group $VGROUP (${SIZE}$SIZE_UNIT) successfully created\n" 2 } lvm_del_all() @@ -2471,6 +2494,7 @@ lvm_partitions() { part_find 'part|crypt' || return 1 PARTS="$(awk 'NF > 0 {print $0 " off"}' <<< "$PARTS")" + [[ $LUKS && $LUKS_PART ]] && part_countdec $LUKS_PART dlg LVM_PARTS check "$_lvmnew" "\nSelect the partition(s) to use for the physical volume (PV)." $PARTS } @@ -2537,6 +2561,7 @@ luks_open() if (( PART_COUNT == 1 )); then LUKS_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")" else + [[ $LVM && $LVM_PARTS ]] && part_countdec $LVM_PARTS dlg LUKS_PART menu "$_luksopen" "\nSelect which partition to open." $PARTS fi @@ -2598,6 +2623,7 @@ luks_setup() elif (( PART_COUNT == 1 )); then LUKS_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")" else + [[ $LVM && $LVM_PARTS ]] && part_countdec $LVM_PARTS dlg LUKS_PART menu "$_luksnew" "\nSelect the partition you want to encrypt." $PARTS fi @@ -3069,11 +3095,34 @@ fi # trap ^C to perform cleanup trap 'printf "\n^C\n" && die 1' INT -while getopts ":htl:d" OPT; do +while getopts ":htl:dnr:b:" OPT; do case "$OPT" in - d) debug ;; - h) usage "$0" ;; - t) TEARFREE=true ;; + n) + NOMOUNT=true + ;; + r) + if [[ ! -b $OPTARG ]]; then + echo "invalid root: $OPTARG" + die 1 + fi + ROOT=$OPTARG + ;; + b) + if [[ ! -b $OPTARG ]]; then + echo "invalid boot: $OPTARG" + die 1 + fi + BOOT=$OPTARG + ;; + d) + debug + ;; + h) + usage "$0" + ;; + t) + TEARFREE=true + ;; l) if [[ "${!WM_SESSIONS[*]}" =~ $OPTARG ]]; then live "$OPTARG" @@ -3081,24 +3130,42 @@ while getopts ":htl:d" OPT; do echo "error: invalid session for -l, see -h for help"; die 1 fi ;; - \?) echo "error: invalid option: -$OPTARG"; die 1 ;; + \?) + echo "invalid option: $OPTARG" + die 1 + ;; esac done system_identify system_devices -fontsize=16 -while :; do - dlg fontsize menu "Font Size" "\nSelect a font size from the list below.\n\nDefault: 16" \ - 12 "setfont ter-i12n" 14 "setfont ter-i14n" 16 "setfont ter-i16n" 18 "setfont ter-i18n" \ - 20 "setfont ter-i20n" 22 "setfont ter-i22n" 24 "setfont ter-i24n" 28 "setfont ter-i28n" \ - 32 "setfont ter-i32n" || break +if [[ $NOMOUNT ]]; then + if [[ (-z $ROOT || ($SYS == 'UEFI' && -z $BOOT)) ]]; then + msg "Not Enough Partitions" "$_errpart" 0 + die 1 + fi + if [[ $BOOT ]]; then + part_bootdev + SEP_BOOT=true + fi +fi - FONT="ter-i${fontsize}n" +if [[ -f /tmp/hassetfont ]]; then + FONT="$(< /tmp/hassetfont)" setfont "$FONT" - yesno "Font Size" "\nKeep the currently set font size?\n" && break -done +else + fontsize=16 + while [[ ! -f /tmp/hassetfont ]]; do + dlg fontsize menu "Font Size" "\nSelect a font size from the list below.\n\nDefault: 16" \ + 12 "setfont ter-i12n" 14 "setfont ter-i14n" 16 "setfont ter-i16n" 18 "setfont ter-i18n" \ + 20 "setfont ter-i20n" 22 "setfont ter-i22n" 24 "setfont ter-i24n" 28 "setfont ter-i28n" \ + 32 "setfont ter-i32n" || break + FONT="ter-i${fontsize}n" + setfont "$FONT" + yesno "Font Size" "\nKeep the currently set font size?\n" && echo "ter-i${fontsize}n" > /tmp/hassetfont + done +fi msg "Welcome to the $DIST Installer" "$_welcome" @@ -3110,6 +3177,12 @@ elif ! net_connect; then die 1 fi +if [[ $NOMOUNT ]]; then + wrn="\nA background install process will begin early when using -n flag\n\nSome files may be overwritten during the process\n" + yesno "Data Warning" "$wrn\nProceed?\n" || die 0 + install_background +fi + while :; do main done