53 lines
2 KiB
Shell
Executable file
53 lines
2 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
[[ $# -ge 3 && $# -le 4 ]] || {
|
|
echo "usage: build-guanghu-first-boot-initramfs.sh <output> <config> <grub-snapshot> [kernel-version]" >&2
|
|
exit 64
|
|
}
|
|
|
|
output=$(readlink -m "$1")
|
|
config=$(readlink -f "$2")
|
|
grub_snapshot=$(readlink -f "$3")
|
|
kernel_version=${4:-$(uname -r)}
|
|
source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
supervisor=${source_root}/scripts/guanghu-first-boot-supervisor.sh
|
|
packaging=${source_root}/packaging/initramfs-tools
|
|
|
|
command -v mkinitramfs >/dev/null
|
|
[[ -r /etc/initramfs-tools/initramfs.conf ]] || {
|
|
echo "host initramfs configuration is unavailable" >&2
|
|
exit 1
|
|
}
|
|
[[ -f ${config} && ! -L ${config} ]] || {
|
|
echo "first-boot configuration is missing or unsafe" >&2
|
|
exit 1
|
|
}
|
|
[[ -f ${grub_snapshot} && ! -L ${grub_snapshot} ]] || {
|
|
echo "GRUB snapshot is missing or unsafe" >&2
|
|
exit 1
|
|
}
|
|
grep -Fqx 'schema=guanghu.first-boot-supervisor/v1' "${config}"
|
|
grep -Fq 'gnulinux-simple-' "${grub_snapshot}"
|
|
|
|
build_root=$(mktemp -d)
|
|
trap 'rm -rf "${build_root}"' EXIT
|
|
mkdir -p "${build_root}/conf.d" "${build_root}/hooks" \
|
|
"${build_root}/scripts/local-premount" \
|
|
"$(dirname "${output}")"
|
|
install -m 0644 /etc/initramfs-tools/initramfs.conf "${build_root}/initramfs.conf"
|
|
install -m 0644 /dev/null "${build_root}/modules"
|
|
cp "${packaging}/hooks/guanghu-first-boot-supervisor" "${build_root}/hooks/"
|
|
cp "${packaging}/scripts/local-premount/guanghu-first-boot-supervisor" \
|
|
"${build_root}/scripts/local-premount/"
|
|
chmod 0755 "${build_root}/hooks/guanghu-first-boot-supervisor" \
|
|
"${build_root}/scripts/local-premount/guanghu-first-boot-supervisor"
|
|
|
|
export GUANGHU_FIRST_BOOT_SUPERVISOR_SOURCE=${supervisor}
|
|
export GUANGHU_FIRST_BOOT_CONFIG_SOURCE=${config}
|
|
export GUANGHU_FIRST_BOOT_GRUB_SOURCE=${grub_snapshot}
|
|
mkinitramfs -d "${build_root}" -o "${output}" "${kernel_version}"
|
|
chmod 0600 "${output}"
|
|
sha256sum "${output}" >"${output}.sha256"
|
|
printf 'GUANGHU_FIRST_BOOT_INITRAMFS_BUILT kernel=%s output=%s\n' \
|
|
"${kernel_version}" "${output}"
|