Compare commits

...

6 Commits

View File

@@ -11,6 +11,8 @@ zfs_arch_dataset_name='archlinux'
set -E set -E
trap '[ "$?" -ne 77 ] || exit 77' ERR trap '[ "$?" -ne 77 ] || exit 77' ERR
declare zpool_drive
function set_ntp () { function set_ntp () {
timedatectl set-ntp true timedatectl set-ntp true
} }
@@ -50,17 +52,23 @@ function get_partitions () {
} }
function get_parts () { function get_parts () {
local zfs_install_drive
declare parttype parts declare parttype parts
parttype="${1:?}" parttype="${1:?}"
zfs_install_drive="${2:-}"
case "${parttype}" in case "${parttype}" in
zfs) zfs)
parts="$(get_partitions | jq --raw-output '.[][] | select(.parttype=="6a85cf4d-1dd2-11b2-99a6-080020736631") | .path')" || exit 1 parts="$(get_partitions | jq --raw-output '.[][] | select(.parttype=="6a85cf4d-1dd2-11b2-99a6-080020736631") | .path')" || exit 1
;; ;;
efi) efi)
if [[ "${zfs_install_drive}" ]]; then
parts="$(get_partitions | jq --raw-output '.[][] | select(.path=="'"${zfs_install_drive}"'") | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1
else
parts="$(get_partitions | jq --raw-output '.[][] | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1 parts="$(get_partitions | jq --raw-output '.[][] | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1
fi
;; ;;
*) *)
>2 printf -- '%s\n' 'Unknown partition type '"'"'"${parttype}"'"'"', exiting 1 ...' >2 printf -- '%s\n' 'Unknown partition type '"'"'"${parttype}"'"'"', exiting ...'
exit 77 exit 77
;; ;;
esac esac
@@ -76,7 +84,7 @@ function we_have_exactly_one_part () {
if [[ "$(wc -c <<<"${parts_list}")" -gt '1' ]]; then if [[ "$(wc -c <<<"${parts_list}")" -gt '1' ]]; then
case "${parts_count}" in case "${parts_count}" in
0) 0)
>2 printf -- '%s\n' 'No '"${parttype^^}"' partition found. Exiting 1 ...' >2 printf -- '%s\n' 'No '"${parttype^^}"' partition found. Exiting ...'
exit 77 exit 77
;; ;;
1) 1)
@@ -86,7 +94,7 @@ function we_have_exactly_one_part () {
return 1 return 1
;; ;;
esac esac
>2 printf -- '%s\n' 'Partition list does not look valid. Cowardly exiting 1 ...' >2 printf -- '%s\n' 'Partition list does not look valid. Cowardly exiting ...'
exit 77 exit 77
fi fi
} }
@@ -99,34 +107,26 @@ function get_drive_id () {
printf -- '%s' "${drive_id_single}" printf -- '%s' "${drive_id_single}"
return 0 return 0
fi fi
>2 printf -- '%s\n' 'Not exactly one '"'${1:?}'"' partition entry in /dev/disk/by-id, exiting 1 ...' >2 printf -- '%s\n' 'Not exactly one '"'${1:?}'"' partition entry in /dev/disk/by-id, exiting ...'
exit 77 exit 77
} }
function select_part () { function select_part () {
local parts enriched_parts enriched_parts_count part_number part_type local parts enriched_parts enriched_parts_count part_number part_type zfs_install_drive zfs_install_parent
declare part declare part
part_type="${1:?}" # 'efi' or 'zfs' part_type="${1:?}" # 'efi' or 'zfs'
zfs_install_drive="${2:-}"
if [[ "${zfs_install_drive}" ]]; then
parts="$(get_parts "${part_type}" "${zfs_install_drive}")"
else
parts="$(get_parts "${part_type}")" parts="$(get_parts "${part_type}")"
fi
if we_have_exactly_one_part "${part_type}" "${parts}"; then if we_have_exactly_one_part "${part_type}" "${parts}"; then
part="${parts}" part="${parts}"
else else
printf -- '%s\n' 'Which '"${part_type^^}"' partition do you want us to use?' 2> printf -- '%s\n' 'More than one '"${part_type^^}"' partition to pick for installation. Cowardly exiting ...'
while IFS= read -r found_part; do exit 77
enriched_parts+=("'${found_part}'"' (aka ID '"'$(get_drive_id "${found_part}")'"')')
done <<<"${parts}"
enriched_parts_count="${#enriched_parts[@]}"
select part in "${enriched_parts[@]}"; do
part_number="${REPLY}"
if [[ "${part_number}" -le "${enriched_parts_count}" ]]; then
part="$(sed "${REPLY}q;d" <<<"${parts}")"
printf -- '%s\n' 'You'"'"'ve selected '"'${part}'"' ...'
break
else
printf -- '%s\n' 'Invalid option, please choose between 1 and '"${enriched_parts_count}"
fi
done
fi fi
printf -- '%s' "${part}" printf -- '%s' "${part}"
return 0 return 0
@@ -193,7 +193,7 @@ function export_pool () {
} }
function setup_zpool () { function setup_zpool () {
local zpool_drive drive_by_id local drive_by_id
zpool_drive="$(select_part 'zfs')" zpool_drive="$(select_part 'zfs')"
drive_by_id="$(get_drive_id "${zpool_drive}")" drive_by_id="$(get_drive_id "${zpool_drive}")"
@@ -215,7 +215,7 @@ function mount_system () {
zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}"
zfs mount -a zfs mount -a
local efi_part="$(select_part 'efi')" local efi_part="$(select_part 'efi' "${zpool_drive:?})"
mkdir -p '/mnt/efi' mkdir -p '/mnt/efi'
mount "${efi_part}" '/mnt/efi' mount "${efi_part}" '/mnt/efi'
} }