#!/bin/bash # # Build Archipelago Auto-Installer ISO (StartOS-like) # # This creates an ISO that automatically installs to the internal disk # with minimal user interaction - similar to StartOS experience. # # CRITICAL: This script CAPTURES the LIVE SERVER state by default. # Set DEV_SERVER to point to your development server. # # Usage: # DEV_SERVER=archipelago@192.168.1.228 ./build-auto-installer-iso.sh # OR just: ./build-auto-installer-iso.sh (uses default server) # # To build from source instead: # BUILD_FROM_SOURCE=1 ./build-auto-installer-iso.sh # # Features: # - Pre-built root filesystem (no network needed during install) # - Auto-detects internal disk (skips USB boot drive) # - Automatic installation with progress display # - Boots directly to web UI after install # # Image versions: sourced from scripts/image-versions.sh (single source of truth). # All container image references MUST use the $*_IMAGE variables defined there. # # --- PLANNED REFACTOR (post-beta) --- # This script is ~1870 lines and should be split into a modular library. # Proposed structure: # image-recipe/ # build-auto-installer-iso.sh — Main orchestrator (config, CLI args, step sequencing) # lib/ # rootfs.sh — Step 1: Build root filesystem via Docker (~185 lines) # installer-env.sh — Step 2: Build minimal installer via debootstrap (~80 lines) # components.sh — Step 3: Add Archipelago components (binary, configs, web UI) (~120 lines) # container-images.sh — Step 3b: Bundle container images for offline install (~330 lines) # auto-install-script.sh — Step 4: Generate the embedded auto-install.sh (~615 lines) # boot-config.sh — Step 5: Configure live boot auto-start + overlay squashfs (~215 lines) # create-iso.sh — Step 6: Build final bootable ISO with xorriso/grub (~140 lines) # Each lib/ script exports functions; main script sources them and calls in sequence. # DO NOT split until tested on the build server — this is critical infrastructure. # --- # set -e # Source pinned image versions (single source of truth) SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" [ -f "$SCRIPT_DIR/../scripts/image-versions.sh" ] && . "$SCRIPT_DIR/../scripts/image-versions.sh" # Configuration DEV_SERVER="${DEV_SERVER:-archipelago@192.168.1.228}" BUILD_FROM_SOURCE="${BUILD_FROM_SOURCE:-0}" UNBUNDLED="${UNBUNDLED:-0}" ARCH="${ARCH:-x86_64}" # ── Sequential build numbering ───────────────────────────────────────── # Increments on each build. Users see this in UI (Settings, sidebar). # Counter persists in /opt/archipelago/build-counter (on build machine). BUILD_COUNTER_FILE="/opt/archipelago/build-counter" if [ -f "$BUILD_COUNTER_FILE" ]; then BUILD_NUM=$(( $(cat "$BUILD_COUNTER_FILE") + 1 )) else BUILD_NUM=1 fi echo "$BUILD_NUM" | sudo tee "$BUILD_COUNTER_FILE" > /dev/null 2>/dev/null || BUILD_NUM=1 GIT_SHORT=$(cd "$SCRIPT_DIR/.." && git rev-parse --short HEAD 2>/dev/null || echo "dev") # Version format: major.minor.patch-prerelease (semver) # Read version from Cargo.toml (single source of truth) BUILD_VERSION=$(grep '^version' "$SCRIPT_DIR/../core/archipelago/Cargo.toml" 2>/dev/null | head -1 | sed 's/version = "//;s/"//' || echo "0.0.0") echo "Build #${BUILD_NUM} (${BUILD_VERSION}, commit ${GIT_SHORT})" # Architecture-dependent variables case "$ARCH" in x86_64|amd64) ARCH="x86_64" DEB_ARCH="amd64" LINUX_IMAGE_PKG="linux-image-amd64" GRUB_EFI_PKG="grub-efi-amd64" GRUB_EFI_SIGNED_PKG="grub-efi-amd64-signed" GRUB_PC_PKG="grub-pc-bin" GRUB_TARGET="x86_64-efi" GRUB_BIOS_TARGET="i386-pc" CONTAINER_PLATFORM="linux/amd64" LIB_DIR="${LIB_DIR}" ;; arm64|aarch64) ARCH="arm64" DEB_ARCH="arm64" LINUX_IMAGE_PKG="linux-image-arm64" GRUB_EFI_PKG="grub-efi-arm64" GRUB_EFI_SIGNED_PKG="grub-efi-arm64-signed" GRUB_PC_PKG="" GRUB_TARGET="arm64-efi" GRUB_BIOS_TARGET="" CONTAINER_PLATFORM="linux/arm64" LIB_DIR="aarch64-linux-gnu" ;; *) echo "❌ Unsupported architecture: $ARCH (use x86_64 or arm64)" exit 1 ;; esac SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" WORK_DIR="$SCRIPT_DIR/build/auto-installer" OUTPUT_DIR="$SCRIPT_DIR/results" ROOTFS_DIR="$WORK_DIR/rootfs" INSTALLER_DIR="$WORK_DIR/installer" if [ "$UNBUNDLED" = "1" ]; then echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Building Archipelago UNBUNDLED ISO (no pre-loaded apps) ║" echo "╚════════════════════════════════════════════════════════════════╝" else echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Building Archipelago Auto-Installer ISO (StartOS-like) ║" echo "╚════════════════════════════════════════════════════════════════╝" fi echo "" if [ "$BUILD_FROM_SOURCE" = "1" ]; then echo "📦 Mode: Building from SOURCE CODE" elif [ "$UNBUNDLED" = "1" ]; then echo "📦 Mode: UNBUNDLED (apps downloaded on-demand from Marketplace)" echo " Server: $DEV_SERVER (backend + web UI only)" else echo "📦 Mode: Capturing LIVE SERVER state" echo " Server: $DEV_SERVER" fi echo "🏗️ Architecture: $ARCH ($DEB_ARCH)" echo "" # Check for required tools check_tools() { local missing="" local can_install=false # Check if we can auto-install (running as root on Debian/Ubuntu) if [ "$EUID" -eq 0 ] && [ -f /etc/debian_version ]; then can_install=true fi # Check for docker or podman if command -v docker >/dev/null 2>&1; then CONTAINER_CMD="docker" elif command -v podman >/dev/null 2>&1; then CONTAINER_CMD="podman" else missing="$missing docker-or-podman" fi for tool in xorriso mksquashfs; do if ! command -v $tool >/dev/null 2>&1; then missing="$missing $tool" fi done # Check for isolinux MBR (needed for hybrid USB boot) if [ ! -f /usr/lib/ISOLINUX/isohdpfx.bin ] && [ ! -f /usr/share/syslinux/isohdpfx.bin ]; then missing="$missing isolinux" fi if [ -n "$missing" ]; then echo "Missing required tools:$missing" if [ "$can_install" = true ]; then echo " Auto-installing missing dependencies..." apt-get update -qq if [[ "$missing" == *"xorriso"* ]]; then apt-get install -y xorriso fi if [[ "$missing" == *"mksquashfs"* ]]; then apt-get install -y squashfs-tools fi if [[ "$missing" == *"isolinux"* ]]; then apt-get install -y isolinux syslinux-common fi if [[ "$missing" == *"docker-or-podman"* ]]; then echo " Installing podman..." apt-get install -y podman CONTAINER_CMD="podman" fi echo " Dependencies installed successfully!" else echo " Install with: sudo apt install xorriso squashfs-tools isolinux podman" echo " Or run this script with sudo to auto-install" exit 1 fi fi # Re-check after potential installation if command -v docker >/dev/null 2>&1; then CONTAINER_CMD="docker" elif command -v podman >/dev/null 2>&1; then CONTAINER_CMD="podman" else echo "❌ Container runtime still not available after installation" exit 1 fi echo "Using container runtime: $CONTAINER_CMD" # Fix root podman D-Bus issue (sd-bus: Transport endpoint is not connected) # When running as sudo, systemd cgroup manager can't reach the user D-Bus session. if [ "$CONTAINER_CMD" = "podman" ] && [ "$(id -u)" = "0" ]; then if ! $CONTAINER_CMD run --rm debian:bookworm true 2>/dev/null; then echo " Root podman D-Bus issue detected, using cgroupfs manager" CONTAINER_CMD="podman --cgroup-manager=cgroupfs" fi fi # Ensure insecure registry config for Archipelago app registry (HTTP) if [ "$CONTAINER_CMD" = "podman" ]; then mkdir -p /etc/containers/registries.conf.d cat > /etc/containers/registries.conf.d/archipelago.conf <<'REGCONF' [[registry]] location = "80.71.235.15:3000" insecure = true REGCONF fi } check_tools mkdir -p "$WORK_DIR" mkdir -p "$OUTPUT_DIR" # ============================================================================= # STEP 1: Build complete root filesystem using Docker # ============================================================================= echo "📦 Step 1: Building root filesystem..." ROOTFS_TAR="$WORK_DIR/archipelago-rootfs.tar" if [ ! -f "$ROOTFS_TAR" ] || [ "$1" == "--rebuild" ]; then echo " Using Docker to create Debian root filesystem..." # Create a Dockerfile for building the rootfs cat > "$WORK_DIR/Dockerfile.rootfs" < /etc/apt/sources.list && \ echo "deb http://deb.debian.org/debian bookworm-updates main non-free-firmware" >> /etc/apt/sources.list && \ echo "deb http://deb.debian.org/debian-security bookworm-security main non-free-firmware" >> /etc/apt/sources.list && \ rm -f /etc/apt/sources.list.d/debian.sources # Install all packages we need including nginx, podman, tor, and openssl (for self-signed certs) RUN apt-get update && apt-get install -y --no-install-recommends \ ${LINUX_IMAGE_PKG} \ ${GRUB_EFI_PKG} \ ${GRUB_EFI_SIGNED_PKG} \ ${GRUB_PC_PKG} \ systemd \ systemd-sysv \ dbus \ sudo \ network-manager \ openssh-server \ nginx \ podman \ uidmap \ slirp4netns \ fuse-overlayfs \ tor \ python3 \ curl \ git \ vim-tiny \ ca-certificates \ openssl \ chrony \ locales \ console-setup \ keyboard-configuration \ cryptsetup \ firmware-realtek \ firmware-iwlwifi \ firmware-misc-nonfree \ firmware-linux-nonfree \ intel-microcode \ amd64-microcode \ xorg \ xdotool \ chromium \ unclutter \ fonts-liberation \ xfonts-base \ plymouth \ plymouth-themes \ zstd \ socat \ python3 \ apache2-utils \ wireguard-tools \ acpid \ acpi-support-base \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Strip docs, man pages, and unused locales RUN find /usr/share/doc -depth -type f ! -name copyright -delete 2>/dev/null || true && \ find /usr/share/doc -empty -delete 2>/dev/null || true && \ rm -rf /usr/share/man /usr/share/info /usr/share/lintian /usr/share/linda && \ find /usr/share/locale -maxdepth 1 -mindepth 1 ! -name 'en_US' ! -name 'locale.alias' -exec rm -rf {} + 2>/dev/null || true # Install Tailscale from official repo RUN curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.noarmor.gpg | tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null && \ curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.tailscale-keyring.list | tee /etc/apt/sources.list.d/tailscale.list && \ apt-get update && apt-get install -y --no-install-recommends tailscale && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Configure locale RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen # Create archipelago user with password "archipelago" RUN useradd -m -s /bin/bash -G sudo archipelago && \ echo "archipelago:archipelago" | chpasswd && \ echo "root:archipelago" | chpasswd && \ echo "archipelago ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/archipelago # Verify password hash was set (not locked) RUN grep -q "^archipelago:\$" /etc/shadow && echo "Password set OK" || echo "WARNING: password may not be set" # Set hostname RUN echo "archipelago" > /etc/hostname # Configure SSH RUN mkdir -p /etc/ssh && \ sed -i 's/#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config || true && \ sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config || true # Configure nginx for Archipelago RUN rm -f /etc/nginx/sites-enabled/default COPY nginx-archipelago.conf /etc/nginx/sites-available/archipelago RUN ln -sf /etc/nginx/sites-available/archipelago /etc/nginx/sites-enabled/archipelago # Install nginx snippets (PWA config, HTTPS app proxies) COPY snippets/ /etc/nginx/snippets/ # Generate self-signed SSL certificate for HTTPS (PWA install requires secure context) RUN mkdir -p /etc/archipelago/ssl && \ openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ -keyout /etc/archipelago/ssl/archipelago.key \ -out /etc/archipelago/ssl/archipelago.crt \ -subj "/C=XX/ST=Bitcoin/L=Node/O=Archipelago/CN=archipelago" && \ chmod 600 /etc/archipelago/ssl/archipelago.key # Create archipelago systemd service COPY archipelago.service /etc/systemd/system/archipelago.service COPY archipelago-update.service /etc/systemd/system/archipelago-update.service COPY archipelago-update.timer /etc/systemd/system/archipelago-update.timer COPY archipelago-doctor.service /etc/systemd/system/archipelago-doctor.service COPY archipelago-doctor.timer /etc/systemd/system/archipelago-doctor.timer COPY archipelago-reconcile.service /etc/systemd/system/archipelago-reconcile.service COPY archipelago-reconcile.timer /etc/systemd/system/archipelago-reconcile.timer COPY archipelago-tor-helper.service /etc/systemd/system/archipelago-tor-helper.service COPY archipelago-tor-helper.path /etc/systemd/system/archipelago-tor-helper.path COPY nostr-vpn.service /etc/systemd/system/nostr-vpn.service COPY archipelago-wg.service /etc/systemd/system/archipelago-wg.service COPY archipelago-wg-address.service /etc/systemd/system/archipelago-wg-address.service COPY nostr-relay.service /etc/systemd/system/nostr-relay.service COPY nostr-relay-config.toml /etc/archipelago/nostr-relay-config.toml # WireGuard kernel module auto-load on boot RUN echo "wireguard" >> /etc/modules-load.d/wireguard.conf # Copy container doctor + reconcile scripts (referenced by the services above) RUN mkdir -p /home/archipelago/archy/scripts/lib COPY container-doctor.sh /home/archipelago/archy/scripts/container-doctor.sh COPY reconcile-containers.sh /home/archipelago/archy/scripts/reconcile-containers.sh COPY container-specs.sh /home/archipelago/archy/scripts/container-specs.sh COPY tor-helper.sh /opt/archipelago/scripts/tor-helper.sh COPY lib/ /home/archipelago/archy/scripts/lib/ RUN chmod +x /home/archipelago/archy/scripts/*.sh /home/archipelago/archy/scripts/lib/*.sh /opt/archipelago/scripts/*.sh && \ chown -R archipelago:archipelago /home/archipelago/archy # Enable services RUN systemctl enable NetworkManager || true && \ systemctl enable ssh || true && \ systemctl enable nginx || true && \ systemctl enable archipelago || true && \ systemctl enable tor || true && \ systemctl enable tailscaled || true && \ systemctl enable chrony || true && \ systemctl enable archipelago-update.timer || true && \ systemctl enable archipelago-doctor.timer || true && \ systemctl enable archipelago-reconcile.timer || true && \ systemctl enable archipelago-tor-helper.path || true && \ systemctl enable nostr-relay || true # archipelago-wg + wg-address: enabled by first-boot after WG key is generated # nostr-vpn: enabled by first-boot after Nostr identity is generated # (env file doesn't exist until onboarding, so pre-enabling causes crash-loop) # Remove policy-rc.d so services can start on first boot RUN rm -f /usr/sbin/policy-rc.d # Create directories (including Cloud storage for FileBrowser) RUN mkdir -p /var/lib/archipelago/data /var/lib/archipelago/config /var/lib/archipelago/containers /var/lib/archipelago/nostr-relay /var/lib/archipelago/nostr-vpn && \ mkdir -p /etc/archipelago && \ mkdir -p /opt/archipelago/bin /opt/archipelago/scripts /opt/archipelago/web-ui && \ mkdir -p /var/lib/archipelago/data/cloud/Documents /var/lib/archipelago/data/cloud/Photos /var/lib/archipelago/data/cloud/Music /var/lib/archipelago/data/cloud/Videos /var/lib/archipelago/data/cloud/Downloads && \ cp /etc/archipelago/nostr-relay-config.toml /var/lib/archipelago/nostr-relay/config.toml && \ chown -R archipelago:archipelago /var/lib/archipelago /opt/archipelago # Clean up RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* DOCKERFILE # Copy nginx snippets for HTTPS (PWA, app proxies) if [ -d "$SCRIPT_DIR/configs/snippets" ]; then mkdir -p "$WORK_DIR/snippets" cp "$SCRIPT_DIR/configs/snippets/"*.conf "$WORK_DIR/snippets/" 2>/dev/null || true echo " Using nginx snippets from configs/snippets/" else mkdir -p "$WORK_DIR/snippets" echo " ⚠ No nginx snippets found, HTTPS features may not work" fi # Use nginx config from configs/ (includes app proxies for Nextcloud, Vaultwarden, etc.) if [ -f "$SCRIPT_DIR/configs/nginx-archipelago.conf" ]; then cp "$SCRIPT_DIR/configs/nginx-archipelago.conf" "$WORK_DIR/nginx-archipelago.conf" echo " Using nginx config from configs/nginx-archipelago.conf" else echo " ⚠ configs/nginx-archipelago.conf not found, using minimal config" cat > "$WORK_DIR/nginx-archipelago.conf" <<'NGINXCONF' server { listen 80; server_name _; root /opt/archipelago/web-ui; index index.html; location / { try_files $uri $uri/ /index.html; } location /archipelago/ { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /rpc/ { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } location /ws { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_read_timeout 86400s; } } NGINXCONF fi # Copy udev rule for mesh radio stable naming if [ -f "$SCRIPT_DIR/configs/99-mesh-radio.rules" ]; then cp "$SCRIPT_DIR/configs/99-mesh-radio.rules" "$WORK_DIR/99-mesh-radio.rules" echo " Using 99-mesh-radio.rules from configs/" fi # Copy update service and timer if [ -f "$SCRIPT_DIR/configs/archipelago-update.service" ]; then cp "$SCRIPT_DIR/configs/archipelago-update.service" "$WORK_DIR/archipelago-update.service" cp "$SCRIPT_DIR/configs/archipelago-update.timer" "$WORK_DIR/archipelago-update.timer" echo " Using archipelago-update.service + timer from configs/" fi # Copy container doctor and reconciliation timers + scripts if [ -f "$SCRIPT_DIR/configs/archipelago-doctor.service" ]; then cp "$SCRIPT_DIR/configs/archipelago-doctor.service" "$WORK_DIR/archipelago-doctor.service" cp "$SCRIPT_DIR/configs/archipelago-doctor.timer" "$WORK_DIR/archipelago-doctor.timer" cp "$SCRIPT_DIR/configs/archipelago-reconcile.service" "$WORK_DIR/archipelago-reconcile.service" cp "$SCRIPT_DIR/configs/archipelago-reconcile.timer" "$WORK_DIR/archipelago-reconcile.timer" # Copy the actual scripts the services reference for s in container-doctor.sh reconcile-containers.sh container-specs.sh tor-helper.sh; do if [ -f "$SCRIPT_DIR/../scripts/$s" ]; then cp "$SCRIPT_DIR/../scripts/$s" "$WORK_DIR/$s" fi done # Copy shared script library (mem_limit etc.) if [ -d "$SCRIPT_DIR/../scripts/lib" ]; then mkdir -p "$WORK_DIR/lib" cp "$SCRIPT_DIR/../scripts/lib/"*.sh "$WORK_DIR/lib/" 2>/dev/null || true fi echo " Using container doctor + reconcile timers from configs/" fi # Copy Tor helper path-activated service (allows backend to manage Tor as non-root) if [ -f "$SCRIPT_DIR/configs/archipelago-tor-helper.service" ]; then cp "$SCRIPT_DIR/configs/archipelago-tor-helper.service" "$WORK_DIR/archipelago-tor-helper.service" cp "$SCRIPT_DIR/configs/archipelago-tor-helper.path" "$WORK_DIR/archipelago-tor-helper.path" echo " Using tor-helper path unit from configs/" fi # Copy NostrVPN system service (native mesh VPN, not a container) if [ -f "$SCRIPT_DIR/configs/nostr-vpn.service" ]; then cp "$SCRIPT_DIR/configs/nostr-vpn.service" "$WORK_DIR/nostr-vpn.service" echo " Using nostr-vpn.service from configs/" fi if [ -f "$SCRIPT_DIR/configs/archipelago-wg.service" ]; then cp "$SCRIPT_DIR/configs/archipelago-wg.service" "$WORK_DIR/archipelago-wg.service" echo " Using archipelago-wg.service from configs/" fi if [ -f "$SCRIPT_DIR/configs/archipelago-wg-address.service" ]; then cp "$SCRIPT_DIR/configs/archipelago-wg-address.service" "$WORK_DIR/archipelago-wg-address.service" echo " Using archipelago-wg-address.service from configs/" fi # Copy private Nostr relay service (native, for NostrVPN signaling) if [ -f "$SCRIPT_DIR/configs/nostr-relay.service" ]; then cp "$SCRIPT_DIR/configs/nostr-relay.service" "$WORK_DIR/nostr-relay.service" echo " Using nostr-relay.service from configs/" fi if [ -f "$SCRIPT_DIR/configs/nostr-relay-config.toml" ]; then cp "$SCRIPT_DIR/configs/nostr-relay-config.toml" "$WORK_DIR/nostr-relay-config.toml" echo " Using nostr-relay-config.toml from configs/" fi # Copy WireGuard helper script (privileged peer management) if [ -f "$SCRIPT_DIR/../scripts/archipelago-wg" ]; then cp "$SCRIPT_DIR/../scripts/archipelago-wg" "$WORK_DIR/archipelago-wg" echo " Using archipelago-wg helper from scripts/" fi # Use archipelago.service from configs/ (User=root for Podman container access) if [ -f "$SCRIPT_DIR/configs/archipelago.service" ]; then cp "$SCRIPT_DIR/configs/archipelago.service" "$WORK_DIR/archipelago.service" echo " Using archipelago.service from configs/" else cat > "$WORK_DIR/archipelago.service" <<'SYSTEMDSERVICE' [Unit] Description=Archipelago Backend After=network-online.target archipelago-setup-tor.service Wants=network-online.target [Service] Type=simple User=archipelago Environment="ARCHIPELAGO_BIND=127.0.0.1:5678" Environment="XDG_RUNTIME_DIR=/run/user/1000" ExecStartPre=/bin/bash -c 'mkdir -p /run/user/1000 && chown archipelago:archipelago /run/user/1000 && chmod 700 /run/user/1000' ExecStart=/usr/local/bin/archipelago Restart=on-failure RestartSec=5 ProtectHome=no [Install] WantedBy=multi-user.target SYSTEMDSERVICE fi echo " Building $CONTAINER_CMD image (this may take a few minutes)..." $CONTAINER_CMD build --no-cache --platform $CONTAINER_PLATFORM -t archipelago-rootfs -f "$WORK_DIR/Dockerfile.rootfs" "$WORK_DIR" echo " Exporting filesystem..." $CONTAINER_CMD rm -f archipelago-rootfs-tmp 2>/dev/null || true $CONTAINER_CMD create --platform $CONTAINER_PLATFORM --name archipelago-rootfs-tmp archipelago-rootfs $CONTAINER_CMD export archipelago-rootfs-tmp > "$ROOTFS_TAR" $CONTAINER_CMD rm archipelago-rootfs-tmp echo "✅ Root filesystem created: $(du -h "$ROOTFS_TAR" | cut -f1)" else echo "✅ Using cached root filesystem: $(du -h "$ROOTFS_TAR" | cut -f1)" fi # ============================================================================= # STEP 2: Build minimal installer environment (replaces Debian Live) # ============================================================================= echo "" echo "Step 2: Building minimal installer environment via debootstrap..." INSTALLER_ISO="$WORK_DIR/installer-iso" INSTALLER_SQUASHFS="$WORK_DIR/installer-squashfs" rm -rf "$INSTALLER_ISO" "$INSTALLER_SQUASHFS" mkdir -p "$INSTALLER_ISO/live" "$INSTALLER_ISO/archipelago" mkdir -p "$INSTALLER_ISO/boot/grub" "$INSTALLER_ISO/isolinux" mkdir -p "$INSTALLER_ISO/EFI/BOOT" # Build the installer filesystem inside a container # This creates: vmlinuz, initrd.img, filesystem.squashfs echo " Building installer rootfs with debootstrap (this takes a few minutes)..." $CONTAINER_CMD run --rm --privileged --platform $CONTAINER_PLATFORM \ -v "$WORK_DIR:/output" \ -e DEB_ARCH="$DEB_ARCH" \ -e LIB_DIR="$LIB_DIR" \ debian:bookworm bash -c ' set -e apt-get update -qq apt-get install -y -qq debootstrap squashfs-tools initramfs-tools dosfstools mtools \ grub-efi-amd64-bin grub-pc-bin grub-common isolinux syslinux-common echo " [container] Running debootstrap --variant=minbase..." debootstrap --variant=minbase --arch=${DEB_ARCH} \ --include=systemd,systemd-sysv,udev,dbus,bash,coreutils,mount,util-linux,\ kmod,procps,iproute2,ca-certificates,gdisk,\ cryptsetup,cryptsetup-initramfs,parted,dosfstools,e2fsprogs,\ linux-image-${DEB_ARCH},grub-efi-${DEB_ARCH},grub-pc-bin,\ pciutils,usbutils,less,nano \ bookworm /installer http://deb.debian.org/debian # Install live-boot via chroot — debootstrap minbase resolver cannot handle it. # The chroot approach works (confirmed in CI run 90) — just needs proc/sys/dev mounts. echo " [container] Installing live-boot for squashfs root support..." cp /etc/resolv.conf /installer/etc/resolv.conf 2>/dev/null || true mount --bind /proc /installer/proc mount --bind /sys /installer/sys mount --bind /dev /installer/dev chroot /installer apt-get update -qq chroot /installer apt-get install -y --no-install-recommends live-boot live-boot-initramfs-tools chroot /installer apt-get clean umount /installer/dev 2>/dev/null || true umount /installer/sys 2>/dev/null || true umount /installer/proc 2>/dev/null || true # Verify live-boot hooks are in place (scripts/live is a FILE not a directory) if [ -e /installer/usr/share/initramfs-tools/scripts/live ]; then echo " [container] live-boot initramfs hooks: OK" else echo " [container] FATAL: live-boot hooks not found after install!" ls -la /installer/usr/share/initramfs-tools/scripts/ 2>/dev/null exit 1 fi echo " [container] Configuring installer environment..." # Set hostname echo "archipelago-installer" > /installer/etc/hostname # Set root password echo "root:archipelago" | chroot /installer chpasswd # Auto-login on tty1 mkdir -p /installer/etc/systemd/system/getty@tty1.service.d cat > /installer/etc/systemd/system/getty@tty1.service.d/autologin.conf < /installer/etc/profile.d/z99-archipelago-installer.sh </dev/null || exit 0 fi export INSTALLER_STARTED=1 sleep 1 clear echo "" echo -e "\033[38;5;208m ▄▀█ █▀▄ █▀▀ █ █ █ █▀█ █▀▀ █ ▄▀█ █▀▀ █▀█\033[0m" echo -e "\033[38;5;208m █▀█ █▀▄ █ █▀█ █ █▀▀ ██▀ █ █▀█ █ █ █ █\033[0m" echo -e "\033[38;5;208m ▀ ▀ ▀ ▀ ▀▀▀ ▀ ▀ ▀ ▀ ▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀ ▀▀▀\033[0m" echo -e " \033[38;5;130mbitcoin node os\033[0m" echo "" BOOT_MEDIA="" for dev in /run/live/medium /lib/live/mount/medium /run/archiso /cdrom /media/cdrom /mnt/iso; do if [ -f "\$dev/archipelago/auto-install.sh" ]; then BOOT_MEDIA="\$dev" break fi done # If standard mount points failed, actively find and mount the boot device if [ -z "\$BOOT_MEDIA" ]; then echo -e " \033[37mSearching for boot device...\033[0m" mkdir -p /run/archiso 2>/dev/null for blk in /dev/sr0 /dev/sd[a-z] /dev/sd[a-z][0-9] /dev/nvme[0-9]n[0-9]p[0-9]; do [ -b "\$blk" ] || continue mount -o ro "\$blk" /run/archiso 2>/dev/null || continue if [ -f /run/archiso/archipelago/auto-install.sh ]; then BOOT_MEDIA="/run/archiso" break fi umount /run/archiso 2>/dev/null done fi if [ -n "\$BOOT_MEDIA" ]; then echo -e " \033[37mFound installer at: \$BOOT_MEDIA\033[0m" echo "" echo -e " Press Enter to install | \033[1;37mCtrl+C\033[0m for shell" read -s bash "\$BOOT_MEDIA/archipelago/auto-install.sh" else echo -e " \033[37mInstaller not found on boot media.\033[0m" echo "" echo -e " \033[37mDebug info:\033[0m" ls -la /run/live/ 2>/dev/null || echo " /run/live/ does not exist" mount | grep -E "iso9660|squashfs|overlay" 2>/dev/null echo "" echo -e " \033[37mTry: mount /dev/sdX /mnt/iso && bash /mnt/iso/archipelago/auto-install.sh\033[0m" echo "" fi PROFILE chmod +x /installer/etc/profile.d/z99-archipelago-installer.sh # Custom initramfs hook: mount ISO boot media at /run/archiso mkdir -p /installer/etc/initramfs-tools/hooks cat > /installer/etc/initramfs-tools/hooks/archipelago </dev/null || true copy_exec /sbin/blkid manual_add_modules iso9660 vfat squashfs overlay HOOK chmod +x /installer/etc/initramfs-tools/hooks/archipelago mkdir -p /installer/etc/initramfs-tools/scripts/local-bottom cat > /installer/etc/initramfs-tools/scripts/local-bottom/archipelago-mount </dev/null || continue mount -o ro "\$dev" /run/archiso 2>/dev/null || continue if [ -d /run/archiso/archipelago ]; then log_end_msg 0 echo "Found Archipelago media on \$dev" exit 0 fi umount /run/archiso 2>/dev/null || true done log_end_msg 1 echo "Archipelago boot media not found (will retry from userspace)" INITSCRIPT chmod +x /installer/etc/initramfs-tools/scripts/local-bottom/archipelago-mount # Strip docs and man pages from installer rm -rf /installer/usr/share/man/* /installer/usr/share/doc/* rm -rf /installer/var/lib/apt/lists/* /installer/var/cache/apt/* # Extract kernel KVER=$(ls /installer/lib/modules/ | sort -V | tail -1) echo " [container] Kernel version: $KVER" cp /installer/boot/vmlinuz-$KVER /output/vmlinuz # Mount virtual filesystems for proper initramfs generation mount --bind /proc /installer/proc mount --bind /sys /installer/sys mount --bind /dev /installer/dev # Build initramfs with live-boot hooks + our custom hooks chroot /installer update-initramfs -c -k $KVER cp /installer/boot/initrd.img-$KVER /output/initrd.img # Cleanup mounts umount /installer/dev 2>/dev/null || true umount /installer/sys 2>/dev/null || true umount /installer/proc 2>/dev/null || true # Create squashfs echo " [container] Creating installer squashfs..." mksquashfs /installer /output/filesystem.squashfs -comp xz -Xbcj x86 -noappend -quiet # Build GRUB EFI image with embedded bootstrap config (grub-mkstandalone) echo " [container] Building GRUB EFI image..." cat > /tmp/grub-embed.cfg </dev/null mkfs.vfat /output/efi.img >/dev/null mmd -i /output/efi.img ::/EFI ::/EFI/BOOT mcopy -i /output/efi.img /output/BOOTX64.EFI ::/EFI/BOOT/BOOTX64.EFI # Copy ISOLINUX files for legacy BIOS boot cp /usr/lib/ISOLINUX/isolinux.bin /output/isolinux.bin cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /output/ldlinux.c32 cp /usr/lib/syslinux/modules/bios/menu.c32 /output/menu.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/vesamenu.c32 /output/vesamenu.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/libutil.c32 /output/libutil.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/libcom32.c32 /output/libcom32.c32 2>/dev/null || true cp /usr/lib/ISOLINUX/isohdpfx.bin /output/isohdpfx.bin # Generate GRUB fonts for theme echo " [container] Generating GRUB fonts..." apt-get install -y -qq fonts-dejavu-core grub-common >/dev/null 2>&1 mkdir -p /output/grub-fonts grub-mkfont -s 12 -o /output/grub-fonts/dejavu_12.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 14 -o /output/grub-fonts/dejavu_14.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 16 -o /output/grub-fonts/dejavu_16.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 24 -o /output/grub-fonts/dejavu_24.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf echo " [container] Done!" ' # Verify artifacts for artifact in vmlinuz initrd.img filesystem.squashfs BOOTX64.EFI efi.img isolinux.bin isohdpfx.bin; do if [ ! -f "$WORK_DIR/$artifact" ]; then echo " FATAL: Missing build artifact: $artifact" exit 1 fi done # Place artifacts into ISO directory structure cp "$WORK_DIR/vmlinuz" "$INSTALLER_ISO/live/vmlinuz" cp "$WORK_DIR/initrd.img" "$INSTALLER_ISO/live/initrd.img" cp "$WORK_DIR/filesystem.squashfs" "$INSTALLER_ISO/live/filesystem.squashfs" cp "$WORK_DIR/BOOTX64.EFI" "$INSTALLER_ISO/EFI/BOOT/BOOTX64.EFI" cp "$WORK_DIR/efi.img" "$INSTALLER_ISO/boot/grub/efi.img" cp "$WORK_DIR/isolinux.bin" "$INSTALLER_ISO/isolinux/isolinux.bin" cp "$WORK_DIR/ldlinux.c32" "$INSTALLER_ISO/isolinux/ldlinux.c32" cp "$WORK_DIR/menu.c32" "$INSTALLER_ISO/isolinux/menu.c32" 2>/dev/null || true cp "$WORK_DIR/vesamenu.c32" "$INSTALLER_ISO/isolinux/vesamenu.c32" 2>/dev/null || true cp "$WORK_DIR/libutil.c32" "$INSTALLER_ISO/isolinux/libutil.c32" 2>/dev/null || true cp "$WORK_DIR/libcom32.c32" "$INSTALLER_ISO/isolinux/libcom32.c32" 2>/dev/null || true # Install GRUB theme THEME_SRC="$SCRIPT_DIR/branding/grub-theme" THEME_DST="$INSTALLER_ISO/boot/grub/themes/archipelago" mkdir -p "$THEME_DST" if [ -f "$THEME_SRC/theme.txt" ]; then cp "$THEME_SRC/theme.txt" "$THEME_DST/" echo " Installed GRUB theme from branding/grub-theme/" fi # Install generated fonts if [ -d "$WORK_DIR/grub-fonts" ]; then cp "$WORK_DIR/grub-fonts/"*.pf2 "$THEME_DST/" # Also copy unicode font for GRUB to load cp "$WORK_DIR/grub-fonts/dejavu_16.pf2" "$INSTALLER_ISO/boot/grub/font.pf2" fi # Copy GRUB background image (static asset or generate if missing) GRUB_BG="$SCRIPT_DIR/branding/grub-theme/background.png" if [ -f "$GRUB_BG" ]; then cp "$GRUB_BG" "$THEME_DST/background.png" echo " Installed GRUB background" elif [ -f "$SCRIPT_DIR/branding/generate-grub-background.py" ]; then echo " Generating GRUB background..." python3 "$SCRIPT_DIR/branding/generate-grub-background.py" "$THEME_DST/background.png" 2>/dev/null || \ echo " WARNING: Could not generate GRUB background" fi echo " Installer squashfs: $(du -h "$INSTALLER_ISO/live/filesystem.squashfs" | cut -f1)" echo " Kernel: $(du -h "$INSTALLER_ISO/live/vmlinuz" | cut -f1)" echo " Initrd: $(du -h "$INSTALLER_ISO/live/initrd.img" | cut -f1)" echo " Step 2 complete (custom minimal base, no Debian Live)" # ============================================================================= # STEP 3: Add Archipelago components # ============================================================================= echo "" echo "📦 Step 3: Adding Archipelago components..." ARCH_DIR="$INSTALLER_ISO/archipelago" mkdir -p "$ARCH_DIR" mkdir -p "$ARCH_DIR/bin" mkdir -p "$ARCH_DIR/scripts" # Embed netavark + aardvark-dns for container DNS (podman CNI lacks DNS) if [ -f /usr/lib/podman/netavark ] && [ -f /usr/lib/podman/aardvark-dns ]; then cp /usr/lib/podman/netavark "$ARCH_DIR/bin/netavark" cp /usr/lib/podman/aardvark-dns "$ARCH_DIR/bin/aardvark-dns" echo " Embedded netavark + aardvark-dns in ISO" else echo " WARNING: netavark/aardvark-dns not found — install with: apt install aardvark-dns netavark" fi # Copy the pre-built rootfs echo " Including root filesystem..." cp "$ROOTFS_TAR" "$ARCH_DIR/rootfs.tar" # Capture backend binary from live server if [ "$BUILD_FROM_SOURCE" = "1" ]; then echo " Building backend binary from source..." else echo " Capturing backend binary from live server..." fi # Try to get from live server first (unless BUILD_FROM_SOURCE=1) BACKEND_CAPTURED=0 if [ "$BUILD_FROM_SOURCE" != "1" ]; then # Direct copy from ARCHIPELAGO_BIN env, local install, or remote BIN="${ARCHIPELAGO_BIN:-/usr/local/bin/archipelago}" if [ -f "$BIN" ]; then cp "$BIN" "$ARCH_DIR/bin/archipelago" chmod +x "$ARCH_DIR/bin/archipelago" echo " ✅ Backend captured from local system ($(du -h "$ARCH_DIR/bin/archipelago" | cut -f1))" BACKEND_CAPTURED=1 fi # Remote copy via SCP if local failed if [ "$BACKEND_CAPTURED" = "0" ] && [ "$DEV_SERVER" != "localhost" ] && [ "$DEV_SERVER" != "127.0.0.1" ]; then if scp "$DEV_SERVER:/usr/local/bin/archipelago" "$ARCH_DIR/bin/archipelago" 2>/dev/null; then chmod +x "$ARCH_DIR/bin/archipelago" echo " ✅ Backend captured from remote server ($(du -h "$ARCH_DIR/bin/archipelago" | cut -f1))" BACKEND_CAPTURED=1 fi fi fi if [ "$BACKEND_CAPTURED" = "0" ]; then if [ "$BUILD_FROM_SOURCE" != "1" ]; then echo " ⚠️ Could not capture from live server, building from source..." fi BACKEND_DOCKERFILE="$WORK_DIR/Dockerfile.backend" cat > "$BACKEND_DOCKERFILE" <<'BACKENDFILE' FROM rust:1.93-bookworm as builder WORKDIR /build COPY core ./core RUN cd core && cargo build --release --bin archipelago BACKENDFILE if $CONTAINER_CMD build --platform $CONTAINER_PLATFORM -t archipelago-backend -f "$BACKEND_DOCKERFILE" "$SCRIPT_DIR/.." 2>&1 | tail -20; then echo " Extracting backend binary..." BACKEND_CONTAINER=$($CONTAINER_CMD create --platform $CONTAINER_PLATFORM archipelago-backend) $CONTAINER_CMD cp "$BACKEND_CONTAINER:/build/core/target/release/archipelago" "$ARCH_DIR/bin/" && \ echo " ✅ Backend binary built ($(du -h "$ARCH_DIR/bin/archipelago" | cut -f1))" $CONTAINER_CMD rm "$BACKEND_CONTAINER" else echo " ❌ Backend build failed and server capture failed" exit 1 fi fi # Extract NostrVPN binary from container image (native system service, not a container app) echo " Extracting NostrVPN binary..." NVPN_IMAGE="$($CONTAINER_CMD images -q 80.71.235.15:3000/archipelago/nostr-vpn:v0.3.7 2>/dev/null)" if [ -z "$NVPN_IMAGE" ]; then $CONTAINER_CMD pull 80.71.235.15:3000/archipelago/nostr-vpn:v0.3.7 2>/dev/null || true fi NVPN_CONTAINER=$($CONTAINER_CMD create 80.71.235.15:3000/archipelago/nostr-vpn:v0.3.7 2>/dev/null) || true if [ -n "$NVPN_CONTAINER" ]; then $CONTAINER_CMD cp "$NVPN_CONTAINER:/usr/local/bin/nvpn" "$ARCH_DIR/bin/nvpn" 2>/dev/null && \ chmod +x "$ARCH_DIR/bin/nvpn" && \ echo " ✅ NostrVPN binary extracted ($(du -h "$ARCH_DIR/bin/nvpn" | cut -f1))" $CONTAINER_CMD rm "$NVPN_CONTAINER" 2>/dev/null || true else echo " ⚠ NostrVPN image not available — nvpn binary will be missing" fi # Extract nostr-rs-relay binary from container image (native system service for VPN signaling) echo " Extracting nostr-rs-relay binary..." RELAY_IMAGE="$($CONTAINER_CMD images -q 80.71.235.15:3000/archipelago/nostr-rs-relay:0.9.0 2>/dev/null)" if [ -z "$RELAY_IMAGE" ]; then $CONTAINER_CMD pull 80.71.235.15:3000/archipelago/nostr-rs-relay:0.9.0 2>/dev/null || true fi RELAY_CONTAINER=$($CONTAINER_CMD create 80.71.235.15:3000/archipelago/nostr-rs-relay:0.9.0 2>/dev/null) || true if [ -n "$RELAY_CONTAINER" ]; then $CONTAINER_CMD cp "$RELAY_CONTAINER:/usr/local/bin/nostr-rs-relay" "$ARCH_DIR/bin/nostr-rs-relay" 2>/dev/null && \ chmod +x "$ARCH_DIR/bin/nostr-rs-relay" && \ echo " ✅ nostr-rs-relay binary extracted ($(du -h "$ARCH_DIR/bin/nostr-rs-relay" | cut -f1))" $CONTAINER_CMD rm "$RELAY_CONTAINER" 2>/dev/null || true else echo " ⚠ nostr-rs-relay image not available — relay binary will be missing" fi # Copy WireGuard helper script if [ -f "$WORK_DIR/archipelago-wg" ]; then cp "$WORK_DIR/archipelago-wg" "$ARCH_DIR/bin/archipelago-wg" chmod +x "$ARCH_DIR/bin/archipelago-wg" echo " ✅ WireGuard helper script included" fi # Copy NostrVPN UI dashboard for nginx serving if [ -d "$SCRIPT_DIR/../docker/nostr-vpn-ui" ]; then mkdir -p "$ARCH_DIR/web-ui/nostr-vpn" cp "$SCRIPT_DIR/../docker/nostr-vpn-ui/index.html" "$ARCH_DIR/web-ui/nostr-vpn/" echo " ✅ NostrVPN UI dashboard included" fi # Capture web UI from live server if [ "$BUILD_FROM_SOURCE" = "1" ]; then echo " Building web UI from source..." else echo " Capturing web UI from live server..." fi mkdir -p "$ARCH_DIR/web-ui" # Try to get from live server first (unless BUILD_FROM_SOURCE=1) WEBUI_CAPTURED=0 if [ "$BUILD_FROM_SOURCE" != "1" ]; then # Direct copy from local filesystem (when running on target with sudo) if [ -d "/opt/archipelago/web-ui" ] && [ "$(ls -A /opt/archipelago/web-ui 2>/dev/null)" ]; then cp -r /opt/archipelago/web-ui/* "$ARCH_DIR/web-ui/" echo " ✅ Web UI captured from local system ($(du -sh "$ARCH_DIR/web-ui" | cut -f1))" WEBUI_CAPTURED=1 fi # Remote copy via rsync if local failed if [ "$WEBUI_CAPTURED" = "0" ] && [ "$DEV_SERVER" != "localhost" ] && [ "$DEV_SERVER" != "127.0.0.1" ]; then if rsync -az "$DEV_SERVER:/opt/archipelago/web-ui/" "$ARCH_DIR/web-ui/" 2>/dev/null && [ "$(ls -A "$ARCH_DIR/web-ui")" ]; then echo " ✅ Web UI captured from remote server ($(du -sh "$ARCH_DIR/web-ui" | cut -f1))" WEBUI_CAPTURED=1 fi fi fi if [ "$WEBUI_CAPTURED" = "0" ]; then if [ "$BUILD_FROM_SOURCE" != "1" ]; then echo " ⚠️ Could not capture from live server, building from source..." fi cd "$SCRIPT_DIR/../neode-ui" if npm run build 2>&1 | tail -5; then if [ -d "$SCRIPT_DIR/../web/dist/neode-ui" ]; then echo " Including web UI from web/dist/neode-ui..." cp -r "$SCRIPT_DIR/../web/dist/neode-ui/"* "$ARCH_DIR/web-ui/" echo " ✅ Web UI built ($(du -sh "$ARCH_DIR/web-ui" | cut -f1))" fi else echo " ⚠️ Web UI build failed" # Try to use existing build if [ -d "$SCRIPT_DIR/../web/dist/neode-ui" ]; then echo " Using existing web UI build..." cp -r "$SCRIPT_DIR/../web/dist/neode-ui/"* "$ARCH_DIR/web-ui/" elif [ -d "$SCRIPT_DIR/../neode-ui/dist" ]; then echo " Using neode-ui/dist..." cp -r "$SCRIPT_DIR/../neode-ui/dist/"* "$ARCH_DIR/web-ui/" else echo " ❌ No web UI available" exit 1 fi fi cd "$SCRIPT_DIR" fi # Include AIUI web app (Claude chat interface) AIUI_INCLUDED=0 # Search multiple locations for a pre-built AIUI app for AIUI_DIR in \ "$SCRIPT_DIR/../../AIUI/packages/app/dist" \ "$HOME/AIUI/packages/app/dist" \ "/home/archipelago/AIUI/packages/app/dist" \ "/opt/archipelago/web-ui/aiui" \ "/home/archipelago/archy/AIUI/packages/app/dist"; do if [ -d "$AIUI_DIR" ] && [ -f "$AIUI_DIR/index.html" ]; then echo " Including AIUI from $AIUI_DIR..." mkdir -p "$ARCH_DIR/web-ui/aiui" # Use rsync to handle same-file (CI workspace == /opt/archipelago) gracefully if command -v rsync >/dev/null 2>&1; then rsync -a "$AIUI_DIR/" "$ARCH_DIR/web-ui/aiui/" else cp -r "$AIUI_DIR/"* "$ARCH_DIR/web-ui/aiui/" 2>/dev/null || true fi echo " ✅ AIUI included ($(du -sh "$ARCH_DIR/web-ui/aiui" | cut -f1))" AIUI_INCLUDED=1 break fi done if [ "$AIUI_INCLUDED" = "0" ]; then echo " ⚠️ AIUI not found — build it first:" echo " cd ~/AIUI/packages/app && VITE_BASE_PATH=/aiui/ npx vite build" echo " Searched: ~/AIUI, /home/archipelago/AIUI, /opt/archipelago/web-ui/aiui" fi # Copy app manifests if [ -d "$SCRIPT_DIR/../apps" ]; then echo " Including app manifests..." cp -r "$SCRIPT_DIR/../apps" "$ARCH_DIR/" fi # Copy Plymouth theme files for installation on target PLYMOUTH_SRC="$SCRIPT_DIR/branding/plymouth-theme" if [ -d "$PLYMOUTH_SRC" ]; then mkdir -p "$ARCH_DIR/plymouth-theme" cp "$PLYMOUTH_SRC/"* "$ARCH_DIR/plymouth-theme/" echo " Included Plymouth theme" fi # ============================================================================= # STEP 3b: Bundle container images for offline installation # ============================================================================= echo "" if [ "$UNBUNDLED" = "1" ]; then echo "📦 Step 3b: Bundling core containers only (UNBUNDLED mode)" echo " Optional apps will be downloaded on-demand from the Marketplace after install." IMAGES_DIR="$ARCH_DIR/container-images" mkdir -p "$IMAGES_DIR" # FileBrowser is a core dependency (powers the Cloud file manager) — always bundle it CORE_IMAGE="${FILEBROWSER_IMAGE}" CORE_FILE="filebrowser.tar" if [ -f "$IMAGES_DIR/$CORE_FILE" ]; then echo " ✅ Using cached: $CORE_FILE" else echo " Pulling $CORE_IMAGE ($CONTAINER_PLATFORM)..." if $CONTAINER_CMD pull --platform $CONTAINER_PLATFORM "$CORE_IMAGE"; then $CONTAINER_CMD save "$CORE_IMAGE" -o "$IMAGES_DIR/$CORE_FILE" 2>/dev/null && \ echo " ✅ Saved core: $CORE_FILE ($(du -h "$IMAGES_DIR/$CORE_FILE" | cut -f1))" || \ echo " ⚠️ Failed to save $CORE_IMAGE" else echo " ⚠️ Failed to pull $CORE_IMAGE — Cloud will not work until installed" fi fi else echo "📦 Step 3b: Bundling container images for offline use..." IMAGES_DIR="$ARCH_DIR/container-images" mkdir -p "$IMAGES_DIR" # When DEV_SERVER is set (and not localhost), try to capture images from live server # so the ISO includes the same set as the dev server (including custom UIs: bitcoin-ui, lnd-ui). IMAGES_CAPTURED_FROM_SERVER=0 if [ -n "$DEV_SERVER" ] && [ "$DEV_SERVER" != "localhost" ] && [ "$DEV_SERVER" != "127.0.0.1" ]; then echo " Capturing container images from live server ($DEV_SERVER)..." # Patterns match against `podman images` repository names (not container names) CAPTURE_PATTERNS="bitcoin-ui bitcoinknots lnd lnd-ui electrs-ui filebrowser mempool backend frontend electrs tailscale homeassistant home-assistant btcpayserver nbxplorer postgres alpine-tor nostr-rs-relay strfry fedimintd gatewayd dwn-server vaultwarden searxng mariadb valkey nginx-alpine portainer nginx-proxy-manager adguard" REMOTE_TMP="/tmp/archipelago-image-capture-$$" SAVED_LIST=$(ssh "$DEV_SERVER" "mkdir -p $REMOTE_TMP && for p in $CAPTURE_PATTERNS; do img=\$(podman images --format '{{.Repository}}:{{.Tag}}' 2>/dev/null | grep -i \"\$p\" | head -1); [ -n \"\$img\" ] && podman save -o \"$REMOTE_TMP/\$p.tar\" \"\$img\" 2>/dev/null && echo \"\$p\"; done" 2>/dev/null) || true for p in $SAVED_LIST; do if [ -n "$p" ] && scp "$DEV_SERVER:$REMOTE_TMP/$p.tar" "$IMAGES_DIR/$p.tar" 2>/dev/null; then echo " ✅ Captured from server: $p.tar" IMAGES_CAPTURED_FROM_SERVER=1 fi done ssh "$DEV_SERVER" "rm -rf $REMOTE_TMP" 2>/dev/null || true if [ "$IMAGES_CAPTURED_FROM_SERVER" = "0" ]; then echo " ⚠️ No images captured from server, will use registry pull fallback" fi fi # Define images to bundle for fallback (when not from server or missing). Includes filebrowser. # bitcoin-ui and lnd-ui are custom and normally captured from server or built separately. # Alpha: core Bitcoin/Lightning stack + essential apps. Others pulled on-demand from Marketplace. CONTAINER_IMAGES=" ${BITCOIN_KNOTS_IMAGE} bitcoin-knots.tar ${LND_IMAGE} lnd.tar ${HOMEASSISTANT_IMAGE} homeassistant.tar ${BTCPAY_IMAGE} btcpayserver.tar ${NBXPLORER_IMAGE} nbxplorer.tar ${POSTGRES_IMAGE} postgres-btcpay.tar ${MEMPOOL_BACKEND_IMAGE} mempool-backend.tar ${MEMPOOL_WEB_IMAGE} mempool-frontend.tar ${ELECTRUMX_IMAGE} electrumx.tar ${MARIADB_IMAGE} mariadb-mempool.tar ${FEDIMINT_IMAGE} fedimint.tar ${FEDIMINT_GATEWAY_IMAGE} fedimint-gateway.tar ${FILEBROWSER_IMAGE} filebrowser.tar ${ALPINE_TOR_IMAGE} alpine-tor.tar ${NGINX_ALPINE_IMAGE} nginx-alpine.tar ${DWN_SERVER_IMAGE} dwn-server.tar ${GRAFANA_IMAGE} grafana.tar ${UPTIME_KUMA_IMAGE} uptime-kuma.tar ${VAULTWARDEN_IMAGE} vaultwarden.tar ${SEARXNG_IMAGE} searxng.tar ${PORTAINER_IMAGE} portainer.tar ${TAILSCALE_IMAGE} tailscale.tar ${JELLYFIN_IMAGE} jellyfin.tar ${PHOTOPRISM_IMAGE} photoprism.tar ${NEXTCLOUD_IMAGE} nextcloud.tar ${NPM_IMAGE} nginx-proxy-manager.tar ${ONLYOFFICE_IMAGE} onlyoffice.tar ${ADGUARDHOME_IMAGE} adguardhome.tar " # Pull and save each image (force target arch) only if not already present echo "$CONTAINER_IMAGES" | while read -r image filename; do [ -z "$image" ] && continue tarpath="$IMAGES_DIR/$filename" if [ -f "$tarpath" ]; then echo " ✅ Using cached: $filename" else echo " Pulling $image ($CONTAINER_PLATFORM)..." if $CONTAINER_CMD pull --platform $CONTAINER_PLATFORM "$image"; then echo " Saving $filename..." if $CONTAINER_CMD save "$image" -o "$tarpath" 2>/dev/null; then echo " ✅ Saved: $(du -h "$tarpath" | cut -f1)" else echo " ⚠️ Failed to save $image (zstd/format issue) - skipping" rm -f "$tarpath" fi else echo " ⚠️ Failed to pull $image - skipping" fi fi done fi # end UNBUNDLED check # Create first-boot service to load images into Podman echo " Creating first-boot image loader service..." cat > "$WORK_DIR/archipelago-load-images.service" <<'LOADSERVICE' [Unit] Description=Load Archipelago Container Images After=network.target podman.service ConditionPathExists=/opt/archipelago/container-images ConditionPathExists=!/var/lib/archipelago/.images-loaded [Service] Type=oneshot ExecStart=/opt/archipelago/scripts/load-container-images.sh ExecStartPost=/usr/bin/touch /var/lib/archipelago/.images-loaded RemainAfterExit=yes [Install] WantedBy=multi-user.target LOADSERVICE cat > "$WORK_DIR/load-container-images.sh" <<'LOADSCRIPT' #!/bin/bash # Load pre-bundled container images into Podman IMAGES_DIR="/opt/archipelago/container-images" LOG_FILE="/var/log/archipelago-images.log" echo "$(date): Starting container image load" >> "$LOG_FILE" if [ ! -d "$IMAGES_DIR" ]; then echo "$(date): No images directory found" >> "$LOG_FILE" exit 0 fi for tarfile in "$IMAGES_DIR"/*.tar; do if [ -f "$tarfile" ]; then echo "$(date): Loading $(basename "$tarfile")..." >> "$LOG_FILE" podman load -i "$tarfile" >> "$LOG_FILE" 2>&1 && \ echo "$(date): Successfully loaded $(basename "$tarfile")" >> "$LOG_FILE" || \ echo "$(date): Failed to load $(basename "$tarfile")" >> "$LOG_FILE" fi done # Ensure archy-net exists for mempool stack (db, api, frontend) podman network create archy-net 2>/dev/null || true echo "$(date): Container image load complete" >> "$LOG_FILE" echo "$(date): Available images:" >> "$LOG_FILE" podman images >> "$LOG_FILE" 2>&1 LOADSCRIPT chmod +x "$WORK_DIR/load-container-images.sh" # Copy scripts to ISO mkdir -p "$ARCH_DIR/scripts" cp "$WORK_DIR/load-container-images.sh" "$ARCH_DIR/scripts/" cp "$WORK_DIR/archipelago-load-images.service" "$ARCH_DIR/scripts/" # Tor setup: copy torrc and create first-boot setup script mkdir -p "$ARCH_DIR/scripts/tor" if [ -f "$SCRIPT_DIR/../scripts/tor/torrc.template" ]; then cp "$SCRIPT_DIR/../scripts/tor/torrc.template" "$ARCH_DIR/scripts/tor/torrc" fi echo " Creating first-boot Tor setup service..." cat > "$WORK_DIR/archipelago-setup-tor.service" <<'TORSERVICE' [Unit] Description=Setup and start Archipelago Tor hidden services After=archipelago-load-images.service network.target podman.service ConditionPathExists=/opt/archipelago/scripts/setup-tor.sh [Service] Type=oneshot ExecStart=/opt/archipelago/scripts/setup-tor.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target TORSERVICE cat > "$WORK_DIR/setup-tor.sh" <<'TORSCRIPT' #!/bin/bash # Setup and start Tor hidden services (autoinstaller first-boot) # Prefers system Tor (apt package) over container ARCHY_TOR_DIR="/var/lib/archipelago/tor" TOR_CONFIG_DIR="/var/lib/archipelago/tor-config" TOR_DIR="/var/lib/tor" LOG="/var/log/archipelago-tor.log" mkdir -p "$ARCHY_TOR_DIR" "$TOR_CONFIG_DIR" # Write services.json for the backend to read cat > "$ARCHY_TOR_DIR/services.json" </dev/null || true # Generate torrc — use /var/lib/tor/ for hidden services (AppArmor-safe) cat > /etc/tor/torrc <