diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2022-05-14 13:11:19 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-16 08:12:36 -0400 |
commit | 2f18030412ea5a25c0212685a647150772ebb6b7 (patch) | |
tree | 258e2bbb2356180dd4ec8ec24e9128827c80e5fe | |
parent | bcfedecb0caa5ff3a5e47f4a122507c460cf68fe (diff) |
refactor partitioning
-rwxr-xr-x | install.sh | 242 | ||||
-rw-r--r-- | translations.sh.inc | 23 |
2 files changed, 160 insertions, 105 deletions
@@ -361,7 +361,8 @@ SelectPartition() local device_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ --menu "${TR[device-${Lang}]}" 20 70 50 "${DlgParams[@]}" ) local device=$( GetDevice $(( ${device_n} - 1 )) ) - [[ -n "${device_n}" ]] && [[ -n "${device}" ]] && SetStateVar 'DEVICE' ${device} || exit + [[ -n "${device_n}" ]] && SetStateVar 'DEVICE_N' ${device_n} || exit + [[ -n "${device}" ]] && SetStateVar 'DEVICE' ${device} || exit # prompt for partitioner local part_method=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ @@ -369,50 +370,6 @@ SelectPartition() 'auto' "${TR[part_auto-${Lang}]}" \ 'manual' "${TR[part_man-${Lang}]}" ) [[ -n "${part_method}" ]] && SetStateVar 'PART_METHOD' ${part_method} || exit - - if [[ "${part_method}" == 'manual' ]] - then # manual partitioning - if which gparted &> /dev/null ; then gparted ${device} ; - elif which cfdisk &> /dev/null ; then cfdisk ${device} ; fi ; - - # query partition information - PopulatePartOptions ${device_n} # populates DlgParams - (( ${#DlgParams[@]} )) || ExitFail "${TR[part_none-${Lang}]}" - - # prompt for root partition - local part_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ - --menu "${TR[mount_root-${Lang}]}" 20 70 50 \ - "${DlgParams[@]}" ) - if [[ -n "${part_n}" ]] - then SetStateVar 'ROOT_PART' ${device}${part_n} - RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; - else exit - fi - - # prompt to mount additional partitions - if (( ${#DlgParams[@]} )) - then part_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ - --ok-label "Yes" \ - --cancel-label "No" \ - --menu "${TR[mount_boot-${Lang}]}" 20 70 50 \ - "${DlgParams[@]}" ) - if [[ -n "${part_n}" ]] - then SetStateVar 'BOOT_PART' ${device}${part_n} - RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; - fi - fi - if (( ${#DlgParams[@]} )) - then part_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ - --ok-label "Yes" \ - --cancel-label "No" \ - --menu "${TR[mount_home-${Lang}]}" 20 70 50 \ - "${DlgParams[@]}" ) - if [[ -n "${part_n}" ]] - then SetStateVar 'HOME_PART' ${device}${part_n} - RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; - fi - fi - fi } NoticeReady() @@ -425,71 +382,139 @@ NoticeReady() (( $( WizardDlg "${TR[dlg_ready-${Lang}]}" --yesno "${ready_msg}" 0 0 ) )) || exit } +_PartitionAuto() +{ + # sanity checks + [[ -n "$(GetStateVar 'DEVICE')" ]] + + # automatic partitioning + local device=$(GetStateVar 'DEVICE') + local offset_mb=1 + local swap_mb=1000 # NOTE: this is hard-coded into user-facing strings: 'part_auto-*' + local root_part_n=1 + local swap_part_n=2 + local root_type_n=83 + local swap_type_n=82 + SetStateVar 'ROOT_PART' ${device}${root_part_n} + + # create partition table + parted -s ${device} -- mklabel msdos + + # configure partitions + parted -s ${device} -- mkpart primary ${offset_mb}MiB -${swap_mb}MiB # $root_part_n + parted -s ${device} -- mkpart primary -${swap_mb}MiB -1s # $swap_part_n + parted -s ${device} -- set ${root_part_n} boot on + + # format partitions + sleep 0.5 ; partprobe ; + (echo t ; echo ${root_part_n} ; echo ${root_type_n} ; echo w) | \ + fdisk ${device} &> /dev/null + sleep 0.5 ; partprobe ; + (echo t ; echo ${swap_part_n} ; echo ${swap_type_n} ; echo w) | \ + fdisk ${device} &> /dev/null + yes | mkfs.ext4 ${device}${root_part_n} &> /dev/null + mkswap ${device}${swap_part_n} &> /dev/null +} + +_PartitionManual() +{ + # sanity checks + [[ -n "$(GetStateVar 'DEVICE' )" ]] + [[ -n "$(GetStateVar 'DEVICE_N')" ]] + + # manual partitioning + local device=$(GetStateVar 'DEVICE') + if [[ -n "${DISPLAY}" ]] && which gparted &> /dev/null ; then gparted ${device} ; + elif which cfdisk &> /dev/null ; then cfdisk ${device} ; + fi + + # query partition information + local device_n=$(GetStateVar 'DEVICE_N') + PopulatePartOptions ${device_n} # PopulatePartOptions() populates DlgParams + (( ${#DlgParams[@]} )) || ExitFail "${TR[part_none-${Lang}]}" + + # prompt for root partition + local part_n=$( WizardDlg "${TR[dlg_part-${Lang}]}" \ + --menu "${TR[mount_root-${Lang}]}" 20 70 50 \ + "${DlgParams[@]}" ) + if [[ -n "${part_n}" ]] + then SetStateVar 'ROOT_PART' ${device}${part_n} + RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; + else exit + fi + + # prompt to mount additional partitions + local dlg_opts="--ok-label '${TR[yes-${Lang}]}' --cancel-label '${TR[no-${Lang}]}'" + if (( ${#DlgParams[@]} )) + then part_n=$( DIALOGOPTS="${dlg_opts}" \ + WizardDlg "${TR[dlg_part-${Lang}]}" \ + --menu "${TR[mount_boot-${Lang}]}" 20 70 50 \ + "${DlgParams[@]}" ) + if [[ -n "${part_n}" ]] + then SetStateVar 'BOOT_PART' ${device}${part_n} + RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; + fi + fi + if (( ${#DlgParams[@]} )) + then part_n=$( DIALOGOPTS="${dlg_opts}" \ + WizardDlg "${TR[dlg_part-${Lang}]}" \ + --menu "${TR[mount_home-${Lang}]}" 20 70 50 \ + "${DlgParams[@]}" ) + if [[ -n "${part_n}" ]] + then SetStateVar 'HOME_PART' ${device}${part_n} + RemoveOption ${part_n} ; PopulatePartOptions ${device_n} ; + fi + fi +} + Partition() { # sanity checks [[ -n "$(GetStateVar 'DEVICE' )" ]] [[ -n "$(GetStateVar 'PART_METHOD')" ]] - [[ -n "$(GetStateVar 'ROOT_PART' )" ]] - [[ -n "$(GetStateVar 'BOOT_PART' )" ]] - [[ -n "$(GetStateVar 'HOME_PART' )" ]] - - local device=$( GetStateVar 'DEVICE' ) - local part_method=$(GetStateVar 'PART_METHOD') - local root_part=$( GetStateVar 'ROOT_PART' ) - local boot_part=$( GetStateVar 'BOOT_PART' ) - local home_part=$( GetStateVar 'HOME_PART' ) - - if [[ "${part_method}" == 'manual' ]] - then [[ -n "${root_part}" && -n "${boot_part}" && -n "${home_part}" ]] - elif [[ "${part_method}" == 'auto' ]] - then # automatic partitioning - local root_part_n=1 - local swap_part_n=2 - local root_type_n=83 - local swap_type_n=82 - root_part=${device}${root_part_n} - - # create partition table - parted -s ${device} -- mklabel msdos - - # configure partitions - parted -s ${device} -- mkpart primary 1MiB -1000MiB # $root_part_n - parted -s ${device} -- mkpart primary -1000MiB -1s # $swap_part_n - parted -s ${device} -- set ${root_part_n} boot on - - # format partitions - sleep 0.5 ; partprobe ; - (echo t ; echo ${root_part_n} ; echo ${root_type_n} ; echo w) | \ - fdisk ${device} &> /dev/null - sleep 0.5 ; partprobe ; - (echo t ; echo ${swap_part_n} ; echo ${swap_type_n} ; echo w) | \ - fdisk ${device} &> /dev/null - yes | mkfs.ext4 ${device}${root_part_n} &> /dev/null - mkswap ${device}${swap_part_n} &> /dev/null - fi - # format un-formatted partitions and mount partitions + # switch automatic/manual partitioning + [[ "$(GetStateVar 'PART_METHOD')" == 'auto' ]] && _PartitionAuto || _PartitionManual + + # sanity checks + [[ -n "$(GetStateVar 'ROOT_PART')" ]] + + declare -A partitions=( [Root]=$(GetStateVar 'ROOT_PART') \ + [Boot]=$(GetStateVar 'BOOT_PART') \ + [Home]=$(GetStateVar 'HOME_PART') ) local partition - umount /mnt &> /dev/null || true + local dlg_msg + + # format un-formatted partitions and mount partitions umount /mnt/boot &> /dev/null || true umount /mnt/home &> /dev/null || true - for partition in ${root_part} ${boot_part} ${home_part} - do # prompt to format un-formatted partiion - ! blkid ${partition} | grep ' TYPE="' &> /dev/null && \ - (( $( WizardDlg "${TR[dlg_part-${Lang}]}" \ - --yesno "${partition} ${TR[format-${Lang}]}" 20 70 ) )) && \ - mkfs.ext4 ${partition} > /dev/null || true + umount /mnt &> /dev/null || true + for partition in ${!partitions[@]} + do dlg_msg="${partition} partiion: ${partitions[${partition}]} ${TR[format-${Lang}]}" + # prompt to format un-formatted partiion + ! blkid ${partition} | grep ' TYPE="' &> /dev/null && \ + (( $( WizardDlg "${TR[dlg_part-${Lang}]}" --yesno "${dlg_msg}" 20 70 ) )) && \ + mkfs.ext4 ${partition} > /dev/null || true # final validation - blkid ${partition} | grep ' TYPE="' &> /dev/null + if ! blkid ${partition} | grep ' TYPE="' &> /dev/null + then SetStateVar 'DEVICE' ; SetStateVar 'ROOT_PART' ; + SetStateVar 'DEVICE_N' ; SetStateVar 'ROOT_PART' ; + SetStateVar 'PART_METHOD' ; SetStateVar 'HOME_PART' ; + # TODO: allow the installer to check if all prior state-vars + # are present in .session_state; and offer to reset them + # or to resume at SelectPartition() instead. + # change 'abort-' message to indicate that possibility. + ExitFail "${TR[abort-${Lang}]}" + fi done - if [[ -n "${root_part}" ]] ; then mkdir -p /mnt - mount ${root_part} /mnt ; fi ; - if [[ -n "${boot_part}" ]] ; then mkdir -p /mnt/boot - mount ${boot_part} /mnt/boot ; fi ; - if [[ -n "${home_part}" ]] ; then mkdir -p /mnt/home - mount ${home_part} /mnt/home ; fi ; + + if [[ -n "${partitions[Root]}" ]] ; then mkdir -p /mnt ; + mount ${partitions[Root]} /mnt ; fi ; + if [[ -n "${partitions[Boot]}" ]] ; then mkdir -p /mnt/boot ; + mount ${partitions[Boot]} /mnt/boot ; fi ; + if [[ -n "${partitions[Home]}" ]] ; then mkdir -p /mnt/home ; + mount ${partitions[Home]} /mnt/home ; fi ; } InstallPkgs() @@ -576,22 +601,31 @@ trap 'trap - EXIT INT TERM ; LogError "${FUNCNAME[0]}" ${LINENO} ;' ERR ## main entry ## +## essential non-interactive non-destructive steps ## NoticeIntro # Explain that no changes will be made until the final stage Init # Check for isorepo existence and internet connection InitKeyring # Initialize pacman keyring + +## essential interactive non-destructive steps ## NoticeCustomize # Explain that the next decisions are mandatory, but interchangeable SelectDefaults # Choose to install the standard system, or to customize SelectLogins # Set root password and decide to register unprivileged login user SelectBase # Select base package-set (bypassed per SelectDefaults) -NoticeOptional # Explain that the next decisions are optional + +## non-essential interactive non-destructive steps ## +NoticeOptional # Explain that the next decisions are non-essential SelectBoot # Choose to install bootloader SelectWmde # Choose to install graphical environment (bypassed per SelectDefaults) SelectEnv # Set environment parameters for the target system (bypassed per SelectDefaults) -SelectPartition # Partition manually or defer to automatic -NoticeReady # List chosen options and offer last chance to bail -Partition # Automatic partition and mount target disks (non-interactive) -InstallPkgs # Install packages with pacstrap (non-interactive) -ConfigChroot # Generate fstab, register login, configure services (non-interactive) (in-chroot) +SelectPartition # Choose to partition manually or defer to automatic + +## essential interactive destructive steps ## +NoticeReady # Display chosen options and offer last chance to bail +Partition # Partition and mount target disks (may or may not be interactive) + +## essential non-interactive destructive steps ## +InstallPkgs # Install packages with pacstrap +ConfigChroot # Generate fstab, register login, configure services (in-chroot) NoticeDone # Yay!!! Cleanup # Clean-up and un-mount the chroot (non-interactive) diff --git a/translations.sh.inc b/translations.sh.inc index 53dd8f4..98449e8 100644 --- a/translations.sh.inc +++ b/translations.sh.inc @@ -442,6 +442,18 @@ declare -r -A TR=( [mount_root-gl]="Montar particion root /:" [mount_root-pt]="Montar a partição root /:" + [yes-en]="Yes" + [yes-eo]="Jes" + [yes-es]="Sí" + [yes-gl]="Si" + [yes-pt]="Sim" + + [no-en]="No" + [no-eo]="Ne" + [no-es]="No" + [no-gl]="Non" + [no-pt]="Não" + [mount_boot-en]="(Optional) Mount /boot partition?" [mount_boot-eo]="(Laŭvola) Muntu /boot subdiskon?" [mount_boot-es]="(Opcional) Montar particion /boot?" @@ -454,12 +466,21 @@ declare -r -A TR=( [mount_home-gl]="(Opcional) Montar particion /home?" [mount_home-pt]="(Opcional) Montar a partição /home?" + + ## install.sh::Partition() ## + [format-en]="does not appear to be formatted. The installer can not continue unless it is formatted. Do you want to format it with EXT4 now?" - [format-eo]="ne aspektas kiel strukturita. La instalilo ne progresos, krom se ĝin estas strukturita. Ĉu vi volas strukturas ĝin kiel EXT4 nun?" + [format-eo]="ne aspektas kiel strukturita. La instalilo ne povas progresi, krom se ĝin estas strukturita. Ĉu vi volas strukturas ĝin kiel EXT4 nun?" [format-es]="no parece estar formateado. El instalador no puede continuar a menos que esté formateado. ¿Quieres formatearlo con EXT4 ahora?" [format-gl]="non parece ter formato. O instalador non pode continuar a menos que estea formatado. ¿Quere formatalo agora con EXT4?" [format-pt]="não parece estar formatado. O instalador não pode continuar a menos que seja formatado. Quer formatar com EXT4 agora?" + [abort-en]="The installer must abort now." + [abort-eo]="La instalado devas ĉesigi nun." + [abort-es]="La instalación debe abortar ahora." + [abort-gl]="A instalación debe abortar agora." + [abort-pt]="A instalação deve abortar agora." + ## install.sh::NoticeDone() ## |