#!/usr/bin/env bash # # Copyright 2025, Stormux, # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this package; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # set -e help() { echo "Stormux x86_64 ISO Builder" echo echo "Usage: $0 [options]" echo echo "Options:" echo " -o Output directory (default: ./out)" echo " -w Work directory (default: ./work)" echo " -h Show this help" echo echo "This script builds a Stormux x86_64 ISO using archiso." echo "It must be run as root on an Arch Linux system." exit 0 } # Parse command line arguments output_dir="./out" work_dir="./work" while getopts "o:w:h" opt; do case "$opt" in o) output_dir="$OPTARG" ;; w) work_dir="$OPTARG" ;; h) help ;; *) help ;; esac done # Make sure this script is run as root if [ "$(whoami)" != "root" ]; then echo "Error: This script must be run as root." exit 1 fi # Capture the calling user for chown later callingUser="${SUDO_USER:-$USER}" # Check for required tools for tool in mkarchiso pacman; do if ! command -v "$tool" &> /dev/null; then echo "Error: $tool is not installed. Please install archiso package." exit 1 fi done # Get the directory where this script is located script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "Building Stormux x86_64 ISO..." echo "Profile directory: $script_dir" echo "Output directory: $output_dir" echo "Work directory: $work_dir" echo # Clean up work directory from previous builds to ensure clean build environment if [ -d "$work_dir" ]; then echo "Cleaning up previous build artifacts..." rm -rf "$work_dir" fi # Note: Shared configuration files from pi4/files should already be in airootfs/ # The airootfs/ directory is maintained as part of the x86_64 profile # and should not be dynamically copied during build to avoid conflicts with packages echo "Using existing airootfs configuration files..." # Add Stormux repository key to build host's keyring echo "Setting up Stormux repository key on build host..." key_file="$script_dir/stormux_repo.pub" if [ ! -f "$key_file" ]; then echo "Error: Stormux repository key not found at $key_file" echo "Please ensure stormux_repo.pub exists in the x86_64 directory" exit 1 fi # Check if key is already in keyring if ! pacman-key --list-keys 52ADA49000F1FF0456F8AEEFB4CDE1CD56EF8E82 &>/dev/null; then echo "Adding Stormux repository key to build host keyring..." pacman-key --add "$key_file" pacman-key --lsign-key 52ADA49000F1FF0456F8AEEFB4CDE1CD56EF8E82 echo "Key added successfully" else echo "Stormux repository key already in keyring" fi # Build the ISO mkarchiso -v -w "$work_dir" -o "$output_dir" "$script_dir" # Rename ISO to stormux-x86_64-YYYY-MM-DD.iso dateStamp="$(date --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%d)" pushd "$output_dir" > /dev/null shopt -s nullglob isoFiles=( *.iso ) shopt -u nullglob if [[ ${#isoFiles[@]} -eq 1 && -f "${isoFiles[0]}" ]]; then desiredIso="stormux-x86_64-${dateStamp}.iso" if [[ "${isoFiles[0]}" != "$desiredIso" ]]; then if [[ -e "$desiredIso" ]]; then echo "Warning: $desiredIso already exists; skipping rename." else mv "${isoFiles[0]}" "$desiredIso" echo "Renamed ISO to: $desiredIso" fi fi else echo "Warning: expected one ISO in output, found ${#isoFiles[@]}; skipping rename." fi popd > /dev/null # Generate sha1sum for the ISO echo echo "Generating sha1sum..." pushd "$output_dir" > /dev/null for isoFile in *.iso; do if [ -f "$isoFile" ]; then sha1sum "$isoFile" > "${isoFile}.sha1sum" echo "Created sha1sum: ${isoFile}.sha1sum" fi done popd > /dev/null # Change ownership of output directory to calling user if [ -n "$callingUser" ] && [ "$callingUser" != "root" ]; then echo "Changing ownership of $output_dir to $callingUser..." chown -R "$callingUser:$callingUser" "$output_dir" fi echo echo "Build complete!" echo "ISO file is in: $output_dir"