Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·94 lines (79 loc) · 3.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·94 lines (79 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# Install (or remove) the OpenCode usage collector for Omarchy's Agents panel.
# Tells you what it will do, then asks. Nothing outside your home directory is
# touched, and nothing belonging to Omarchy is modified.
set -euo pipefail
BIN_DIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/agents/usage"
COLLECTOR="omarchy-agent-usage-opencode"
SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
say() { printf '%s\n' "$*"; }
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
confirm() {
[[ "${ASSUME_YES:-0}" == "1" ]] && return 0
local reply
read -r -p "$1 [y/N] " reply
[[ "$reply" == [yY] || "$reply" == [yY][eE][sS] ]]
}
uninstall() {
say "This will remove:"
say " $BIN_DIR/$COLLECTOR"
say " $UNIT_DIR/opencode-usage.{service,timer}"
say " $STATE_DIR/opencode.json (the usage record; the tab disappears)"
say ""
confirm "Remove them?" || { say "Nothing done."; exit 0; }
systemctl --user disable --now opencode-usage.timer 2>/dev/null || true
rm -f "$UNIT_DIR/opencode-usage.service" "$UNIT_DIR/opencode-usage.timer"
rm -f "$BIN_DIR/$COLLECTOR" "$STATE_DIR/opencode.json"
systemctl --user daemon-reload
say "Removed."
exit 0
}
[[ "${1:-}" == "--uninstall" ]] && uninstall
[[ "${1:-}" == "--help" || "${1:-}" == "-h" ]] && {
say "usage: $0 [--uninstall] [--help]"
say " ASSUME_YES=1 $0 # no prompt"
exit 0
}
command -v systemctl >/dev/null || die "systemctl not found; this expects a systemd user session."
command -v python3 >/dev/null || die "python3 not found."
python3 - <<'PY' || die "Python 3.11 or newer is required (this script uses X | Y type syntax)."
import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)
PY
# Warn, do not block: someone may well be installing this before first run.
OPENCODE_DB="${XDG_DATA_HOME:-$HOME/.local/share}/opencode/opencode.db"
[[ -f "$OPENCODE_DB" ]] || say "note: $OPENCODE_DB does not exist yet. Run OpenCode once, or the tab will stay hidden until you do."
AGENTS_PLUGIN="${OMARCHY_PATH:-/usr/share/omarchy}/shell/plugins/agents"
[[ -d "$AGENTS_PLUGIN" ]] || say "note: $AGENTS_PLUGIN not found. Without Omarchy's agents plugin there is no panel to add a tab to."
say "This will install:"
say " $SRC/bin/$COLLECTOR"
say " -> $BIN_DIR/$COLLECTOR"
say " $SRC/systemd/opencode-usage.{service,timer}"
say " -> $UNIT_DIR/"
say "then enable and start opencode-usage.timer (runs every 2 minutes)."
say ""
say "The collector reads OpenCode's database read-only and writes one JSON file"
say "to $STATE_DIR/. It makes no network call."
say ""
confirm "Proceed?" || { say "Nothing done."; exit 0; }
mkdir -p "$BIN_DIR" "$UNIT_DIR" "$STATE_DIR"
install -m 0755 "$SRC/bin/$COLLECTOR" "$BIN_DIR/$COLLECTOR"
install -m 0644 "$SRC/systemd/opencode-usage.service" "$UNIT_DIR/opencode-usage.service"
install -m 0644 "$SRC/systemd/opencode-usage.timer" "$UNIT_DIR/opencode-usage.timer"
systemctl --user daemon-reload
systemctl --user enable --now opencode-usage.timer
say ""
if systemctl --user start opencode-usage.service; then
say "Installed, and the first collection ran."
else
say "Installed, but the first run failed. See: journalctl --user -u opencode-usage.service"
fi
say ""
say "Open the Agents panel in the top bar; the OpenCode tab should be there."
say "If it is not, the collector found no usage yet — check with:"
say " systemctl --user status opencode-usage.service"
say " cat $STATE_DIR/opencode.json"
say ""
say "Note: linger is off by default, so the timer runs only while you are logged in."
say "That is usually what you want on a laptop."