Files
m3tam3re 20feae2098 feat: add automatic updates for vibetyper, msty-studio, zellij-ps
- 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
2026-07-26 12:09:22 +02:00

76 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env nix-shell
#!nix-shell --pure -i bash -p bash curl jq nix nix-prefetch cacert git
set -euo pipefail
# Update zellij-ps to the latest commit on the helper-scripts master branch.
# The upstream repo (m3ta.dev/m3tam3re/helper-scripts) has no tags/releases,
# so we track the tip of master via the Gitea API.
#
# This is a "branch-tracking" updater: always pulls the newest commit,
# NOT a stable release. Suitable for personal script repos.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NIX_FILE="$SCRIPT_DIR/default.nix"
DOMAIN="code.m3ta.dev"
OWNER="m3tam3re"
REPO="helper-scripts"
BRANCH="master"
echo "Fetching latest commit on $BRANCH of $DOMAIN/$OWNER/$REPO..."
LATEST_SHA=$(curl -fsSL "https://$DOMAIN/api/v1/repos/$OWNER/$REPO/branches/$BRANCH" \
| jq -r '.commit.id')
if [[ -z "$LATEST_SHA" ]]; then
echo "ERROR: Failed to fetch latest commit from $DOMAIN/$OWNER/$REPO" >&2
exit 1
fi
# Read current rev from the nix file
CURRENT_SHA=$(awk '
/^[[:space:]]*rev = "/ {
gsub(/^[[:space:]]*rev = "/, "")
gsub(/".*/, "")
print
exit
}
' "$NIX_FILE")
echo "Current: ${CURRENT_SHA:0:10}"
echo "Latest: ${LATEST_SHA:0:10}"
if [[ "$LATEST_SHA" == "$CURRENT_SHA" ]]; then
echo "Already at latest commit, nothing to do."
exit 0
fi
echo "==> Updating zellij-ps: ${CURRENT_SHA:0:10} -> ${LATEST_SHA:0:10}"
# Compute new sha256 via nix-prefetch-url (matches existing sha256 = "..." style)
ARCHIVE_URL="https://$DOMAIN/$OWNER/$REPO/archive/$LATEST_SHA.tar.gz"
echo "Prefetching: $ARCHIVE_URL"
HASH=$(nix-prefetch-url --unpack --type sha256 "$ARCHIVE_URL" 2>/dev/null)
if [[ -z "$HASH" ]]; then
echo "ERROR: nix-prefetch-url failed" >&2
exit 1
fi
echo "New sha256: $HASH"
# Update rev and sha256 in the nix file
sed -i "s|^\([[:space:]]*\)rev = \"[^\"]*\";|\1rev = \"$LATEST_SHA\";|" "$NIX_FILE"
sed -i "s|^\([[:space:]]*\)sha256 = \"[^\"]*\";|\1sha256 = \"$HASH\";|" "$NIX_FILE"
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
SHORT="${LATEST_SHA:0:10}"
git -C "$NIXPKGS_ROOT" add "$NIX_FILE"
git -C "$NIXPKGS_ROOT" commit -m "zellij-ps: update helper-scripts to $SHORT"
echo "==> Committed"
fi