package-linux.sh 5.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. # Linux packages of a built LYNX binary: an AppImage (one file, runs on most distributions) and a .tar.gz
  3. # (folder with install.sh for a per-user install). Both carry the .desktop entry, the icon and the .lynx file type.
  4. #
  5. # usage: scripts/package-linux.sh <LYNX binary> <label> <output folder> [Demo.lynx]
  6. # Variables: APPIMAGETOOL (path to appimagetool; downloaded into ~/opt when missing), ARCH (default x86_64)
  7. set -euo pipefail
  8. cd "$(dirname "$0")/.."
  9. BIN="$1"; LABEL="$2"; OUTDIR="$3"; DEMO="${4:-}"
  10. ARCH="${ARCH:-x86_64}"
  11. NAME="LYNX-$LABEL-linux-$ARCH" # .tar.gz
  12. APPIMAGE="LYNX-$LABEL-$ARCH.AppImage" # AppImage names leave out "linux" (all AppImages are for Linux)
  13. APPID=com.lynx_share.LYNX # AppStream component id = desktop file name inside the AppImage
  14. APPIMAGETOOL_VERSION=1.9.0
  15. WORK="$(mktemp -d)"
  16. trap 'rm -rf "$WORK"' EXIT
  17. mkdir -p "$OUTDIR"
  18. # --- folder for the .tar.gz --------------------------------------------------------------------------------
  19. PKG="$WORK/$NAME"
  20. mkdir -p "$PKG"
  21. install -m 755 "$BIN" "$PKG/LYNX"
  22. strip --strip-unneeded "$PKG/LYNX" 2> /dev/null || true
  23. ./scripts/fetch-onnxruntime.sh linux "$PKG"
  24. install -m 644 resources/linux/lynx.desktop resources/linux/lynx-mime.xml LICENSE THIRD_PARTY.md PRIVACY.md "$PKG/"
  25. ./scripts/collect-licenses.sh "$PKG/licenses" # third-party licence texts (round 190nk)
  26. install -m 644 resources/lynx_icon_256.png "$PKG/lynx.png"
  27. cp -r resources/linux/icons "$PKG/icons" # hicolor 16-512 px (tools/make_logo.py; 16 and 24 px: the small-size form)
  28. install -m 755 resources/linux/install.sh "$PKG/install.sh"
  29. [[ -n "$DEMO" && -f "$DEMO" ]] && install -m 644 "$DEMO" "$PKG/Demo.lynx"
  30. tar -C "$WORK" -czf "$OUTDIR/$NAME.tar.gz" "$NAME"
  31. # --- AppImage ----------------------------------------------------------------------------------------------
  32. APPDIR="$WORK/LYNX.AppDir"
  33. mkdir -p "$APPDIR/usr/bin" "$APPDIR/usr/share/applications" "$APPDIR/usr/share/icons" \
  34. "$APPDIR/usr/share/mime/packages" "$APPDIR/usr/share/metainfo"
  35. install -m 755 "$PKG/LYNX" "$PKG"/libonnxruntime.so.* "$APPDIR/usr/bin/"
  36. install -m 644 resources/linux/lynx.desktop "$APPDIR/usr/share/applications/$APPID.desktop"
  37. install -m 644 resources/linux/lynx.desktop "$APPDIR/$APPID.desktop"
  38. # AppStream metadata with this build's version and date (validated by appimagetool when appstreamcli is installed)
  39. RELDATE="$(git log -1 --format=%cs 2> /dev/null || date -u +%F)"
  40. sed -e "s/@VERSION@/$LABEL/" -e "s/@DATE@/$RELDATE/" resources/linux/$APPID.appdata.xml > "$APPDIR/usr/share/metainfo/$APPID.appdata.xml"
  41. cp -r resources/linux/icons/hicolor "$APPDIR/usr/share/icons/hicolor"
  42. install -m 644 resources/lynx_icon_256.png "$APPDIR/lynx.png"
  43. ln -sf lynx.png "$APPDIR/.DirIcon"
  44. install -m 644 resources/linux/lynx-mime.xml "$APPDIR/usr/share/mime/packages/lynx-mime.xml"
  45. for f in LICENSE THIRD_PARTY.md PRIVACY.md; do install -m 644 "$f" "$APPDIR/usr/share/$f"; done
  46. cp -r "$PKG/licenses" "$APPDIR/usr/share/licenses"
  47. cat > "$APPDIR/AppRun" <<'EOF'
  48. #!/bin/sh
  49. here="$(dirname "$(readlink -f "$0")")"
  50. exec "$here/usr/bin/LYNX" "$@"
  51. EOF
  52. chmod 755 "$APPDIR/AppRun"
  53. TOOL="${APPIMAGETOOL:-$HOME/opt/appimagetool-$APPIMAGETOOL_VERSION-x86_64.AppImage}"
  54. if [[ ! -x "$TOOL" ]]; then
  55. mkdir -p "$(dirname "$TOOL")"
  56. curl -fsSL -o "$TOOL" "https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage"
  57. chmod +x "$TOOL"
  58. fi
  59. # no FUSE needed to run the tool itself (containers, CI)
  60. # update information (Gear Lever, AppImageUpdate): a fixed address on lynx-share.com, no GitHub API (issue #48: its
  61. # anonymous limit of 60 requests an hour shows up as "no updates"). scripts/publish-appimage-update.sh points that address
  62. # at a published release's .zsync. Its URL line is absolute, because readers resolve a relative one against the fixed address.
  63. UPDATE_INFO="${UPDATE_INFO-zsync|https://lynx-share.com/update/LYNX-$ARCH.AppImage.zsync}"
  64. APPIMAGE_URL="${APPIMAGE_URL-https://github.com/Ka1-S/LYNX-SHARE/releases/download/v$LABEL/$APPIMAGE}"
  65. APPIMAGE_EXTRACT_AND_RUN=1 ARCH="$ARCH" "$TOOL" ${UPDATE_INFO:+-u "$UPDATE_INFO"} "$APPDIR" "$OUTDIR/$APPIMAGE" \
  66. > "$WORK/appimagetool.log" 2>&1 || { cat "$WORK/appimagetool.log"; exit 1; }
  67. if [[ -n "$UPDATE_INFO" && ! -f "$OUTDIR/$APPIMAGE.zsync" ]]; then
  68. [[ -f "$APPIMAGE.zsync" ]] && mv "$APPIMAGE.zsync" "$OUTDIR/"
  69. # appimagetool only writes the .zsync when zsyncmake is installed (the release job installs it)
  70. [[ -f "$OUTDIR/$APPIMAGE.zsync" ]] || ! command -v zsyncmake > /dev/null \
  71. || { echo "no $APPIMAGE.zsync written"; cat "$WORK/appimagetool.log"; exit 1; }
  72. fi
  73. chmod 755 "$OUTDIR/$APPIMAGE"
  74. if [[ -n "$UPDATE_INFO" && -f "$OUTDIR/$APPIMAGE.zsync" ]]; then
  75. ( cd "$OUTDIR" && zsyncmake -u "$APPIMAGE_URL" -o "$APPIMAGE.zsync" "$APPIMAGE" )
  76. fi
  77. # issue #48 (Gear Lever, AppImageUpdate): what they read must stay right. The embedded update information is ours, the
  78. # .zsync points at this release's AppImage, and its name still matches the pattern embedded up to 0.1.24, which those
  79. # versions use to find it on the releases.
  80. if [[ -n "$UPDATE_INFO" ]]; then
  81. if command -v readelf > /dev/null; then
  82. embedded="$(readelf --string-dump=.upd_info --wide "$OUTDIR/$APPIMAGE" | sed -n 's/^ *\[ *0\] *//p' | sed 's/ *$//')"
  83. [[ "$embedded" == "$UPDATE_INFO" ]] || { echo "update information is '$embedded', not '$UPDATE_INFO'"; exit 1; }
  84. fi
  85. case "$APPIMAGE.zsync" in LYNX-*-$ARCH.AppImage.zsync) ;; *) echo "$APPIMAGE.zsync does not match LYNX-*-$ARCH.AppImage.zsync"; exit 1 ;; esac
  86. if [[ -f "$OUTDIR/$APPIMAGE.zsync" ]]; then
  87. url="$(head -c 4096 "$OUTDIR/$APPIMAGE.zsync" | sed -n 's/^URL: //p' | head -1)"
  88. [[ "$url" == "$APPIMAGE_URL" ]] || { echo "$APPIMAGE.zsync points at '$url'"; exit 1; }
  89. fi
  90. fi
  91. ls -la "$OUTDIR/$NAME.tar.gz" "$OUTDIR/$APPIMAGE"*