repack_slicer.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env bash
  2. set -e
  3. # ==============================================================================
  4. # CONFIGURATION MODULE: ADD MISSING DEBIAN PACKAGES HERE
  5. # ==============================================================================
  6. # Space-separated list of Debian packages to scrape for dynamic libraries.
  7. PACKAGES_TO_INJECT="libglu1-mesa"
  8. # ==============================================================================
  9. # Argument check
  10. TARGET_APPIMAGE="$1"
  11. if [ -z "$TARGET_APPIMAGE" ] || [ ! -f "$TARGET_APPIMAGE" ]; then
  12. echo "Error: Pass the path to the broken OrcaSlicer AppImage as the first argument."
  13. exit 1
  14. fi
  15. EXTRACT_DIR="/tmp/orcaslicer_unpack"
  16. FINAL_BIN="/bin/Orcaslicer-new"
  17. WORKSPACE_DEB="/tmp/lib_extract_workspace"
  18. echo "=== Step 1: Purging old workspaces ==="
  19. rm -rf "$EXTRACT_DIR" /tmp/appimagetool* "$WORKSPACE_DEB"
  20. echo "=== Step 2: Unpacking the raw AppImage ==="
  21. cd /tmp
  22. "$TARGET_APPIMAGE" --appimage-extract
  23. mv /tmp/squashfs-root "$EXTRACT_DIR"
  24. # Force structure targets inside their layout to cover all RPATH scenarios
  25. mkdir -p "$EXTRACT_DIR/usr/lib"
  26. mkdir -p "$EXTRACT_DIR/bin"
  27. mkdir -p "$EXTRACT_DIR/usr/bin"
  28. echo "=== Step 3: Extracting and Shotgun-Injecting Modular Libraries ==="
  29. mkdir -p "$WORKSPACE_DEB"
  30. for PKG in $PACKAGES_TO_INJECT; do
  31. echo " -> Processing package: $PKG"
  32. mkdir -p "$WORKSPACE_DEB/$PKG"
  33. cd "$WORKSPACE_DEB/$PKG"
  34. # Grab the binary package file from APT repositories
  35. apt-get download "$PKG"
  36. # Extract the internal archive filesystem cleanly
  37. dpkg-deb -x *.deb .
  38. # Rip out every compiled library inside the package and force it into every level
  39. find . -type f -name "*.so*" | while read -r SO_FILE; do
  40. SO_NAME=$(basename "$SO_FILE")
  41. echo " + Shotgun-injecting $SO_NAME into all layout paths..."
  42. # Blanket copy to completely defeat hardcoded binary RPATH limits
  43. cp "$SO_FILE" "$EXTRACT_DIR/"
  44. cp "$SO_FILE" "$EXTRACT_DIR/bin/"
  45. cp "$SO_FILE" "$EXTRACT_DIR/usr/bin/"
  46. cp "$SO_FILE" "$EXTRACT_DIR/usr/lib/"
  47. # Auto-build matching unversioned symlinks across all target paths
  48. BASE_SO=$(echo "$SO_NAME" | grep -o '^lib[^.]*\.so\.[0-9]\+') || true
  49. if [ -n "$BASE_SO" ] && [ "$BASE_SO" != "$SO_NAME" ]; then
  50. ln -sf "$SO_NAME" "$EXTRACT_DIR/$BASE_SO"
  51. ln -sf "$SO_NAME" "$EXTRACT_DIR/bin/$BASE_SO"
  52. ln -sf "$SO_NAME" "$EXTRACT_DIR/usr/bin/$BASE_SO"
  53. ln -sf "$SO_NAME" "$EXTRACT_DIR/usr/lib/$BASE_SO"
  54. fi
  55. done
  56. done
  57. echo "=== Step 4: Provisioning AppImage Builder Runtime ==="
  58. cd /tmp
  59. curl -LO https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage
  60. chmod +x appimagetool-x86_64.AppImage
  61. echo "=== Step 5: Compiling fresh container output ==="
  62. export ARCH=x86_64
  63. ./appimagetool-x86_64.AppImage "$EXTRACT_DIR" "$FINAL_BIN"
  64. chmod +x "$FINAL_BIN"
  65. echo "=== Step 6: Cleaning environment artifacts ==="
  66. rm -rf "$EXTRACT_DIR" /tmp/appimagetool-x86_64.AppImage "$WORKSPACE_DEB"
  67. echo "=== Success! Modified executable dropped to: $FINAL_BIN ==="