#!/hint/bash -euE # Copyright (C) 2023 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later load_module "$(dirname -- "${BASH_SOURCE[0]}")/base-net.sh" packages+=( # Things to put in the initramfs: #bash # base #coreutils # base #grep # base #systemd # base #util-linux # base arch-install-scripts dosfstools e2fsprogs lvm2 pv # Other jq libisoburn mkinitcpio-netconf syslinux ) pre_install+=(20:bootstrap:pre_install) bootstrap:pre_install() { local arg_mountpoint=$1 # The `keymap` mkinitcpio hook looks at locale.conf to # determine whether to enable Unicode. This is important so # that the output of `systemd-repart` is readable. cat >"${arg_mountpoint}/etc/locale.conf" <<-EOF LANG=en_US.UTF-8 EOF install -Dm644 /dev/stdin "$arg_mountpoint/etc/mkinitcpio.conf.d/umorpha-bootstrap.conf" <<'EOF' #!/hint/bash # Copyright (C) 2023 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later # Remove 'kms' from HOOKS. for ((i=0; i<${#HOOKS[@]}; i++)); do if [[ ${HOOKS[i]} == kms ]]; then HOOKS=("${HOOKS[@]:0:i}" "${HOOKS[@]:i+1}") fi done # Insert 'umorpha-bootstrap' and 'lvm2' into HOOKS. for ((i=0; i<${#HOOKS[@]}; i++)); do if [[ ${HOOKS[i]} == filesystems ]]; then HOOKS=("${HOOKS[@]:0:i}" umorpha-bootstrap lvm2 "${HOOKS[@]:i}" ) break fi done EOF install -Dm644 /dev/stdin "$arg_mountpoint/usr/lib/initcpio/install/umorpha-bootstrap" <<'EOF' #!/hint/bash # Copyright (C) 2023 Umorpha Systems # SPDX-License-Identifier: AGPL-3.0-or-later build() { add_module cdrom add_binary eject add_checked_modules /drivers/net/ add_binary ip add_binary /usr/lib/initcpio/ipconfig /sbin/ipconfig add_binary curl add_file /etc/ssl/certs/ca-certificates.crt add_binary jq add_runscript add_binary umorpha-install add_binary umorpha-mount add_binary arch-chroot add_binary bash add_binary chroot add_binary readlink add_binary pv add_binary systemd-repart add_binary mkfs.ext4 add_binary mkfs.vfat add_binary lvcreate add_binary pvcreate add_binary pvs add_binary vgchange add_binary vgcreate add_binary vgremove add_binary vgs } help() { cat <&1) echo "$out" echo "$out" | grep -o 'dns[0-9]*\s*:\s*\S*' | sed 's/.*:/nameserver /' >/etc/resolv.conf msg "- [cloud-init] -----------------------------------------------------------------" if ! curl --fail-with-body -H 'Metadata-Token: cloudinit' http://169.254.169.254/v1.json >/vultr-v1.json; then umorpha_emergency_shell "Failed to download '/vultr-v1.json'" fi if ! jq -r '.["user-data"]' /cloud-init-user-data; then umorpha_emergency_shell "Failed to parse '/vultr-v1.json'" fi if [ "$(head -c2 /cloud-init-user-data)" != '#!' ]; then echo ":: /cloud-init-user-data does not look like a script, skipping" else chmod 755 /cloud-init-user-data if ! /cloud-init-user-data; then umorpha_emergency_shell "Failed to run '/cloud-inituser-data'" fi fi msg "- [dbg] ------------------------------------------------------------------------" echo "Last chance to poke around." launch_interactive_shell msg "- [reboot] ---------------------------------------------------------------------" reboot -f } run_hook() { export mount_handler='bootstrap_mount_handler' } EOF install -Dm755 "$(dirname -- "${BASH_SOURCE[0]}")/../bin/umorpha-install" "$arg_mountpoint/usr/bin/umorpha-install" install -Dm755 "$(dirname -- "${BASH_SOURCE[0]}")/../bin/umorpha-mount" "$arg_mountpoint/usr/bin/umorpha-mount" } post_install+=(20:bootstrap:post_install) bootstrap:post_install() { local arg_mountpoint=$1 chmod 644 -- "$arg_mountpoint"/boot/initramfs*.img rm -rf "$arg_mountpoint"/boot/syslinux mkdir -p -- "$arg_mountpoint/boot/isolinux" ln -sr -t "$arg_mountpoint/boot/isolinux" -- \ "$arg_mountpoint/usr/lib/syslinux/bios/isolinux.bin" \ "$arg_mountpoint/usr/lib/syslinux/bios/ldlinux.c32" install -Dm644 /dev/stdin "$arg_mountpoint/boot/isolinux/syslinux.cfg" <<-EOF DEFAULT boot LABEL boot LINUX /vmlinuz-linux-libre-vanilla INITRD /initramfs-linux-libre-vanilla.img EOF }