From 6f03ba80682a4ef4977cb73e7faedfb1f479361d Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 16 Jun 2026 15:21:12 -0400 Subject: [PATCH] Add dependency installer --- Makefile | 6 +- README.md | 3 +- scripts/install-deps.sh | 199 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 2 deletions(-) create mode 100755 scripts/install-deps.sh diff --git a/Makefile b/Makefile index 951f389..7328572 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,12 @@ export SECURE_BOOT_CERT ?= export GNOME_SUITE ?= trixie export GNOME_MIRROR ?= http://deb.debian.org/debian -.PHONY: help 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 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: @printf '%s\n' \ 'ForgeOS targets:' \ + ' make deps - install Debian/Ubuntu host deps for rootfs + run' \ ' make fetch - download upstream source tarballs' \ ' make kernel - build the Linux kernel and stage modules' \ ' make busybox - build BusyBox rescue utilities' \ @@ -44,6 +45,9 @@ help: ' make clean - remove build, staging, and output artifacts' \ ' make distclean - also remove downloaded and extracted sources' +deps: + @./scripts/install-deps.sh + fetch: @./scripts/fetch-sources.sh diff --git a/README.md b/README.md index 2d61b2f..a9b7b10 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,12 @@ As of `2026-06-16`, the project defaults to: ```bash cd /home/joe/forgeos +sudo scripts/install-deps.sh make rootfs make run ``` -That path builds the kernel, systemd, D-Bus, BusyBox rescue tools, and a compressed initramfs, then boots it directly in QEMU over serial. +That dependency script is for Debian/Ubuntu hosts and installs only the packages needed for the console rootfs plus direct QEMU boot path. The build path then builds the kernel, systemd, D-Bus, BusyBox rescue tools, and a compressed initramfs, then boots it directly in QEMU over serial. To build a UEFI disk image: diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh new file mode 100755 index 0000000..fdbcd0c --- /dev/null +++ b/scripts/install-deps.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +APT_UPDATE=1 +DRY_RUN=0 +CHECK_ONLY=0 + +packages=( + build-essential + bc + bison + flex + ca-certificates + curl + tar + xz-utils + bzip2 + gzip + cpio + rsync + file + pkg-config + meson + ninja-build + gperf + python3 + perl + kmod + openssl + libcap-dev + libmount-dev + libblkid-dev + libexpat1-dev + zlib1g-dev + libzstd-dev + libssl-dev + libelf-dev + qemu-system-x86 +) + +required_commands=( + bash + make + gcc + curl + tar + xz + bzip2 + gzip + cpio + rsync + file + pkg-config + meson + ninja + gperf + python3 + perl + depmod + openssl + ldd + ldconfig + install + qemu-system-x86_64 +) + +usage() { + cat < %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 [[ "$(uname -m)" != "x86_64" ]]; then + printf 'warning: ForgeOS currently expects a native x86_64 build host; this host is %s\n' "$(uname -m)" >&2 +fi + +if ! command -v apt-get >/dev/null 2>&1; then + printf 'error: apt-get was not found. Install equivalent packages manually:\n' >&2 + printf ' %s\n' "${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 "${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 packages:\n' >&2 + printf ' %s\n' "${missing_packages[@]}" >&2 + exit 1 + fi +else + if [[ "${#missing_packages[@]}" -eq 0 ]]; then + msg "all required 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 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 rootfs/run 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 + +if [[ "${#missing_commands[@]}" -gt 0 ]]; then + printf 'missing commands after dependency check:\n' >&2 + printf ' %s\n' "${missing_commands[@]}" >&2 + exit 1 +fi + +msg "host dependencies are ready for make rootfs and make run" +msg "project: $ROOT_DIR"