-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·148 lines (131 loc) · 5.01 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·148 lines (131 loc) · 5.01 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
set -euo pipefail
# pi-web uninstaller — removes binary, service config, and runtime state.
# Triggered as npm preuninstall hook when `pi remove npm:@ygncode/pi-web@beta`
# is run. The npm package directory itself is removed by npm after this script.
#
# Kept intact (survives uninstall → preserves data for reinstall):
# - ~/.pi/agent/pi-web.sqlite (settings, scratchpads, project prefs)
# - ~/.pi/agent/pi-web-memory.sqlite (memory skill data)
# - ~/.config/pi-web/env (PI_WEB_TOKEN, PATH, etc.)
# - ~/.pi/agent/sessions/ (session files)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}→${NC} $*" >&2; }
warn() { echo -e "${YELLOW}⚠${NC} $*" >&2; }
skip() { echo -e " ${YELLOW}(skipped)${NC} $*" >&2; }
# Determine binary location (matches install.sh logic).
if [[ -n "${PI_WEB_INSTALL_DIR:-}" ]]; then
BINARY="${PI_WEB_INSTALL_DIR}/pi-web"
elif [[ -n "${npm_package_name:-}" ]]; then
BINARY="${HOME}/.pi/agent/bin/pi-web"
else
BINARY="/usr/local/bin/pi-web"
fi
# ── Stop running instance ──────────────────────────────────────────
stop_service() {
if [[ -f "$BINARY" ]]; then
info "Stopping running pi-web instance..."
if [[ "$(uname -s)" == "Linux" ]]; then
systemctl --user stop pi-web.service 2>/dev/null || true
elif [[ "$(uname -s)" == "Darwin" ]]; then
launchctl bootout "gui/$(id -u)/com.pi-web" 2>/dev/null || launchctl unload "${HOME}/Library/LaunchAgents/com.pi-web.plist" 2>/dev/null || true
fi
pkill -f "${BINARY}" 2>/dev/null || true
sleep 1
fi
}
# ── Remove binary ──────────────────────────────────────────────────
remove_binary() {
if [[ -f "$BINARY" ]]; then
info "Removing binary: ${BINARY}"
rm -f "$BINARY"
else
skip "binary not found at ${BINARY}"
fi
}
# ── Remove version file ─────────────────────────────────────────────
remove_version_file() {
local vf="${HOME}/.pi/agent/pi-web-version"
if [[ -f "$vf" ]]; then
info "Removing version file: ${vf}"
rm -f "$vf"
else
skip "version file not found"
fi
}
# ── Remove runtime state ────────────────────────────────────────────
remove_state() {
local state="${HOME}/.pi/agent/pi-web/pi-web-state.json"
if [[ -f "$state" ]]; then
info "Removing state file: ${state}"
rm -f "$state"
else
skip "state file not found"
fi
# Remove the parent dir if empty
local parent_dir="${HOME}/.pi/agent/pi-web"
if [[ -d "$parent_dir" ]]; then
rmdir "$parent_dir" 2>/dev/null || true
fi
}
# ── Clean up stale npm temp dirs ────────────────────────────────────
cleanup_npm_temps() {
local pattern="${HOME}/.pi/agent/npm/node_modules/@ygncode/.pi-web-*"
local count=0
for d in $pattern; do
if [[ -d "$d" ]]; then
rm -rf "$d"
count=$((count + 1))
fi
done
if [[ $count -gt 0 ]]; then
info "Cleaned up ${count} stale npm temp dir(s)"
fi
}
# ── Remove macOS launchd plist ─────────────────────────────────────
remove_macos_plist() {
local plist="${HOME}/Library/LaunchAgents/com.pi-web.plist"
if [[ -f "$plist" ]]; then
info "Removing launchd plist: ${plist}"
rm -f "$plist"
else
skip "launchd plist not found"
fi
}
# ── Remove Linux systemd service ────────────────────────────────────
remove_linux_service() {
local service="${HOME}/.config/systemd/user/pi-web.service"
if [[ -f "$service" ]]; then
info "Removing systemd user service: ${service}"
# Disable first (while the unit file still exists) to clear the
# default.target.wants symlink that `systemctl --user enable` created;
# removing the file alone would leave a dangling symlink.
systemctl --user disable pi-web.service 2>/dev/null || true
rm -f "$service"
systemctl --user daemon-reload 2>/dev/null || true
else
skip "systemd service not found"
fi
}
# ── Main ────────────────────────────────────────────────────────────
main() {
echo ""
info "pi-web uninstaller"
echo ""
stop_service
remove_binary
remove_version_file
remove_state
cleanup_npm_temps
case "$(uname -s)" in
Darwin) remove_macos_plist ;;
Linux) remove_linux_service ;;
esac
info "pi-web service and binary removed."
info "Data preserved: ~/.pi/agent/pi-web.sqlite, ~/.pi/agent/pi-web-memory.sqlite, ~/.config/pi-web/env"
echo ""
}
main