mirror of
https://git.valherun.com/valherun/pxe_boot_alma.git
synced 2026-10-14 19:12:03 -04:00
- restructure boot/kickstarts/scripts/docs into homelab/ - docs: alma9->10 breaking changes, CIS hardening, kickstart changes - add find_cron_entries.sh helper and codex running memory notes Co-Authored-By: Claude Fable 5 <[email protected]>
102 lines
3.5 KiB
Bash
Executable File
102 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# sync_alma_tree.sh — Mount an AlmaLinux ISO and sync its contents into the
|
|
# KickStart HTTP tree, with optional tftpboot kernel/initrd extraction.
|
|
#
|
|
# Usage:
|
|
# sync_alma_tree.sh --iso FILE --http-root DIR [options]
|
|
#
|
|
# Options:
|
|
# --iso FILE Path to the AlmaLinux (or CentOS) ISO
|
|
# --http-root DIR Destination HTTP-served install tree
|
|
# --mount-dir DIR Temp mount point (default: auto via mktemp)
|
|
# --tftpboot-dir DIR If given, copy vmlinuz + initrd from images/pxeboot/
|
|
# into this dir using the versioned naming convention:
|
|
# vmlinuz-<LABEL>-pxe
|
|
# initrd-<LABEL>-pxe.img
|
|
# where LABEL is derived from --iso filename
|
|
# (e.g. AlmaLinux-10.1-x86_64 from AlmaLinux-10.1-x86_64-dvd.iso)
|
|
# -h, --help Show this help
|
|
|
|
set -euo pipefail
|
|
|
|
ISO_PATH=""
|
|
HTTP_ROOT=""
|
|
MOUNT_DIR=""
|
|
TFTPBOOT_DIR=""
|
|
|
|
usage() {
|
|
sed -n '/^# Usage:/,/^[^#]/{ /^[^#]/d; s/^# \{0,3\}//; p }' "$0"
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--iso) ISO_PATH="$2"; shift 2 ;;
|
|
--http-root) HTTP_ROOT="$2"; shift 2 ;;
|
|
--mount-dir) MOUNT_DIR="$2"; shift 2 ;;
|
|
--tftpboot-dir) TFTPBOOT_DIR="$2"; shift 2 ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) echo "Unknown option: $1" >&2; usage >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$ISO_PATH" || -z "$HTTP_ROOT" ]]; then
|
|
usage >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$ISO_PATH" ]]; then
|
|
echo "ISO not found: $ISO_PATH" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Re-running with sudo..."
|
|
exec sudo "$0" "$@"
|
|
fi
|
|
|
|
if [[ -z "$MOUNT_DIR" ]]; then
|
|
MOUNT_DIR="$(mktemp -d /tmp/alma-iso.XXXXXX)"
|
|
fi
|
|
|
|
cleanup() {
|
|
if mountpoint -q "$MOUNT_DIR" 2>/dev/null; then
|
|
umount "$MOUNT_DIR"
|
|
fi
|
|
rmdir "$MOUNT_DIR" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
mount -o loop,ro "$ISO_PATH" "$MOUNT_DIR"
|
|
|
|
# ── HTTP install tree ─────────────────────────────────────────────────────────
|
|
mkdir -p "$HTTP_ROOT"
|
|
echo "Syncing install tree to $HTTP_ROOT ..."
|
|
rsync -aH --delete --info=progress2 "$MOUNT_DIR"/ "$HTTP_ROOT"/
|
|
echo "Install tree synced."
|
|
|
|
# ── tftpboot kernel + initrd extraction ──────────────────────────────────────
|
|
if [[ -n "$TFTPBOOT_DIR" ]]; then
|
|
PXEBOOT="$MOUNT_DIR/images/pxeboot"
|
|
if [[ ! -f "$PXEBOOT/vmlinuz" || ! -f "$PXEBOOT/initrd.img" ]]; then
|
|
echo "WARNING: images/pxeboot/vmlinuz or initrd.img not found in ISO — skipping tftpboot extraction." >&2
|
|
else
|
|
# Derive label from ISO filename: strip path, strip extension(s)
|
|
# AlmaLinux-10.1-x86_64-dvd.iso → AlmaLinux-10.1-x86_64
|
|
# AlmaLinux-9.2-x86_64-minimal.iso → AlmaLinux-9.2-x86_64
|
|
BASENAME="$(basename "$ISO_PATH")"
|
|
LABEL="${BASENAME%.iso}"
|
|
LABEL="${LABEL%.ISO}"
|
|
# Strip trailing -dvd, -minimal, -boot, -netinstall suffixes
|
|
LABEL="$(echo "$LABEL" | sed -E 's/-(dvd|minimal|boot|netinstall)$//')"
|
|
|
|
VMLINUZ_DEST="$TFTPBOOT_DIR/vmlinuz-${LABEL}-pxe"
|
|
INITRD_DEST="$TFTPBOOT_DIR/initrd-${LABEL}-pxe.img"
|
|
|
|
mkdir -p "$TFTPBOOT_DIR"
|
|
echo "Extracting tftpboot files with label: $LABEL"
|
|
cp -v "$PXEBOOT/vmlinuz" "$VMLINUZ_DEST"
|
|
cp -v "$PXEBOOT/initrd.img" "$INITRD_DEST"
|
|
echo "tftpboot extraction complete."
|
|
fi
|
|
fi
|