4
0

package-linux.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. install -m 644 resources/linux/lynx.desktop resources/linux/lynx-mime.xml LICENSE THIRD_PARTY.md PRIVACY.md "$PKG/"
  24. install -m 644 resources/lynx_icon_256.png "$PKG/lynx.png"
  25. install -m 755 resources/linux/install.sh "$PKG/install.sh"
  26. [[ -n "$DEMO" && -f "$DEMO" ]] && install -m 644 "$DEMO" "$PKG/Demo.lynx"
  27. tar -C "$WORK" -czf "$OUTDIR/$NAME.tar.gz" "$NAME"
  28. # --- AppImage ----------------------------------------------------------------------------------------------
  29. APPDIR="$WORK/LYNX.AppDir"
  30. mkdir -p "$APPDIR/usr/bin" "$APPDIR/usr/share/applications" "$APPDIR/usr/share/icons/hicolor/256x256/apps" \
  31. "$APPDIR/usr/share/mime/packages" "$APPDIR/usr/share/metainfo"
  32. install -m 755 "$PKG/LYNX" "$APPDIR/usr/bin/LYNX"
  33. install -m 644 resources/linux/lynx.desktop "$APPDIR/usr/share/applications/$APPID.desktop"
  34. install -m 644 resources/linux/lynx.desktop "$APPDIR/$APPID.desktop"
  35. # AppStream metadata with this build's version and date (validated by appimagetool when appstreamcli is installed)
  36. RELDATE="$(git log -1 --format=%cs 2> /dev/null || date -u +%F)"
  37. sed -e "s/@VERSION@/$LABEL/" -e "s/@DATE@/$RELDATE/" resources/linux/$APPID.appdata.xml > "$APPDIR/usr/share/metainfo/$APPID.appdata.xml"
  38. install -m 644 resources/lynx_icon_256.png "$APPDIR/usr/share/icons/hicolor/256x256/apps/lynx.png"
  39. install -m 644 resources/lynx_icon_256.png "$APPDIR/lynx.png"
  40. ln -sf lynx.png "$APPDIR/.DirIcon"
  41. install -m 644 resources/linux/lynx-mime.xml "$APPDIR/usr/share/mime/packages/lynx-mime.xml"
  42. for f in LICENSE THIRD_PARTY.md PRIVACY.md; do install -m 644 "$f" "$APPDIR/usr/share/$f"; done
  43. cat > "$APPDIR/AppRun" <<'EOF'
  44. #!/bin/sh
  45. here="$(dirname "$(readlink -f "$0")")"
  46. exec "$here/usr/bin/LYNX" "$@"
  47. EOF
  48. chmod 755 "$APPDIR/AppRun"
  49. TOOL="${APPIMAGETOOL:-$HOME/opt/appimagetool-$APPIMAGETOOL_VERSION-x86_64.AppImage}"
  50. if [[ ! -x "$TOOL" ]]; then
  51. mkdir -p "$(dirname "$TOOL")"
  52. curl -fsSL -o "$TOOL" "https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage"
  53. chmod +x "$TOOL"
  54. fi
  55. # no FUSE needed to run the tool itself (containers, CI)
  56. # update information (AppImageUpdate): the newest release of Ka1-S/LYNX-SHARE, pre-releases included; appimagetool writes
  57. # the matching .zsync next to the AppImage, and the release job attaches it with the other files in dist/
  58. UPDATE_INFO="${UPDATE_INFO-gh-releases-zsync|Ka1-S|LYNX-SHARE|latest-all|LYNX-*-$ARCH.AppImage.zsync}"
  59. APPIMAGE_EXTRACT_AND_RUN=1 ARCH="$ARCH" "$TOOL" ${UPDATE_INFO:+-u "$UPDATE_INFO"} "$APPDIR" "$OUTDIR/$APPIMAGE" \
  60. > "$WORK/appimagetool.log" 2>&1 || { cat "$WORK/appimagetool.log"; exit 1; }
  61. if [[ -n "$UPDATE_INFO" && ! -f "$OUTDIR/$APPIMAGE.zsync" ]]; then
  62. [[ -f "$APPIMAGE.zsync" ]] && mv "$APPIMAGE.zsync" "$OUTDIR/"
  63. # appimagetool only writes the .zsync when zsyncmake is installed (the release job installs it)
  64. [[ -f "$OUTDIR/$APPIMAGE.zsync" ]] || ! command -v zsyncmake > /dev/null \
  65. || { echo "no $APPIMAGE.zsync written"; cat "$WORK/appimagetool.log"; exit 1; }
  66. fi
  67. chmod 755 "$OUTDIR/$APPIMAGE"
  68. ls -la "$OUTDIR/$NAME.tar.gz" "$OUTDIR/$APPIMAGE"*