Bash · 1294 bytes Raw Blame History
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 ACTION_ID="${1:-org.freedesktop.login1.power-off}"
5
6 if ! command -v pkcheck >/dev/null 2>&1; then
7 echo "pkcheck not found; install polkit tools to run live auth validation"
8 exit 1
9 fi
10
11 if command -v garcardctl >/dev/null 2>&1; then
12 GARCARDCTL=(garcardctl)
13 else
14 GARCARDCTL=(cargo run -q -p garcardctl --)
15 fi
16
17 run_garcardctl() {
18 "${GARCARDCTL[@]}" "$@"
19 }
20
21 echo "[1/5] Check daemon connectivity"
22 run_garcardctl ping
23
24 echo "[2/5] Check daemon status"
25 run_garcardctl status
26
27 echo "[3/5] Check pre-auth summary"
28 run_garcardctl auth-summary
29
30 echo "[4/5] Trigger interactive policy check"
31 echo "Action ID: ${ACTION_ID}"
32 echo "Expected: garcard prompt should appear in your X11 session."
33 set +e
34 pkcheck --allow-user-interaction --process "$$" --action-id "${ACTION_ID}"
35 PKCHECK_RC=$?
36 set -e
37 echo "pkcheck exit code: ${PKCHECK_RC}"
38
39 echo "[5/5] Check post-auth summary"
40 run_garcardctl auth-summary
41
42 cat <<'EOF'
43 Exit code hints:
44 0 authorized
45 1 not authorized or canceled
46 2 no such action or action unavailable in this context
47
48 Next manual checks:
49 - Run again and press Esc to verify cancel behavior.
50 - Run `garcard prompt --mode secret --message "Timeout check" --timeout-secs 5`
51 and wait to verify timeout handling (exit code 124).
52 EOF