From c96c595c789386a2b7c8832ff7f8d6be11038db5 Mon Sep 17 00:00:00 2001 From: "Aaron D. Lee" Date: Sat, 3 Jan 2026 20:22:55 -0500 Subject: [PATCH] Add robust jpegio ARM64 patching system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create rpi/patches/ directory with multi-strategy patching - Patch tries: patch file → sed → Python regex → already-patched detection - Fix jpegio patch to handle multiple -m64 occurrences - Update docs to use wget instead of curl|bash (stdin conflict with read) - Update SSH examples to use admin@stegasoo.local 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- rpi/BUILD_IMAGE.md | 9 ++- rpi/README.md | 21 +++--- rpi/patches/README.md | 57 ++++++++++++++++ rpi/patches/jpegio/apply-patch.sh | 105 ++++++++++++++++++++++++++++++ rpi/patches/jpegio/arm64.patch | 17 +++++ rpi/setup.sh | 17 +++-- 6 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 rpi/patches/README.md create mode 100755 rpi/patches/jpegio/apply-patch.sh create mode 100644 rpi/patches/jpegio/arm64.patch diff --git a/rpi/BUILD_IMAGE.md b/rpi/BUILD_IMAGE.md index d5887f2..9c77d7c 100644 --- a/rpi/BUILD_IMAGE.md +++ b/rpi/BUILD_IMAGE.md @@ -16,14 +16,17 @@ Use rpi-imager with these settings: ```bash # Wait for Pi to boot (~60 seconds), then: -ssh pi@stegasoo.local +ssh admin@stegasoo.local # or use IP from router DHCP list ``` ## Step 3: Run Setup Script ```bash -curl -sSL https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh | bash +# Download and run (avoid curl|bash stdin issues) +wget -O setup.sh https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh +chmod +x setup.sh +./setup.sh ``` This takes ~15-20 minutes and installs: @@ -102,7 +105,7 @@ zstdcat stegasoo-rpi-*.img.zst | sudo dd of=/dev/sdX bs=4M status=progress ```bash # On Pi: -curl -sSL https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh | bash +wget -O setup.sh https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh && chmod +x setup.sh && ./setup.sh sudo systemctl start stegasoo curl -k https://localhost:5000 sudo ~/stegasoo/rpi/sanitize-for-image.sh diff --git a/rpi/README.md b/rpi/README.md index 83f68c1..86ae036 100644 --- a/rpi/README.md +++ b/rpi/README.md @@ -4,17 +4,20 @@ Scripts and resources for deploying Stegasoo on Raspberry Pi. ## Quick Install -On a fresh Raspberry Pi OS (64-bit) installation: +On a fresh Raspberry Pi OS Lite (64-bit) installation: ```bash -curl -sSL https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh | bash +# Download and run (recommended) +wget -O setup.sh https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh +chmod +x setup.sh +./setup.sh ``` -Or download and run manually: +Or clone the repo: ```bash -wget https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh -chmod +x setup.sh +git clone https://github.com/adlee-was-taken/stegasoo.git +cd stegasoo/rpi ./setup.sh ``` @@ -128,10 +131,12 @@ In advanced settings, set: ```bash # SSH into the Pi -ssh pi@stegasoo.local +ssh admin@stegasoo.local -# Run the setup script -curl -sSL https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh | bash +# Download and run setup script +wget -O setup.sh https://raw.githubusercontent.com/adlee-was-taken/stegasoo/main/rpi/setup.sh +chmod +x setup.sh +./setup.sh ``` ### 3. Test It Works diff --git a/rpi/patches/README.md b/rpi/patches/README.md new file mode 100644 index 0000000..2512a57 --- /dev/null +++ b/rpi/patches/README.md @@ -0,0 +1,57 @@ +# RPi Patches + +This directory contains patches for dependencies that need modifications to build on ARM64. + +## Structure + +``` +patches/ + / + arm64.patch # Standard unified diff patch file + apply-patch.sh # Script with fallback strategies +``` + +## How It Works + +The `apply-patch.sh` script tries multiple strategies in order: + +1. **Patch file** - Apply the `.patch` file using `patch -p1` +2. **Sed fallback** - Use sed for simple string replacements +3. **Python fallback** - Use regex for flexible pattern matching + +This layered approach handles: +- Exact matches (patch file works) +- Minor upstream changes (sed catches variations) +- Significant changes (Python regex is most flexible) +- Already patched files (detected and skipped) + +## Adding a New Patch + +1. Create a directory: `patches//` +2. Create the patch file: `git diff > arm64.patch` +3. Create `apply-patch.sh` with appropriate fallback logic +4. Update `setup.sh` to call the patch script + +## jpegio Patch + +The jpegio library includes x86-specific `-m64` compiler flags that fail on ARM64. +The patch removes these flags by replacing: + +```python +cargs.append('-m64') +``` + +with: + +```python +pass # ARM64: removed x86-specific -m64 flag +``` + +## Updating Patches + +When upstream changes break a patch: + +1. Clone the new version +2. Make the necessary modifications +3. Generate a new patch: `diff -u original modified > arm64.patch` +4. Test on a fresh Pi install diff --git a/rpi/patches/jpegio/apply-patch.sh b/rpi/patches/jpegio/apply-patch.sh new file mode 100755 index 0000000..1a4f381 --- /dev/null +++ b/rpi/patches/jpegio/apply-patch.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Apply ARM64 patch to jpegio +# This script tries multiple strategies to remove the x86-specific -m64 flag +# +# Usage: ./apply-patch.sh /path/to/jpegio +# + +set -e + +JPEGIO_DIR="${1:-.}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PATCH_FILE="$SCRIPT_DIR/arm64.patch" + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +cd "$JPEGIO_DIR" + +echo "Applying ARM64 patch to jpegio..." + +# Strategy 1: Try the standard patch file +if [ -f "$PATCH_FILE" ]; then + echo " Trying patch file..." + if patch -p1 --dry-run < "$PATCH_FILE" >/dev/null 2>&1; then + patch -p1 < "$PATCH_FILE" + echo -e " ${GREEN}✓ Patch applied successfully${NC}" + exit 0 + else + echo -e " ${YELLOW}Patch file didn't apply cleanly, trying fallback...${NC}" + fi +fi + +# Strategy 2: Sed replacement (handles any number of occurrences) +if grep -q "cargs.append('-m64')" setup.py 2>/dev/null; then + echo " Using sed fallback..." + sed -i "s/cargs.append('-m64')/pass # ARM64: removed x86-specific -m64 flag/g" setup.py + + # Verify the fix + if grep -q "cargs.append('-m64')" setup.py; then + echo -e " ${RED}✗ Sed replacement failed${NC}" + exit 1 + fi + + echo -e " ${GREEN}✓ Sed fallback successful${NC}" + exit 0 +fi + +# Strategy 3: Check if already patched +if grep -q "ARM64: removed" setup.py 2>/dev/null; then + echo -e " ${GREEN}✓ Already patched${NC}" + exit 0 +fi + +# Strategy 4: Python-based patching (most flexible) +echo " Using Python fallback..." +python3 << 'PYTHON_PATCH' +import re +import sys + +with open('setup.py', 'r') as f: + content = f.read() + +original = content + +# Pattern 1: Direct replacement +content = re.sub( + r"cargs\.append\(['\"]+-m64['\"]+\)", + "pass # ARM64: removed x86-specific -m64 flag", + content +) + +# Pattern 2: Handle variations with different quotes or spacing +content = re.sub( + r"cargs\.append\s*\(\s*['\"]+-m64['\"]+\s*\)", + "pass # ARM64: removed x86-specific -m64 flag", + content +) + +if content == original: + # Check if already patched or pattern not found + if "ARM64: removed" in content: + print("Already patched") + sys.exit(0) + else: + print("Warning: -m64 pattern not found in setup.py") + print("This may indicate jpegio's structure has changed significantly") + sys.exit(0) # Don't fail - maybe they removed it upstream + +with open('setup.py', 'w') as f: + f.write(content) + +print("Python patch applied") +PYTHON_PATCH + +if [ $? -eq 0 ]; then + echo -e " ${GREEN}✓ Python fallback successful${NC}" + exit 0 +fi + +echo -e "${RED}✗ All patching strategies failed${NC}" +echo "Please check jpegio's setup.py manually" +exit 1 diff --git a/rpi/patches/jpegio/arm64.patch b/rpi/patches/jpegio/arm64.patch new file mode 100644 index 0000000..129d4e1 --- /dev/null +++ b/rpi/patches/jpegio/arm64.patch @@ -0,0 +1,17 @@ +--- a/setup.py ++++ b/setup.py +@@ -69,12 +69,12 @@ + largs.append('-mmacosx-version-min=10.9') + + if arch == 'x64': +- cargs.append('-m64') ++ pass # ARM64: removed x86-specific -m64 flag + elif sys.platform == 'linux': + cargs.extend(['-w', '-fPIC']) + + if arch == 'x64': +- cargs.append('-m64') ++ pass # ARM64: removed x86-specific -m64 flag + dname_libjpeg = 'libjpeg' + + # end of if-else diff --git a/rpi/setup.sh b/rpi/setup.sh index 1bc8a15..4e49e1a 100755 --- a/rpi/setup.sh +++ b/rpi/setup.sh @@ -125,14 +125,23 @@ fi echo -e "${GREEN}[3/6]${NC} Building jpegio for ARM..." -# Clone and patch jpegio +# Clone jpegio JPEGIO_DIR="/tmp/jpegio-build" rm -rf "$JPEGIO_DIR" git clone "$JPEGIO_REPO" "$JPEGIO_DIR" -cd "$JPEGIO_DIR" -# Patch for ARM (remove x86-specific -m64 flag) -sed -i "s/cargs.append('-m64')/pass # ARM fix/" setup.py +# Apply ARM64 patch using robust patching system +# The patch script tries: 1) patch file, 2) sed, 3) python regex +if [ -f "$INSTALL_DIR/rpi/patches/jpegio/apply-patch.sh" ]; then + bash "$INSTALL_DIR/rpi/patches/jpegio/apply-patch.sh" "$JPEGIO_DIR" +else + # Fallback if running before stegasoo is cloned (curl install) + echo " Using inline patch fallback..." + cd "$JPEGIO_DIR" + sed -i "s/cargs.append('-m64')/pass # ARM64 fix/g" setup.py +fi + +cd "$JPEGIO_DIR" # Build jpegio pip install --upgrade pip setuptools wheel cython numpy