mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-20 10:12:29 +01:00
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
deploy.sh records the workout app's git tree after each phone install and skips the phone when the tree is the same, so a PC-only change deploys with the phone unplugged. No record means the phone is needed. Todo: 2556952d Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
5.5 KiB
Bash
Executable File
137 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Deploy screen-locker for real: update the live clone, reinstall, restart the
|
|
# long-running user units, prove they are healthy, then ship the workout app.
|
|
#
|
|
# Every path is anchored on the LIVE clone (~/src/screen-locker), never on this
|
|
# script's own directory: install.sh installs editable from wherever it sits,
|
|
# so running a worktree copy of it would point the services at scratch code.
|
|
#
|
|
# workout-locker.service is deliberately NOT restarted: it is the login-time
|
|
# gate and starting it can lock the display. Its timer is only re-enabled.
|
|
#
|
|
# Phone: phone_deploy.sh refuses com.kuhy.workout_app (exit 46) unless kuhy
|
|
# runs this himself with PHONE_PROTECT_ALLOW=com.kuhy.workout_app and the app
|
|
# closed. This script never sets that variable; it passes the caller's
|
|
# environment through and fails loudly when the guard refuses.
|
|
#
|
|
# The phone step is skipped when the workout app's source is unchanged since
|
|
# the last successful phone install: a PC-only change (CI config, a Python pin)
|
|
# then deploys with the phone unplugged. The key is the git tree of APP_DIR,
|
|
# written to PHONE_APP_MARKER after each install; no marker means the phone is
|
|
# required (fail closed). Any app change gives a new tree, so it is never skipped.
|
|
#
|
|
# Usage: bash scripts/deploy.sh [--health-only | --phone-only]
|
|
#
|
|
# Seams: SCREEN_LOCKER_LIVE (live clone), DEPLOY_WEB_PORT (health port),
|
|
# PHONE_DEPLOY (installer), PHONE_APP_MARKER (last installed app tree).
|
|
# Exit: 0 healthy and installed everywhere | 1 any step or check failed.
|
|
|
|
set -euo pipefail
|
|
|
|
readonly LIVE="${SCREEN_LOCKER_LIVE:-$HOME/src/screen-locker}"
|
|
readonly PY="/usr/bin/python3"
|
|
readonly APP_DIR="stronglift_replacement/workout_app"
|
|
readonly PHONE_DEPLOY="${PHONE_DEPLOY:-$HOME/.claude/scripts/phone_deploy.sh}"
|
|
readonly PHONE_APP_MARKER="${PHONE_APP_MARKER:-$HOME/.local/state/screen-locker/phone_app_tree}"
|
|
readonly UNITS=(screen-locker-web.service workout-poke.service runnerup-watch.service)
|
|
|
|
die() { echo "deploy: FAIL: $*" >&2; exit 1; }
|
|
ok() { echo "deploy: ok: $*"; }
|
|
|
|
main_pid() { systemctl --user show -p MainPID --value "$1"; }
|
|
|
|
web_port() {
|
|
if [[ -n "${DEPLOY_WEB_PORT:-}" ]]; then
|
|
echo "$DEPLOY_WEB_PORT"
|
|
else
|
|
(cd /tmp && "$PY" -c 'from screen_locker._web_server import DEFAULT_PORT; print(DEFAULT_PORT)')
|
|
fi
|
|
}
|
|
|
|
# /api/health answers and reports enforcement armed; retried while the
|
|
# freshly restarted server binds its port.
|
|
check_web() {
|
|
local port body i
|
|
port="$(web_port)"
|
|
for i in $(seq 1 15); do
|
|
if body="$(curl -fsS --max-time 2 "http://127.0.0.1:$port/api/health" 2>/dev/null)"; then
|
|
jq -e '.armed == true' >/dev/null <<<"$body" \
|
|
|| die "web health on :$port says enforcement is NOT armed"
|
|
ok "web /api/health on :$port armed (try $i)"
|
|
return 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
die "web /api/health on :$port did not answer within 15 s"
|
|
}
|
|
|
|
health() {
|
|
local unit
|
|
for unit in "${UNITS[@]}"; do
|
|
systemctl --user is-active --quiet "$unit" || die "$unit is not active"
|
|
ok "$unit active"
|
|
done
|
|
check_web
|
|
"$PY" "$LIVE/scripts/check_enforcement_armed.py" --quiet \
|
|
|| die "check_enforcement_armed.py: enforcement is not armed"
|
|
ok "enforcement armed"
|
|
"$PY" "$LIVE/scripts/poke_selftest.py" sandbox >/dev/null \
|
|
|| die "workout-poke sandbox self-test failed"
|
|
ok "workout-poke signed sandbox round trip"
|
|
local mod
|
|
mod="$(cd /tmp && "$PY" -c 'import screen_locker; print(screen_locker.__file__)')"
|
|
[[ "$mod" == "$LIVE"/* ]] || die "screen_locker imports from $mod, not $LIVE"
|
|
ok "screen_locker imports from the live clone"
|
|
}
|
|
|
|
desktop() {
|
|
local unit
|
|
declare -A before=()
|
|
git -C "$LIVE" pull --ff-only || die "git pull --ff-only in $LIVE (dirty or diverged?)"
|
|
[[ "$(git -C "$LIVE" rev-parse HEAD)" == "$(git -C "$LIVE" rev-parse '@{u}')" ]] \
|
|
|| die "$LIVE HEAD is not its upstream after the pull"
|
|
ok "live clone at $(git -C "$LIVE" rev-parse --short HEAD)"
|
|
bash "$LIVE/install.sh" || die "install.sh failed"
|
|
for unit in "${UNITS[@]}"; do before[$unit]="$(main_pid "$unit")"; done
|
|
systemctl --user restart "${UNITS[@]}" || die "restart of ${UNITS[*]} failed"
|
|
for unit in "${UNITS[@]}"; do
|
|
[[ "$(main_pid "$unit")" != "${before[$unit]}" ]] \
|
|
|| die "$unit kept PID ${before[$unit]}: restart did not take"
|
|
done
|
|
ok "restarted ${UNITS[*]}"
|
|
}
|
|
|
|
phone() {
|
|
local rc=0 tree
|
|
tree="$(git -C "$LIVE" rev-parse "HEAD:$APP_DIR")" || die "no $APP_DIR tree at $LIVE HEAD"
|
|
if [[ "$(cat "$PHONE_APP_MARKER" 2>/dev/null || true)" == "$tree" ]]; then
|
|
ok "workout app unchanged since the last phone install (tree ${tree:0:10}); phone step skipped"
|
|
return 0
|
|
fi
|
|
bash "$PHONE_DEPLOY" "$LIVE/$APP_DIR" --release || rc=$?
|
|
case "$rc" in
|
|
0)
|
|
mkdir -p "$(dirname "$PHONE_APP_MARKER")"
|
|
printf '%s\n' "$tree" > "$PHONE_APP_MARKER"
|
|
ok "workout app release build installed on the phone (tree ${tree:0:10})"
|
|
;;
|
|
46) die "phone_deploy protect guard (exit 46) refused com.kuhy.workout_app;" \
|
|
"kuhy runs: PHONE_PROTECT_ALLOW=com.kuhy.workout_app bash $LIVE/scripts/deploy.sh" \
|
|
"with the workout app closed" ;;
|
|
*) die "phone_deploy.sh exited $rc (see its exit-code table)" ;;
|
|
esac
|
|
}
|
|
|
|
if [[ "${1:-}" == "--phone-only" ]]; then
|
|
phone
|
|
exit 0
|
|
fi
|
|
if [[ "${1:-}" == "--health-only" ]]; then
|
|
health
|
|
exit 0
|
|
fi
|
|
desktop
|
|
health
|
|
phone
|
|
ok "deployed"
|