appimage 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env bash
  2. # Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  3. # SPDX-License-Identifier: Apache-2.0
  4. # SPDX-License-Identifier: MIT
  5. set -euxo pipefail
  6. export ARCH={{arch}}
  7. APPIMAGE_BUNDLE_XDG_OPEN=${APPIMAGE_BUNDLE_XDG_OPEN-0}
  8. APPIMAGE_BUNDLE_XDG_MIME=${APPIMAGE_BUNDLE_XDG_MIME-0}
  9. APPIMAGE_BUNDLE_GSTREAMER=${APPIMAGE_BUNDLE_GSTREAMER-0}
  10. TAURI_TRAY_LIBRARY_PATH=${TAURI_TRAY_LIBRARY_PATH-0}
  11. if [ "$ARCH" == "i686" ]; then
  12. linuxdeploy_arch="i386"
  13. else
  14. linuxdeploy_arch="$ARCH"
  15. fi
  16. mkdir -p "{{crate_name}}.AppDir"
  17. cp -r ../appimage_deb/data/usr "{{crate_name}}.AppDir"
  18. cd "{{crate_name}}.AppDir"
  19. mkdir -p "usr/bin"
  20. mkdir -p "usr/lib"
  21. if [[ "$APPIMAGE_BUNDLE_XDG_OPEN" != "0" ]] && [[ -f "/usr/bin/xdg-open" ]]; then
  22. echo "Copying /usr/bin/xdg-open"
  23. cp /usr/bin/xdg-open usr/bin
  24. fi
  25. if [[ "$APPIMAGE_BUNDLE_XDG_MIME" != "0" ]] && [[ -f "/usr/bin/xdg-mime" ]]; then
  26. echo "Copying /usr/bin/xdg-mime"
  27. cp /usr/bin/xdg-mime usr/bin
  28. fi
  29. if [[ "$TAURI_TRAY_LIBRARY_PATH" != "0" ]]; then
  30. echo "Copying appindicator library ${TAURI_TRAY_LIBRARY_PATH}"
  31. cp ${TAURI_TRAY_LIBRARY_PATH} usr/lib
  32. # It looks like we're practicing good hygiene by adding the ABI version.
  33. # But for compatibility we'll symlink this file to what we did before.
  34. # Specifically this prevents breaking libappindicator-sys v0.7.1 and v0.7.2.
  35. if [[ "$TAURI_TRAY_LIBRARY_PATH" == *.so.1 ]]; then
  36. readonly soname=$(basename "$TAURI_TRAY_LIBRARY_PATH")
  37. readonly old_name=$(basename "$TAURI_TRAY_LIBRARY_PATH" .1)
  38. echo "Adding compatibility symlink ${old_name} -> ${soname}"
  39. ln -s ${soname} usr/lib/${old_name}
  40. fi
  41. fi
  42. # Copy WebKit files. Follow symlinks in case `/usr/lib64` is a symlink to `/usr/lib`
  43. find -L /usr/lib* -name WebKitNetworkProcess -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true
  44. find -L /usr/lib* -name WebKitWebProcess -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true
  45. find -L /usr/lib* -name libwebkit2gtkinjectedbundle.so -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true
  46. ( cd "{{tauri_tools_path}}" && ( wget -q -4 -N https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH} || wget -q -4 -N https://github.com/AppImage/AppImageKit/releases/download/12/AppRun-${ARCH} ) )
  47. chmod +x "{{tauri_tools_path}}/AppRun-${ARCH}"
  48. # We need AppRun to be installed as {{crate_name}}.AppDir/AppRun.
  49. # Otherwise the linuxdeploy scripts will default to symlinking our main bin instead and will crash on trying to launch.
  50. cp "{{tauri_tools_path}}/AppRun-${ARCH}" AppRun
  51. cp "{{icon_path}}" .DirIcon
  52. ln -sf "{{icon_path}}" "{{crate_name}}.png"
  53. ln -sf "usr/share/applications/{{crate_name}}.desktop" "{{crate_name}}.desktop"
  54. cd ..
  55. if [[ "$APPIMAGE_BUNDLE_GSTREAMER" != "0" ]]; then
  56. gst_plugin="--plugin gstreamer"
  57. wget -q -4 -N "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gstreamer/master/linuxdeploy-plugin-gstreamer.sh"
  58. chmod +x linuxdeploy-plugin-gstreamer.sh
  59. else
  60. gst_plugin=""
  61. fi
  62. ( cd "{{tauri_tools_path}}" && wget -q -4 -N https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh )
  63. ( cd "{{tauri_tools_path}}" && wget -q -4 -N https://github.com/tauri-apps/binary-releases/releases/download/linuxdeploy/linuxdeploy-${linuxdeploy_arch}.AppImage )
  64. chmod +x "{{tauri_tools_path}}/linuxdeploy-plugin-gtk.sh"
  65. chmod +x "{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage"
  66. dd if=/dev/zero bs=1 count=3 seek=8 conv=notrunc of="{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage"
  67. OUTPUT="{{appimage_filename}}" "{{tauri_tools_path}}/linuxdeploy-${linuxdeploy_arch}.AppImage" --appimage-extract-and-run --appdir "{{crate_name}}.AppDir" --plugin gtk ${gst_plugin} --output appimage