| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env bash
- set -e
- # ==============================================================================
- # CONFIGURATION MODULE: ADD MISSING DEBIAN PACKAGES HERE
- # ==============================================================================
- # Space-separated list of Debian packages to scrape for dynamic libraries.
- PACKAGES_TO_INJECT="libglu1-mesa"
- # ==============================================================================
- # Argument check
- TARGET_APPIMAGE="$1"
- if [ -z "$TARGET_APPIMAGE" ] || [ ! -f "$TARGET_APPIMAGE" ]; then
- echo "Error: Pass the path to the broken OrcaSlicer AppImage as the first argument."
- exit 1
- fi
- EXTRACT_DIR="/tmp/orcaslicer_unpack"
- FINAL_BIN="/bin/Orcaslicer-new"
- WORKSPACE_DEB="/tmp/lib_extract_workspace"
- echo "=== Step 1: Purging old workspaces ==="
- rm -rf "$EXTRACT_DIR" /tmp/appimagetool* "$WORKSPACE_DEB"
- echo "=== Step 2: Unpacking the raw AppImage ==="
- cd /tmp
- "$TARGET_APPIMAGE" --appimage-extract
- mv /tmp/squashfs-root "$EXTRACT_DIR"
- # Force structure targets inside their layout to cover all RPATH scenarios
- mkdir -p "$EXTRACT_DIR/usr/lib"
- mkdir -p "$EXTRACT_DIR/bin"
- mkdir -p "$EXTRACT_DIR/usr/bin"
- echo "=== Step 3: Extracting and Shotgun-Injecting Modular Libraries ==="
- mkdir -p "$WORKSPACE_DEB"
- for PKG in $PACKAGES_TO_INJECT; do
- echo " -> Processing package: $PKG"
- mkdir -p "$WORKSPACE_DEB/$PKG"
- cd "$WORKSPACE_DEB/$PKG"
-
- # Grab the binary package file from APT repositories
- apt-get download "$PKG"
-
- # Extract the internal archive filesystem cleanly
- dpkg-deb -x *.deb .
-
- # Rip out every compiled library inside the package and force it into every level
- find . -type f -name "*.so*" | while read -r SO_FILE; do
- SO_NAME=$(basename "$SO_FILE")
- echo " + Shotgun-injecting $SO_NAME into all layout paths..."
-
- # Blanket copy to completely defeat hardcoded binary RPATH limits
- cp "$SO_FILE" "$EXTRACT_DIR/"
- cp "$SO_FILE" "$EXTRACT_DIR/bin/"
- cp "$SO_FILE" "$EXTRACT_DIR/usr/bin/"
- cp "$SO_FILE" "$EXTRACT_DIR/usr/lib/"
-
- # Auto-build matching unversioned symlinks across all target paths
- BASE_SO=$(echo "$SO_NAME" | grep -o '^lib[^.]*\.so\.[0-9]\+') || true
- if [ -n "$BASE_SO" ] && [ "$BASE_SO" != "$SO_NAME" ]; then
- ln -sf "$SO_NAME" "$EXTRACT_DIR/$BASE_SO"
- ln -sf "$SO_NAME" "$EXTRACT_DIR/bin/$BASE_SO"
- ln -sf "$SO_NAME" "$EXTRACT_DIR/usr/bin/$BASE_SO"
- ln -sf "$SO_NAME" "$EXTRACT_DIR/usr/lib/$BASE_SO"
- fi
- done
- done
- echo "=== Step 4: Provisioning AppImage Builder Runtime ==="
- cd /tmp
- curl -LO https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage
- chmod +x appimagetool-x86_64.AppImage
- echo "=== Step 5: Compiling fresh container output ==="
- export ARCH=x86_64
- ./appimagetool-x86_64.AppImage "$EXTRACT_DIR" "$FINAL_BIN"
- chmod +x "$FINAL_BIN"
- echo "=== Step 6: Cleaning environment artifacts ==="
- rm -rf "$EXTRACT_DIR" /tmp/appimagetool-x86_64.AppImage "$WORKSPACE_DEB"
- echo "=== Success! Modified executable dropped to: $FINAL_BIN ==="
|