#!/bin/bash # # download-packages.sh — Download all .deb packages needed for offline PXE server setup # # Run this on a machine with internet access running Ubuntu 24.04 (Noble). # It downloads every .deb needed by the Ansible playbook into a local directory, # which then gets bundled onto the installer USB. # # Usage: # ./download-packages.sh [output_directory] # # Default output: ./offline-packages/ set -euo pipefail OUT_DIR="${1:-./offline-packages}" mkdir -p "$OUT_DIR" # Packages installed by the Ansible playbook (pxe_server_setup.yml) PLAYBOOK_PACKAGES=( ansible dnsmasq apache2 samba unzip ufw cron ) # Packages installed during autoinstall late-commands (NetworkManager, WiFi, etc.) # These are already in your ubuntu_playbook/*.deb files, but we can refresh them here too. AUTOINSTALL_PACKAGES=( network-manager wpasupplicant wireless-tools linux-firmware firmware-sof-signed ) ALL_PACKAGES=("${PLAYBOOK_PACKAGES[@]}" "${AUTOINSTALL_PACKAGES[@]}") echo "============================================" echo "Offline Package Downloader" echo "============================================" echo "Output directory: $OUT_DIR" echo "" echo "Packages to resolve:" printf ' - %s\n' "${ALL_PACKAGES[@]}" echo "" # Update package cache echo "[1/3] Updating package cache..." sudo apt-get update -qq # Simulate install to find all dependencies echo "[2/3] Resolving dependencies..." DEPS=$(apt-get install --simulate "${ALL_PACKAGES[@]}" 2>&1 \ | grep "^Inst " \ | awk '{print $2}' \ | sort -u) DEP_COUNT=$(echo "$DEPS" | wc -l) echo " Found $DEP_COUNT packages (including dependencies)" # Download all packages echo "[3/3] Downloading packages to $OUT_DIR..." cd "$OUT_DIR" apt-get download $DEPS 2>&1 | tail -5 DEB_COUNT=$(ls -1 *.deb 2>/dev/null | wc -l) TOTAL_SIZE=$(du -sh . | cut -f1) echo "" echo "============================================" echo "Download complete!" echo "============================================" echo " Packages: $DEB_COUNT" echo " Total size: $TOTAL_SIZE" echo " Location: $OUT_DIR/" echo "" echo "Next: copy these into your ubuntu_playbook/ directory" echo " cp $OUT_DIR/*.deb /path/to/ubuntu_playbook/" echo ""