Skip to content

Latest commit

 

History

History
292 lines (204 loc) · 7.16 KB

SCRIPT-RESTORATION.md

File metadata and controls

292 lines (204 loc) · 7.16 KB

Build Script Restoration - Back to Working Version

Date: 2025-11-17 Issue: New "improved" script was not creating bootable ISOs Solution: Restored working backup + applied only critical fixes


🐛 What Went Wrong

The "Improvements" Broke ISO Building:

The new build-iso-docker.sh with all improvements had a critical flaw:

Problem Code:

IMAGE_NAME="archiso-builder"
USE_CACHED_IMAGE="yes"  # Default to yes

# ... later in docker run ...
if [ "$USE_CACHED_IMAGE" = "no" ]; then
    # Install archiso and dependencies
    pacman -S --needed --noconfirm archiso git
fi

What Happened:

  1. Script defaults to USE_CACHED_IMAGE="yes"
  2. Checks if Docker image "archiso-builder" exists
  3. Image doesn't exist (was never created)
  4. Script continues anyway with archlinux:latest
  5. But skips archiso installation because USE_CACHED_IMAGE="yes"!
  6. mkarchiso command fails because archiso is not installed
  7. ISO build fails or creates invalid ISO

Result: ISO either doesn't build or builds incorrectly without proper boot files.


✅ The Solution

Restored Working Backup + Critical Fixes Only:

We restored build-iso-docker.sh.backup (known working version) and applied ONLY the essential fixes:

Applied Fixes:

1. .zlogin Quote Escaping Fix (Line 221)

Before:

cat > airootfs/root/.zlogin << "EOFZLOGIN"

After:

cat > airootfs/root/.zlogin << 'EOFZLOGIN'  # Single quotes prevent escaping

Why: Prevents quote interpretation issues in .zlogin file.


2. File Permissions Array (Lines 254-268)

Added:

# Set proper permissions in profiledef.sh
cat >> profiledef.sh << "EOFPERMS"

# File permissions that will be set in the live environment
file_permissions=(
  ["/usr/local/bin/install-arch"]="0:0:755"
  ["/root/custom-setup/install.sh"]="0:0:755"
  ["/root/custom-setup/install-auto.sh"]="0:0:755"
  ["/root/custom-setup/post-install.sh"]="0:0:755"
  ["/root"]="0:0:750"
)
EOFPERMS

Why: Ensures install-arch command has execute permissions in the ISO.


📋 What We Kept from Backup

Working ISO Build Process:

docker run --rm --privileged \
    -v "$SCRIPT_DIR:/workspace" \
    -w /workspace \
    archlinux:latest \  # Simple, no cached image
    bash -c '

# ALWAYS install archiso (no conditionals)
pacman -Sy --noconfirm reflector
reflector --country US --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
pacman -Sy --noconfirm
pacman -S --needed --noconfirm archiso git  # ← Always installed!

# ... rest of ISO build ...
mkarchiso -v -w "$WORK_DIR/work" -o "$OUTPUT_DIR" "$ISO_DIR"
'

Key Points:

  • Uses archlinux:latest directly (no custom image)
  • ALWAYS installs archiso (no conditional logic)
  • Simple and reliable
  • Proven to work

❌ What We Removed

"Improvements" That Caused Problems:

  1. Docker Image Caching - Tried to use custom image that doesn't exist
  2. Conditional archiso Installation - Skipped installation when it shouldn't
  3. Package Caching - Added complexity
  4. Parallel Downloads - Not needed for core functionality
  5. Complex Error Handling - Made debugging harder

Lesson: Simple and working > Complex and broken


📊 Comparison

Aspect Broken "Improved" Script Restored Working Script
Docker Image Custom archiso-builder (doesn't exist) archlinux:latest (always works)
archiso Install Conditional (broken logic) Always installed
Complexity High (caching, conditionals) Low (straightforward)
Build Success ❌ Failed ✅ Works
Boot Success ❌ "Unsupported" error ✅ Should boot
Lines of Code ~400+ ~300
Dependencies Custom Docker image None

✅ Current Status

build-iso-docker.sh (Now Fixed):

Based on: build-iso-docker.sh.backup (working version)

Applied Fixes:

  1. ✅ .zlogin quote escaping (line 221)
  2. ✅ file_permissions array (lines 254-268)

NOT Applied:

  • ❌ ISO label hyphen fix (not needed - backup uses simple date format without hyphens)
  • ❌ Caching improvements (removed - caused problems)
  • ❌ Parallel downloads (removed - unnecessary complexity)

Validation: ✅ Syntax check passed


🎯 Why This Should Work

Simple Build Process:

  1. Start with clean Arch container (archlinux:latest)
  2. Always install archiso (no conditionals)
  3. Copy releng profile (standard archiso template)
  4. Add custom files (dotfiles, scripts, packages)
  5. Fix permissions (file_permissions array)
  6. Build ISO (mkarchiso)
  7. Output ISO (to iso-output/)

No complex logic, no missing dependencies, no cached images.


🔍 What to Expect

Build Process:

./build-iso-docker.sh

Output:
→ Configuring fast mirrors...
→ Updating package database...
→ Installing archiso and dependencies...  ← ALWAYS RUNS
→ Copying releng profile...
→ Adding custom setup...
→ Creating welcome message...
→ Creating install-arch command...
→ Configuring file permissions...         ← NEW (critical fix)
→ Building ISO...
✓ ISO created successfully!

Expected ISO:

  • Filename: archlinux-2025.11.17-x86_64.iso
  • Size: ~1.5-2 GB
  • Label: PARTEEK-ARCH_20251117 (no hyphens - uses simple date)
  • Bootable: ✅ Yes
  • install-arch: ✅ Should work (permissions fixed)

📝 Files Changed

Restored and Fixed:

  • build-iso-docker.sh - Restored from backup + 2 critical fixes

Kept As-Is:

  • build-iso-docker.sh.backup - Original working version (unchanged)
  • build-iso-native.sh - Native build (has fixes but different workflow)
  • build-iso-simple.sh - Simple build (unchanged)
  • All other files - Unchanged

🚀 Next Steps

Build the ISO:

cd /mnt/c/Users/bindrap/Documents/CustomOS
./build-iso-docker.sh

Expected:

  • Build completes successfully
  • ISO created in iso-output/
  • ISO boots in VirtualBox
  • install-arch command works
  • Installation proceeds normally

📖 Lessons Learned

Keep It Simple:

  1. Don't over-optimize - Working > Fast
  2. Test incrementally - One change at a time
  3. Keep backups - Saved us here!
  4. Understand dependencies - archiso must be installed
  5. Avoid conditionals - Especially for critical steps

The KISS Principle:

Keep It Simple, Stupid

A simple script that works is infinitely better than a complex script that doesn't.


✅ Verification

Script Validation:

$ bash -n build-iso-docker.sh
✓ Syntax OK

Key Sections Verified:

  • ✅ archiso always installed (no conditionals)
  • ✅ .zlogin uses single-quote heredoc
  • ✅ file_permissions array added
  • ✅ Simple date format (no hyphens)
  • ✅ Standard mkarchiso command
  • ✅ No complex caching logic

🎉 Summary

Problem: Overly complex "improved" script broke ISO building

Solution: Restored simple working backup + 2 critical fixes

Result: Clean, simple, working build script

Status: Ready to build bootable ISO


Build command: ./build-iso-docker.sh

Expected outcome: Working bootable ISO!