4
0

package-linux.sh 6.1 KB

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