Compare commits
10 Commits
c367be8845
...
1fb3cc37eb
Author | SHA1 | Date | |
---|---|---|---|
1fb3cc37eb | |||
a970a3d179 | |||
c27f0e9c7c | |||
10440fc6d7 | |||
ed737409e6 | |||
ef03281a63 | |||
8d38827cd1 | |||
49fe3deced | |||
b12c35ed07 | |||
c3708a098e |
108
setup.sh
108
setup.sh
@@ -65,22 +65,21 @@ function get_parts () {
|
||||
}
|
||||
|
||||
function we_have_exactly_one_part () {
|
||||
declare parttype parts_list parts_count
|
||||
local parttype parts_list parts_count
|
||||
parttype="${1:?}"
|
||||
parts_list="${2:?}"
|
||||
parts_count="$(wc -l <<<"${parts_list}")"
|
||||
if [[ "$(wc -c <<<"${parts_list}")" -gt '1' ]]; then
|
||||
case "${parts_count}" in
|
||||
0)
|
||||
printf -- '%s\n' 'No '"${parttype}"' partition found. Exiting 1 ...'
|
||||
printf -- '%s\n' 'No '"${parttype^^}"' partition found. Exiting 1 ...'
|
||||
exit 1
|
||||
;;
|
||||
1)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
printf -- '%s\n' 'Multiple '"${parttype}"' partitions found. We expect exactly one. Cowardly exiting 1 ...'
|
||||
exit 1
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
printf -- '%s\n' 'Partition list does not look valid. Cowardly exiting 1 ...'
|
||||
@@ -88,6 +87,46 @@ function we_have_exactly_one_part () {
|
||||
fi
|
||||
}
|
||||
|
||||
function get_drive_id () {
|
||||
declare drive_id
|
||||
drive_id="$(find -L /dev/disk/by-id -samefile "${1:?}")"
|
||||
if [[ "$(wc -l <<<"${drive_id}")" -eq '1' ]] && [[ "$(wc -c <<<"${drive_id}")" -gt '1' ]]; then
|
||||
printf -- '%s' "${drive_id}"
|
||||
return 0
|
||||
fi
|
||||
printf -- '%s\n' 'Not exactly one '"'${1:?}'"' partition entry in /dev/disk/by-id, exiting 1 ...'
|
||||
exit 1
|
||||
}
|
||||
|
||||
function select_part () {
|
||||
local parts enriched_parts enriched_parts_count part_number part_type
|
||||
declare part
|
||||
part_type="${1:?}" # 'efi' or 'zfs'
|
||||
parts="$(get_parts "${part_type}")"
|
||||
|
||||
if we_have_exactly_one_part "${part_type}" "${parts}"; then
|
||||
part="${parts}"
|
||||
else
|
||||
printf -- '%s\n' 'Which '"${part_type^^}"' partition do you want us to use?'
|
||||
while IFS= read -r found_part; do
|
||||
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
|
||||
printf -- '%s' "${part}"
|
||||
return 0
|
||||
}
|
||||
|
||||
function no_zpool_exists () {
|
||||
declare zpool_list
|
||||
zpool_list="$(zpool list -H)"
|
||||
@@ -95,17 +134,6 @@ function no_zpool_exists () {
|
||||
return 1
|
||||
}
|
||||
|
||||
function zpool_drive_id () {
|
||||
declare drive_id
|
||||
drive_id="$(find -L /dev/disk/by-id -samefile "${1:?}")"
|
||||
if [[ "$(wc -l <<<"${drive_id}")" -eq '1' ]]; then
|
||||
printf -- '%s' "${drive_id}"
|
||||
return 0
|
||||
fi
|
||||
printf -- '%s\n' 'More than zpool partition entry in /dev/disk/by-id, exiting 1 ...'
|
||||
exit 1
|
||||
}
|
||||
|
||||
function set_zpool_password () {
|
||||
# May or may not have a newline at the end, ZFS doesn't care
|
||||
printf -- '%s' 'password' > '/etc/zfs/'"${zpool_name}"'.key'
|
||||
@@ -162,7 +190,7 @@ function export_pool () {
|
||||
function setup_zpool () {
|
||||
declare zpool_drive drive_by_id
|
||||
zpool_drive="${1:?}"
|
||||
drive_by_id="$(zpool_drive_id "${zpool_drive}")"
|
||||
drive_by_id="$(get_drive_id "${zpool_drive}")"
|
||||
|
||||
set_zpool_password
|
||||
if no_zpool_exists; then
|
||||
@@ -181,13 +209,10 @@ function setup_zpool () {
|
||||
function mount_system () {
|
||||
zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}"
|
||||
zfs mount -a
|
||||
|
||||
declare efi_part
|
||||
efi_part="$(get_parts 'efi')"
|
||||
if we_have_exactly_one_part 'efi' "${efi_part}"; then
|
||||
mkdir -p '/mnt/efi'
|
||||
mount "${efi_part}" '/mnt/efi'
|
||||
fi
|
||||
|
||||
local efi_part="$(select_part 'efi')"
|
||||
mkdir -p '/mnt/efi'
|
||||
mount "${efi_part}" '/mnt/efi'
|
||||
}
|
||||
|
||||
function copy_zpool_cache () {
|
||||
@@ -544,26 +569,25 @@ function main () {
|
||||
else
|
||||
set_ntp
|
||||
update_pacman_db
|
||||
|
||||
install_pkgs 'jq'
|
||||
declare zfs_part
|
||||
zfs_part="$(get_parts 'zfs')"
|
||||
if we_have_exactly_one_part 'zfs' "${zfs_part}"; then
|
||||
printf -- 'Creating zpool on partition '"'"'%s'"'"' ...\n' "${zfs_part}"
|
||||
install_zfs
|
||||
setup_zpool "${zfs_part}"
|
||||
mount_system
|
||||
copy_zpool_cache
|
||||
install_archlinux
|
||||
gen_fstab
|
||||
set_hostname
|
||||
set_locale
|
||||
add_zfs_hook_to_initramfs
|
||||
set_initramfs_build_list
|
||||
add_zfs_files_to_new_os
|
||||
enter_chroot
|
||||
# We're done in chroot
|
||||
finalize_os_setup
|
||||
fi
|
||||
local zfs_part
|
||||
zfs_part="$(select_part 'zfs')"
|
||||
|
||||
install_zfs
|
||||
setup_zpool "${zfs_part}"
|
||||
mount_system
|
||||
copy_zpool_cache
|
||||
install_archlinux
|
||||
gen_fstab
|
||||
set_hostname
|
||||
set_locale
|
||||
add_zfs_hook_to_initramfs
|
||||
set_initramfs_build_list
|
||||
add_zfs_files_to_new_os
|
||||
enter_chroot
|
||||
# We're done in chroot
|
||||
finalize_os_setup
|
||||
fi
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user