- vibetyper/msty-studio: unversioned AppImage URLs → HEAD/Last-Modified check via custom update.sh, refreshes sha256 when upstream binary changes - zellij-ps: switch to branch-tracking (master tip via Gitea API) since helper-scripts repo has no tags - all three expose passthru.updateScript so the existing CI workflow discovers them via is_custom_update_script
69 lines
2.6 KiB
Bash
Executable File
69 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env nix-shell
|
|
#!nix-shell --pure -i bash -p bash curl nix nix-prefetch cacert git
|
|
set -euo pipefail
|
|
|
|
# Update vibetyper AppImage hash.
|
|
#
|
|
# Upstream publishes to an unversioned URL (VibeTyper.AppImage) — there is no
|
|
# version-pinned URL and no usable GitHub release. To still catch updates, we:
|
|
# 1. HEAD the URL and read the Last-Modified header
|
|
# 2. Compare to the value stored as a `# last-modified:` comment in default.nix
|
|
# 3. If changed: re-download, compute sha256, update hash + comment, commit
|
|
#
|
|
# The version attribute stays static (manual bump) — only the binary hash is
|
|
# refreshed automatically.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
NIX_FILE="$SCRIPT_DIR/default.nix"
|
|
URL="https://cdn.vibetyper.com/releases/linux/VibeTyper.AppImage"
|
|
|
|
echo "Checking $URL ..."
|
|
# -f: fail on HTTP errors, -s: silent, -S: show errors, -I: HEAD, -L: follow redirects
|
|
HEADERS=$(curl -fsSIL "$URL")
|
|
NEW_LAST_MODIFIED=$(echo "$HEADERS" | tr -d '\r' \
|
|
| awk -F': ' 'tolower($1)=="last-modified" {print $2; exit}')
|
|
|
|
if [[ -z "$NEW_LAST_MODIFIED" ]]; then
|
|
echo "ERROR: Could not read Last-Modified header from $URL" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Read stored Last-Modified from `# last-modified:` comment in the nix file
|
|
CURRENT_LAST_MODIFIED=$(awk -F': ' '/^# last-modified:/ {sub(/^# last-modified: /, ""); print; exit}' "$NIX_FILE")
|
|
|
|
echo "Current: ${CURRENT_LAST_MODIFIED:-<none>}"
|
|
echo "Latest: $NEW_LAST_MODIFIED"
|
|
|
|
if [[ "$NEW_LAST_MODIFIED" == "$CURRENT_LAST_MODIFIED" ]]; then
|
|
echo "No change, nothing to do."
|
|
exit 0
|
|
fi
|
|
|
|
echo "==> Content changed, refreshing hash..."
|
|
|
|
# Compute new sha256 (SRI form, matches existing `sha256 = "sha256-..."` style)
|
|
HASH=$(nix-prefetch-url --type sha256 "$URL" 2>/dev/null)
|
|
SRI=$(nix hash convert --hash-algo sha256 --to sri "$HASH")
|
|
echo "New sha256: $SRI"
|
|
|
|
# Update the sha256 attribute (keeps the existing `sha256 = "sha256-..."` shape)
|
|
sed -i "s|^\([[:space:]]*\)sha256 = \"[^\"]*\";|\1sha256 = \"$SRI\";|" "$NIX_FILE"
|
|
|
|
# Update or insert the last-modified marker comment
|
|
if grep -q '^# last-modified:' "$NIX_FILE"; then
|
|
sed -i "s|^# last-modified:.*|# last-modified: $NEW_LAST_MODIFIED|" "$NIX_FILE"
|
|
else
|
|
sed -i "1i # last-modified: $NEW_LAST_MODIFIED" "$NIX_FILE"
|
|
fi
|
|
|
|
echo "Updated $NIX_FILE"
|
|
|
|
# Commit when inside a git repo
|
|
NIXPKGS_ROOT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || true)
|
|
if [[ -n "$NIXPKGS_ROOT" ]] && \
|
|
[[ -n "$(git -C "$NIXPKGS_ROOT" status --porcelain "$NIX_FILE")" ]]; then
|
|
git -C "$NIXPKGS_ROOT" add "$NIX_FILE"
|
|
git -C "$NIXPKGS_ROOT" commit -m "vibetyper: refresh AppImage ($NEW_LAST_MODIFIED)"
|
|
echo "==> Committed"
|
|
fi
|