4
0

publish-appimage-update.sh 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Points the AppImage's fixed update address (update/.htaccess on lynx-share.com) at a published release, after checking
  3. # that release's files. It changes that one file on the site, no deploy. Run it from the release checklist.
  4. # usage: scripts/publish-appimage-update.sh v0.1.25-alpha [--check-only]
  5. # A release with an arm64 AppImage (LYNX-<label>-aarch64.AppImage, from 0.1.31) also gets its own address,
  6. # update/LYNX-aarch64.AppImage.zsync, checked the same way (round 190oy).
  7. # Anything wrong: exit 1 with the address left as it was.
  8. set -euo pipefail
  9. TAG="${1:?usage: publish-appimage-update.sh <tag> [--check-only]}"
  10. CHECK_ONLY=0; [[ "${2:-}" == "--check-only" ]] && CHECK_ONLY=1
  11. # shellcheck source=scripts/appimage-update-lib.sh
  12. . "$(dirname "$0")/appimage-update-lib.sh"
  13. LABEL="${TAG#v}"
  14. APPIMAGE="LYNX-$LABEL-x86_64.AppImage"
  15. BASE="https://github.com/$UPDATE_REPO/releases/download/$TAG"
  16. fail() { echo "publish-appimage-update: $*" >&2; exit 1; }
  17. [[ "$(gh api "repos/$UPDATE_REPO/releases/tags/$TAG" --jq .draft)" == "false" ]] || fail "$TAG is not a published release"
  18. WORK="$(mktemp -d)"
  19. trap 'rm -r -- "${WORK:?}"' EXIT
  20. # (the public addresses, as an update check sees them, not the API's view)
  21. header() { head -c 4096 "$1" | sed -n "s/^$2: //p" | head -1; }
  22. # check_appimage <AppImage name> <work prefix> <fixed address>: the release's .zsync and AppImage belong together and
  23. # the AppImage asks the fixed address for its updates
  24. check_appimage() {
  25. local name="$1" w="$2" address="$3" embedded
  26. curl -fsSL -o "$w.z" "$BASE/$name.zsync" || fail "no $name.zsync on $TAG"
  27. curl -fsSL -o "$w.a" "$BASE/$name" || fail "no $name on $TAG"
  28. [[ "$(header "$w.z" URL)" == "$BASE/$name" ]] || fail "$name.zsync URL is '$(header "$w.z" URL)', not $BASE/$name"
  29. [[ "$(header "$w.z" Length)" == "$(stat -c%s "$w.a")" ]] || fail "$name.zsync Length does not match the AppImage"
  30. [[ "$(header "$w.z" SHA-1)" == "$(sha1sum "$w.a" | cut -d' ' -f1)" ]] || fail "$name.zsync SHA-1 does not match the AppImage"
  31. # (readelf reads the .upd_info section of either architecture's AppImage)
  32. embedded="$(readelf --string-dump=.upd_info --wide "$w.a" | sed -n 's/^ *\[ *0\] *//p' | sed 's/ *$//')"
  33. [[ "$embedded" == "zsync|$address" ]] || fail "$name embeds '$embedded'"
  34. }
  35. check_appimage "$APPIMAGE" "$WORK/x86" "$UPDATE_ADDRESS"
  36. # the arm64 AppImage, when the release has one
  37. ARM_APPIMAGE="LYNX-$LABEL-aarch64.AppImage" ARM_ZSYNC=
  38. if gh api "repos/$UPDATE_REPO/releases/tags/$TAG" --jq '.assets[].name' | grep -qxF "$ARM_APPIMAGE.zsync"; then
  39. check_appimage "$ARM_APPIMAGE" "$WORK/arm" "$UPDATE_ADDRESS_AARCH64"
  40. ARM_ZSYNC="$BASE/$ARM_APPIMAGE.zsync"
  41. fi
  42. # never back to an older release
  43. CURRENT="$(update_target)" || fail "can't read $UPDATE_ADDRESS"
  44. current_tag="$(update_target_tag "$CURRENT")"
  45. if [[ -n "$current_tag" && "$current_tag" != "$TAG" && "$(printf '%s\n%s\n' "$current_tag" "$TAG" | sort -V | tail -1)" != "$TAG" ]]; then
  46. fail "the address points at $current_tag, newer than $TAG"
  47. fi
  48. [[ "$CHECK_ONLY" == 0 ]] || { echo "checked $TAG${ARM_ZSYNC:+ (and its arm64 AppImage)}, address left at ${current_tag:-nothing}"; exit 0; }
  49. update_htaccess "$BASE/$APPIMAGE.zsync" "$ARM_ZSYNC" > "$WORK/htaccess"
  50. site_upload "$WORK/htaccess" update/.htaccess || fail "the upload failed"
  51. sleep 5
  52. want="$(header "$WORK/x86.z" SHA-1)"
  53. curl -fsSL -o "$WORK/live" "$UPDATE_ADDRESS?check=$$" || fail "$UPDATE_ADDRESS does not answer after the upload"
  54. [[ "$(header "$WORK/live" SHA-1)" == "$want" ]] || fail "$UPDATE_ADDRESS does not serve $TAG's .zsync after the upload"
  55. echo "$UPDATE_ADDRESS -> $TAG"
  56. if [[ -n "$ARM_ZSYNC" ]]; then
  57. curl -fsSL -o "$WORK/live-arm" "$UPDATE_ADDRESS_AARCH64?check=$$" || fail "$UPDATE_ADDRESS_AARCH64 does not answer after the upload"
  58. [[ "$(header "$WORK/live-arm" SHA-1)" == "$(header "$WORK/arm.z" SHA-1)" ]] || fail "$UPDATE_ADDRESS_AARCH64 does not serve $TAG's .zsync after the upload"
  59. echo "$UPDATE_ADDRESS_AARCH64 -> $TAG"
  60. fi