refactor(meta): Add function numbering (#3)

This commit is contained in:
hygienic-books 2023-10-20 15:24:39 +02:00
parent 29a5ede899
commit 2876f55e82

View File

@ -22,10 +22,12 @@ function we_are_changerooted () {
} }
function set_ntp () { function set_ntp () {
#1.1
timedatectl set-ntp true timedatectl set-ntp true
} }
function update_pacman_db () { function update_pacman_db () {
#1.2
printf -- '%s\n' 'Refreshing mirror list ...' printf -- '%s\n' 'Refreshing mirror list ...'
systemctl start reflector systemctl start reflector
# In an ISO and for the minimal number of packages we need we do not # In an ISO and for the minimal number of packages we need we do not
@ -34,11 +36,13 @@ function update_pacman_db () {
} }
function install_pkgs () { function install_pkgs () {
#1.3
printf -- '%s\n' 'Installing packages ...' printf -- '%s\n' 'Installing packages ...'
pacman -S --needed --noconfirm "${@}" pacman -S --needed --noconfirm "${@}"
} }
function install_zfs () { function install_zfs () {
#1.4
declare reset_colors='\033[0m' declare reset_colors='\033[0m'
curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash
printf -- "${reset_colors}" printf -- "${reset_colors}"
@ -209,6 +213,7 @@ function export_pool () {
} }
function setup_zpool () { function setup_zpool () {
#1.4
local 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}")"
@ -228,6 +233,7 @@ function setup_zpool () {
} }
function mount_system () { function mount_system () {
#1.5
zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}"
zfs mount -a zfs mount -a
@ -240,6 +246,7 @@ function mount_system () {
} }
function copy_zpool_cache () { function copy_zpool_cache () {
#1.6
mkdir -p '/mnt/etc/zfs' mkdir -p '/mnt/etc/zfs'
zpool set 'cachefile=/etc/zfs/'"${zpool_name}"'.cache' "${zpool_name}" zpool set 'cachefile=/etc/zfs/'"${zpool_name}"'.cache' "${zpool_name}"
} }
@ -260,6 +267,7 @@ function pacman_dont_check_space () {
} }
function install_archlinux () { function install_archlinux () {
#1.7
pacman_dl_parallel pacman_dl_parallel
pacman_dont_check_space pacman_dont_check_space
pacstrap /mnt \ pacstrap /mnt \
@ -286,6 +294,7 @@ function install_archlinux () {
} }
function gen_fstab () { function gen_fstab () {
#1.8
genfstab -U /mnt | grep -v "${zpool_name}" | tr -s '\n' | sed -r -e 's/\/mnt//' -e '/./,$!d' > '/mnt/etc/fstab' genfstab -U /mnt | grep -v "${zpool_name}" | tr -s '\n' | sed -r -e 's/\/mnt//' -e '/./,$!d' > '/mnt/etc/fstab'
} }
@ -298,6 +307,7 @@ EOF
} }
function set_hostname () { function set_hostname () {
#1.9
declare new_hostname declare new_hostname
install_pkgs 'pwgen' install_pkgs 'pwgen'
new_hostname="$(pwgen --no-numerals --no-capitalize --ambiguous 8)" new_hostname="$(pwgen --no-numerals --no-capitalize --ambiguous 8)"
@ -306,6 +316,7 @@ function set_hostname () {
} }
function set_locale () { function set_locale () {
#1.10
printf -- '%s\n' \ printf -- '%s\n' \
'KEYMAP=de-latin1' \ 'KEYMAP=de-latin1' \
'FONT=Lat2-Terminus16' \ 'FONT=Lat2-Terminus16' \
@ -316,6 +327,7 @@ function set_locale () {
} }
function add_zfs_hook_to_initramfs () { function add_zfs_hook_to_initramfs () {
#1.11
# Add zfs hook, remove fsck hook from initramfs. # Add zfs hook, remove fsck hook from initramfs.
sed -ri \ sed -ri \
-e 's'$'\x1''(HOOKS=)(.*?[\(| ])(filesystems)([\)| ][^\r\n\f]*)'$'\x1''\1\2zfs \3\4'$'\x1''g' \ -e 's'$'\x1''(HOOKS=)(.*?[\(| ])(filesystems)([\)| ][^\r\n\f]*)'$'\x1''\1\2zfs \3\4'$'\x1''g' \
@ -330,6 +342,7 @@ function add_zfs_hook_to_initramfs () {
} }
function set_initramfs_build_list () { function set_initramfs_build_list () {
#1.12
# No need to build fallback initramfs, our new fallback is ZFS snapshots # No need to build fallback initramfs, our new fallback is ZFS snapshots
sed -ri \ sed -ri \
-e '/^#/d' \ -e '/^#/d' \
@ -343,12 +356,14 @@ function set_initramfs_build_list () {
} }
function add_zfs_files_to_new_os () { function add_zfs_files_to_new_os () {
#1.13
for zfs_file in '/etc/hostid' '/etc/zfs/zpool.cache' $([[ ! "${ARCHZBM_ZFSPROPS_NO_ENCRYPTION}" ]] && printf -- '%s' '/etc/zfs/'"${zpool_name}"'.key'); do for zfs_file in '/etc/hostid' '/etc/zfs/zpool.cache' $([[ ! "${ARCHZBM_ZFSPROPS_NO_ENCRYPTION}" ]] && printf -- '%s' '/etc/zfs/'"${zpool_name}"'.key'); do
rsync -av --itemize-changes {'','/mnt'}"${zfs_file}" rsync -av --itemize-changes {'','/mnt'}"${zfs_file}"
done done
} }
function enter_chroot () { function enter_chroot () {
#1.14
arch-chroot /mnt /bin/bash -xe <<EOF arch-chroot /mnt /bin/bash -xe <<EOF
curl --silent '${this_script_url}' | bash curl --silent '${this_script_url}' | bash
EOF EOF
@ -522,10 +537,12 @@ function install_os_in_chroot () {
} }
function set_root_pw () { function set_root_pw () {
#2.1
printf -- '%s\n' 'root:password' | chpasswd --root '/mnt' printf -- '%s\n' 'root:password' | chpasswd --root '/mnt'
} }
function configure_networking () { function configure_networking () {
#2.2
cat > '/mnt/etc/systemd/network/50-wired.network' <<"EOF" cat > '/mnt/etc/systemd/network/50-wired.network' <<"EOF"
[Match] [Match]
Name=en* Name=en*
@ -543,6 +560,7 @@ EOF
} }
function configure_dns () { function configure_dns () {
#2.3
rm '/mnt/etc/resolv.conf' rm '/mnt/etc/resolv.conf'
ln -s '/run/systemd/resolve/stub-resolv.conf' '/mnt/etc/resolv.conf' ln -s '/run/systemd/resolve/stub-resolv.conf' '/mnt/etc/resolv.conf'
@ -553,14 +571,17 @@ function configure_dns () {
} }
function configure_reflector () { function configure_reflector () {
#2.4
systemctl enable 'reflector' --root='/mnt' systemctl enable 'reflector' --root='/mnt'
} }
function configure_zfs () { function configure_zfs () {
#2.5
systemctl enable 'zfs-import-cache' 'zfs-mount' 'zfs-import.target' 'zfs.target' --root='/mnt' systemctl enable 'zfs-import-cache' 'zfs-mount' 'zfs-import.target' 'zfs.target' --root='/mnt'
} }
function configure_zfs_mount_gen () { function configure_zfs_mount_gen () {
#2.6
mkdir -p '/mnt/etc/zfs/zfs-list.cache' mkdir -p '/mnt/etc/zfs/zfs-list.cache'
touch '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}" touch '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}"
zfs list -H -o name,mountpoint,canmount,atime,relatime,devices,exec,readonly,setuid,nbmand | sed 's/\/mnt//' > '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}" zfs list -H -o name,mountpoint,canmount,atime,relatime,devices,exec,readonly,setuid,nbmand | sed 's/\/mnt//' > '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}"
@ -568,6 +589,7 @@ function configure_zfs_mount_gen () {
} }
function configure_zfsbootmenu () { function configure_zfsbootmenu () {
#2.7
curl -s 'https://raw.githubusercontent.com/zbm-dev/zfsbootmenu/master/etc/zfsbootmenu/mkinitcpio.conf' | sed -r -e '/^#/d' -e '/^$/d' > '/mnt/etc/zfsbootmenu/mkinitcpio.conf' curl -s 'https://raw.githubusercontent.com/zbm-dev/zfsbootmenu/master/etc/zfsbootmenu/mkinitcpio.conf' | sed -r -e '/^#/d' -e '/^$/d' > '/mnt/etc/zfsbootmenu/mkinitcpio.conf'
cat > '/mnt/etc/zfsbootmenu/config.yaml' <<EOF cat > '/mnt/etc/zfsbootmenu/config.yaml' <<EOF
Global: Global:
@ -590,6 +612,7 @@ EOF
} }
function gen_zfsbootmenu () { function gen_zfsbootmenu () {
#2.8
arch-chroot /mnt /bin/bash -xe <<"EOF" arch-chroot /mnt /bin/bash -xe <<"EOF"
source /etc/locale.conf source /etc/locale.conf
mkdir -p '/efi/EFI/ZBM' mkdir -p '/efi/EFI/ZBM'
@ -612,6 +635,7 @@ function get_disks_with_one_efipart () {
} }
function add_zbm_to_efi () { function add_zbm_to_efi () {
#2.9
if ! efibootmgr | grep -Piq -- 'ZFSBootMenu'; then if ! efibootmgr | grep -Piq -- 'ZFSBootMenu'; then
local efi_disks_list local efi_disks_list
efi_disks_list="$(get_disks_with_one_efipart)" efi_disks_list="$(get_disks_with_one_efipart)"
@ -627,45 +651,47 @@ function add_zbm_to_efi () {
} }
function umount_all () { function umount_all () {
#2.10
umount '/mnt/efi' umount '/mnt/efi'
zfs umount -a zfs umount -a
zpool export "${zpool_name}" zpool export "${zpool_name}"
} }
function finalize_os_setup () { function finalize_os_setup () {
set_root_pw #1.15
configure_networking set_root_pw #2.1
configure_dns configure_networking #2.2
configure_reflector configure_dns #2.3
configure_zfs configure_reflector #2.4
configure_zfs_mount_gen configure_zfs #2.5
configure_zfsbootmenu configure_zfs_mount_gen #2.6
gen_zfsbootmenu configure_zfsbootmenu #2.7
add_zbm_to_efi gen_zfsbootmenu #2.8
umount_all add_zbm_to_efi #2.9
umount_all #2.10
} }
function main () { function main () {
if we_are_changerooted; then if we_are_changerooted; then
install_os_in_chroot install_os_in_chroot
else else
set_ntp set_ntp #1.1
update_pacman_db update_pacman_db #1.2
install_pkgs 'jq' install_pkgs 'jq' #1.3
install_zfs install_zfs #1.4
setup_zpool setup_zpool #1.4
mount_system mount_system #1.5
copy_zpool_cache copy_zpool_cache #1.6
install_archlinux install_archlinux #1.7
gen_fstab gen_fstab #1.8
set_hostname set_hostname #1.9
set_locale set_locale #1.10
add_zfs_hook_to_initramfs add_zfs_hook_to_initramfs #1.11
set_initramfs_build_list set_initramfs_build_list #1.12
add_zfs_files_to_new_os add_zfs_files_to_new_os #1.13
enter_chroot enter_chroot #1.14
# We're done in chroot # We're done in chroot
finalize_os_setup finalize_os_setup #1.15
fi fi
} }