152 lines
3.5 KiB
Bash
152 lines
3.5 KiB
Bash
#!/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
|
|
libisoburn
|
|
syslinux
|
|
)
|
|
|
|
pre_install+=(20:bootstrap:pre_install)
|
|
bootstrap:pre_install() {
|
|
local arg_mountpoint=$1
|
|
|
|
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
|
|
|
|
# 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_runscript
|
|
|
|
add_binary umorpha-install
|
|
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 pvcreate
|
|
add_binary vgchange
|
|
add_binary vgcreate
|
|
add_binary vgremove
|
|
add_binary lvcreate
|
|
|
|
add_binary lsblk
|
|
add_binary wipefs
|
|
}
|
|
|
|
help() {
|
|
cat <<HELPEOF
|
|
This hook mounts the CD and runs 'umorpha-install' on the rootfs.img
|
|
found there.
|
|
|
|
Boot parameters:
|
|
- iso: the ISO disk device
|
|
HELPEOF
|
|
}
|
|
EOF
|
|
|
|
install -Dm644 /dev/stdin "$arg_mountpoint/usr/lib/initcpio/hooks/umorpha-bootstrap" <<'EOF'
|
|
#!/hint/ash
|
|
# Copyright (C) 2023 Umorpha Systems
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# args: errmsg
|
|
umorpha_emergency_shell() {
|
|
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
|
|
err "$*"
|
|
echo "You are now being dropped into an emergency shell."
|
|
launch_interactive_shell
|
|
msg "Trying to continue (this will most likely fail) ..."
|
|
}
|
|
|
|
# args: /path/to/newroot
|
|
bootstrap_mount_handler() {
|
|
local newroot="${1}"
|
|
|
|
local isodev
|
|
if ! isodev=$(resolve_device "$iso"); then
|
|
umorpha_emergency_shell "Failed to resolve device '$iso'"
|
|
fi
|
|
case "$iso" in
|
|
'UUID='* | 'LABEL='* | 'PARTUUID='* | 'PARTLABEL='*) : ;;
|
|
*) iso="$isodev" ;;
|
|
esac
|
|
|
|
if ! mount --mkdir -o ro "$iso" /mnt/iso; then
|
|
umorpha_emergency_shell "Failed to mount iso '$iso'"
|
|
fi
|
|
|
|
ln -s /tmp /var/tmp
|
|
mkdir /dev/pts /dev/shm
|
|
msg "----------------------------------------------------------------------"
|
|
if ! umorpha-install /mnt/iso/rootfs.img /dev/vda; then
|
|
umorpha_emergency_shell "Failed to install rootfs to /dev/vda"
|
|
fi
|
|
eject /mnt/iso
|
|
reboot -f
|
|
}
|
|
|
|
run_hook() {
|
|
export mount_handler='bootstrap_mount_handler'
|
|
}
|
|
EOF
|
|
|
|
install -Dm755 /dev/stdin "$arg_mountpoint/usr/bin/umorpha-install" <<'INSTALLEOF'
|
|
@UMORPHA_INSTALL_CONTENT@
|
|
INSTALLEOF
|
|
}
|
|
|
|
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
|
|
}
|