From abc27819cbd41b2f94a53625a04bdeee7fa0337d Mon Sep 17 00:00:00 2001 From: Avi Date: Wed, 30 Sep 2026 12:12:26 -0500 Subject: [PATCH] feat(launcher): one-click update script for the desktop entry update-keynctr.sh: fetch origin/master, ff-only pull (aborts on dirty tracked tree), cargo + frontend rebuild, notify-send result. Login-shell PATH is reconstructed for cargo/node. Idempotent: quiet no-op when already current. Installed as 'Keynctr Update' desktop entry + right-click 'Update Keynctr' action on the main entry (entries live in ~/.local/share/applications, not tracked). --- update-keynctr.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 update-keynctr.sh diff --git a/update-keynctr.sh b/update-keynctr.sh new file mode 100755 index 0000000..eb473b3 --- /dev/null +++ b/update-keynctr.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# Update Keynctr from origin/master and rebuild, then notify. +# Safe for the vault: touches only the repo + build outputs, never +# ~/.local/share/keynectr. If there is nothing new it exits quietly-fast. +# A dirty tracked tree aborts the pull (nothing is stashed or overwritten). +set -uo pipefail + +REPO="/home/avi/Projects/Keynctr" +LOG="$HOME/.local/state/keynctr-update.log" +mkdir -p "$(dirname "$LOG")" + +notify() { notify-send "${1:-Keynctr update}" "$2" ${3:+-u "$3"}; } + +# The desktop launcher env lacks login-shell PATH bits; cargo/node live there. +export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$HOME/.bin:$PATH" +for dir in "$HOME"/.nvm/versions/node/*/bin "$HOME"/.local/share/mise/installs/node/*/bin; do + [[ -d "$dir" ]] && PATH="$dir:$PATH" +done +export PATH + +{ + echo "===== $(date -Is) update run =====" + cd "$REPO" || { notify "Keynctr update failed" "Repo not found." "critical"; exit 1; } + + git fetch origin master 2>&1 || { notify "Keynctr update failed" "git fetch failed (offline?)" "critical"; exit 1; } + + LOCAL=$(git rev-parse HEAD) + REMOTE=$(git rev-parse origin/master) + if [[ "$LOCAL" == "$REMOTE" ]]; then + echo "already up to date @ ${LOCAL:0:7}" + notify "Keynctr is up to date" "Already on the latest build (${LOCAL:0:7})." + exit 0 + fi + + # Refuse to pull over uncommitted tracked changes. + if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then + echo "dirty tracked tree; aborting pull" + notify "Keynctr update aborted" "You have uncommitted changes in the repo — nothing was changed." "critical" + exit 1 + fi + + git pull --ff-only origin master 2>&1 || { notify "Keynctr update failed" "git pull failed." "critical"; exit 1; } + + echo "-- cargo build --release" + cargo build --release 2>&1 | tail -2 || { notify "Keynctr update failed" "cargo build failed — see $LOG" "critical"; exit 1; } + + echo "-- frontend build" + (cd frontend && npm run build 2>&1 | tail -2 && npm run electron:build 2>&1 | tail -1) \ + || { notify "Keynctr update failed" "frontend build failed — see $LOG" "critical"; exit 1; } + + echo "updated ${LOCAL:0:7} -> ${REMOTE:0:7}" + notify "Keynctr updated" "Updated to ${REMOTE:0:7}. Launch Keynctr to use the new build." "normal" +} >>"$LOG" 2>&1