archy/image-recipe/scripts/install-archipelago.sh
2026-01-24 22:59:20 +00:00

94 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# Install Archipelago components into Alpine image
# This script is called after the base image is built
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
OUTPUT_DIR="${1:-$SCRIPT_DIR/../results}"
BUILD_DIR="$SCRIPT_DIR/../build"
APK_DIR="$SCRIPT_DIR/../apks"
echo "🔧 Installing Archipelago into image..."
echo " Output: $OUTPUT_DIR"
echo ""
# Find the built image (ISO or extracted)
if [ -f "$OUTPUT_DIR"/*.iso ]; then
ISO_FILE=$(ls "$OUTPUT_DIR"/*.iso | head -1)
echo "📦 Found ISO: $ISO_FILE"
echo " (Archipelago will be installed when ISO is booted)"
# For ISO, we'd need to extract, modify, and rebuild
# This is complex, so we'll do it in the init script instead
elif [ -d "$OUTPUT_DIR" ]; then
# Extracted image directory
IMAGE_ROOT="$OUTPUT_DIR"
echo "📁 Installing into extracted image: $IMAGE_ROOT"
# Install backend APK
if [ -f "$APK_DIR"/*.apk ]; then
APK_FILE=$(ls "$APK_DIR"/*.apk | head -1)
echo "📦 Installing backend APK: $APK_FILE"
# In a real chroot, we'd do: apk add --allow-untrusted "$APK_FILE"
# For now, we'll extract and copy manually
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
tar -xzf "$APK_FILE"
# Copy files to image
if [ -d "$IMAGE_ROOT" ]; then
cp -r usr/* "$IMAGE_ROOT/usr/" 2>/dev/null || true
cp -r etc/* "$IMAGE_ROOT/etc/" 2>/dev/null || true
fi
rm -rf "$TEMP_DIR"
fi
# Install frontend
if [ -d "$BUILD_DIR/frontend" ]; then
echo "🎨 Installing frontend..."
mkdir -p "$IMAGE_ROOT/usr/share/archipelago/web"
cp -r "$BUILD_DIR/frontend/"* "$IMAGE_ROOT/usr/share/archipelago/web/"
fi
else
echo "⚠️ No image found to install into"
echo " Archipelago will be installed on first boot"
fi
# Create first boot script
cat > "$SCRIPT_DIR/../alpine-profile/overlay/etc/local.d/archipelago-install.start" <<'EOF'
#!/bin/sh
# First boot installation script for Archipelago
# Install backend APK if available
if [ -f /tmp/archipelago-backend.apk ]; then
apk add --allow-untrusted /tmp/archipelago-backend.apk
rm /tmp/archipelago-backend.apk
fi
# Enable services
rc-update add archipelago default || true
systemctl enable archipelago || true
# Create archipelago user if needed
if ! id archipelago >/dev/null 2>&1; then
adduser -D -s /bin/bash archipelago
echo "archipelago ALL=(ALL) NOPASSWD: /usr/bin/podman" >> /etc/sudoers
fi
# Setup Podman for archipelago user
mkdir -p /home/archipelago/.config/containers
chown -R archipelago:archipelago /home/archipelago
# Create data directories
mkdir -p /var/lib/archipelago/{apps,secrets,logs,backups}
chown -R archipelago:archipelago /var/lib/archipelago
# Start services
rc-service archipelago start || systemctl start archipelago || true
EOF
chmod +x "$SCRIPT_DIR/../alpine-profile/overlay/etc/local.d/archipelago-install.start"
echo "✅ Archipelago installation configured"