Add image dependency installer

This commit is contained in:
joe committed 2026-06-16 15:36:43 -04:00
1 parent 6f03ba8068
commit 398fecb5be
3 files changed
+214 -1

No files matched your search

+5 -1
View File
@@ -19,12 +19,13 @@ export SECURE_BOOT_CERT ?=
export GNOME_SUITE ?= trixie export GNOME_SUITE ?= trixie
export GNOME_MIRROR ?= http://deb.debian.org/debian export GNOME_MIRROR ?= http://deb.debian.org/debian
.PHONY: help deps fetch kernel busybox systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean .PHONY: help deps image-deps fetch kernel busybox systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean
help: help:
@printf '%s\n' \ @printf '%s\n' \
'ForgeOS targets:' \ 'ForgeOS targets:' \
' make deps - install Debian/Ubuntu host deps for rootfs + run' \ ' make deps - install Debian/Ubuntu host deps for rootfs + run' \
' make image-deps - install Debian/Ubuntu host deps for image + run-image' \
' make fetch - download upstream source tarballs' \ ' make fetch - download upstream source tarballs' \
' make kernel - build the Linux kernel and stage modules' \ ' make kernel - build the Linux kernel and stage modules' \
' make busybox - build BusyBox rescue utilities' \ ' make busybox - build BusyBox rescue utilities' \
@@ -48,6 +49,9 @@ help:
deps: deps:
@./scripts/install-deps.sh @./scripts/install-deps.sh
image-deps:
@./scripts/install-image-deps.sh
fetch: fetch:
@./scripts/fetch-sources.sh @./scripts/fetch-sources.sh
+1
View File
@@ -45,6 +45,7 @@ To build a UEFI disk image:
```bash ```bash
cd /home/joe/forgeos cd /home/joe/forgeos
sudo scripts/install-image-deps.sh
make image make image
make run-image make run-image
``` ```
+208
View File
@@ -0,0 +1,208 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
APT_UPDATE=1
DRY_RUN=0
CHECK_ONLY=0
image_packages=(
qemu-utils
parted
dosfstools
e2fsprogs
mtools
grub-common
grub-efi-amd64-bin
ovmf
)
required_commands=(
qemu-img
parted
mkfs.vfat
mkfs.ext4
mcopy
mmd
grub-mkstandalone
dd
awk
truncate
qemu-system-x86_64
)
required_paths=(
/usr/lib/grub/x86_64-efi
/usr/share/OVMF/OVMF_CODE_4M.fd
/usr/share/OVMF/OVMF_VARS_4M.fd
)
usage() {
cat <<EOF
Usage: scripts/install-image-deps.sh [options]
Install Debian/Ubuntu host packages needed for:
make image
make run-image
Options:
--check Only verify packages, commands, and firmware files; do not install.
--dry-run Print the apt commands that would run; do not install.
--no-update Skip apt-get update before installing.
--help Show this help.
This script first checks the console rootfs/run dependencies through
scripts/install-deps.sh, then installs the extra disk image and UEFI QEMU
dependencies. It does not install desktop, GNOME, host installer, or Secure Boot
signing extras.
EOF
}
msg() {
printf '==> %s\n' "$*"
}
die() {
printf 'error: %s\n' "$*" >&2
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--check)
CHECK_ONLY=1
;;
--dry-run)
DRY_RUN=1
;;
--no-update)
APT_UPDATE=0
;;
--help|-h)
usage
exit 0
;;
*)
die "unknown option: $1"
;;
esac
shift
done
if [[ ! -x "$ROOT_DIR/scripts/install-deps.sh" ]]; then
die "missing executable rootfs dependency installer: $ROOT_DIR/scripts/install-deps.sh"
fi
rootfs_args=()
[[ "$CHECK_ONLY" -eq 1 ]] && rootfs_args+=(--check)
[[ "$DRY_RUN" -eq 1 ]] && rootfs_args+=(--dry-run)
[[ "$APT_UPDATE" -eq 0 ]] && rootfs_args+=(--no-update)
rootfs_failed=0
if [[ "$CHECK_ONLY" -eq 1 ]]; then
if ! "$ROOT_DIR/scripts/install-deps.sh" "${rootfs_args[@]}"; then
rootfs_failed=1
fi
else
"$ROOT_DIR/scripts/install-deps.sh" "${rootfs_args[@]}"
fi
if ! command -v apt-get >/dev/null 2>&1; then
printf 'error: apt-get was not found. Install equivalent image packages manually:\n' >&2
printf ' %s\n' "${image_packages[*]}" >&2
exit 1
fi
if [[ -r /etc/os-release ]]; then
# shellcheck disable=SC1091
source /etc/os-release
os_family="${ID:-} ${ID_LIKE:-}"
case " $os_family " in
*" debian "*|*" ubuntu "*) ;;
*)
printf 'warning: this script is tested on Debian/Ubuntu hosts; detected ID=%s ID_LIKE=%s\n' "${ID:-unknown}" "${ID_LIKE:-unknown}" >&2
;;
esac
fi
missing_packages=()
for package in "${image_packages[@]}"; do
if ! dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -qx 'install ok installed'; then
missing_packages+=("$package")
fi
done
if [[ "$CHECK_ONLY" -eq 1 ]]; then
if [[ "${#missing_packages[@]}" -gt 0 ]]; then
printf 'missing image packages:\n' >&2
printf ' %s\n' "${missing_packages[@]}" >&2
fi
else
if [[ "${#missing_packages[@]}" -eq 0 ]]; then
msg "all required image packages are already installed"
else
if [[ "$EUID" -eq 0 ]]; then
sudo_cmd=()
elif command -v sudo >/dev/null 2>&1; then
sudo_cmd=(sudo)
else
die "missing image packages require root privileges and sudo is not installed"
fi
if [[ "$DRY_RUN" -eq 1 ]]; then
[[ "$APT_UPDATE" -eq 1 ]] && printf '%q ' "${sudo_cmd[@]}" apt-get update && printf '\n'
printf '%q ' "${sudo_cmd[@]}" apt-get install -y --no-install-recommends "${missing_packages[@]}"
printf '\n'
exit 0
fi
if [[ "$APT_UPDATE" -eq 1 ]]; then
msg "updating apt package indexes"
"${sudo_cmd[@]}" apt-get update
fi
msg "installing ForgeOS image/run-image dependencies"
"${sudo_cmd[@]}" apt-get install -y --no-install-recommends "${missing_packages[@]}"
fi
fi
missing_commands=()
for tool in "${required_commands[@]}"; do
if ! command -v "$tool" >/dev/null 2>&1; then
missing_commands+=("$tool")
fi
done
missing_paths=()
for path in "${required_paths[@]}"; do
if [[ ! -e "$path" ]]; then
missing_paths+=("$path")
fi
done
failed=0
if [[ "$rootfs_failed" -ne 0 ]]; then
failed=1
fi
if [[ "${#missing_packages[@]}" -gt 0 && "$CHECK_ONLY" -eq 1 ]]; then
failed=1
fi
if [[ "${#missing_commands[@]}" -gt 0 ]]; then
printf 'missing commands after image dependency check:\n' >&2
printf ' %s\n' "${missing_commands[@]}" >&2
failed=1
fi
if [[ "${#missing_paths[@]}" -gt 0 ]]; then
printf 'missing files after image dependency check:\n' >&2
printf ' %s\n' "${missing_paths[@]}" >&2
failed=1
fi
if [[ "$failed" -ne 0 ]]; then
exit 1
fi
msg "host dependencies are ready for make image and make run-image"
msg "project: $ROOT_DIR"