Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·189 lines (167 loc) · 7.7 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·189 lines (167 loc) · 7.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# uninstall.sh
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$ROOT_DIR/lib/install/python.sh"
source "$ROOT_DIR/lib/install/backup.sh"
APHOTIC_TOML="$ROOT_DIR/aphotic.toml"
PURGE_PACKAGES=0
ASSUME_YES=0
# One prompt helper so every question in here has the same answer to --yes.
# --yes means yes to what the prompt itself offers: it restores the backup,
# and it removes the assistant's model, the greeter scaffold and the profile's
# packages if they are there. It never reaches past a guard that exists to
# stop damage, so greetd stays refused while it is the active display manager.
confirm() {
local prompt="$1" answer
if [[ "$ASSUME_YES" == "1" ]]; then
answer="y"
else
read -rep "$prompt" answer
fi
[[ "$answer" == "y" || "$answer" == "Y" ]]
}
while [[ $# -gt 0 ]]; do
case "$1" in
--purge-packages) PURGE_PACKAGES=1; shift ;;
--yes|-y) ASSUME_YES=1; shift ;;
--aphotic-toml) APHOTIC_TOML="$2"; shift 2 ;;
-h|--help)
echo "Usage: ./uninstall.sh [--yes] [--purge-packages] [--aphotic-toml <path>]"
echo
echo " --yes, -y answer every prompt with yes, for a non-interactive run"
exit 0
;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
if [[ ! -f "$APHOTIC_TOML" ]]; then
echo "No aphotic.toml found ($APHOTIC_TOML) — nothing recorded to uninstall."
exit 1
fi
PYTHON_BIN=$(resolve_python_bin)
latest_backup() {
local root
root="$(backup_root)"
[[ -d "$root" ]] || return 1
ls -1 "$root" | sort | tail -n 1
}
restore_latest_backup() {
local latest
latest=$(latest_backup) || { echo "No backups found to restore."; return 1; }
echo "Restoring backup: $latest"
cp -R "$(backup_root)/$latest/." "$HOME/.config/"
}
if ! confirm $'Restore most recent backup? (y,n) '; then
echo "Aborted, no changes made."
exit 0
fi
restore_latest_backup || exit 1
if [[ -L "$HOME/.local/bin/aphotic" ]]; then
rm -f "$HOME/.local/bin/aphotic"
echo "Removed ~/.local/bin/aphotic"
fi
if systemctl --user list-unit-files aphotic-shell.service &>/dev/null; then
systemctl --user disable --now aphotic-shell.service &>/dev/null || true
echo "Disabled aphotic-shell.service"
fi
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
[[ -f "$rc" ]] || continue
sed -i '/# Added by aphotic install.sh so ~\/.local\/bin (aphotic CLI) is on PATH/,+1d' "$rc"
done
ASSISTANT_CONFIG="$HOME/.config/aphotic/ai-config.json"
if [[ -f "$ASSISTANT_CONFIG" ]]; then
ASSISTANT_MODEL=$("$PYTHON_BIN" -c 'import json, sys
try:
data = json.load(open(sys.argv[1]))
except (FileNotFoundError, json.JSONDecodeError):
data = {}
print(data.get("assistantModel", "") if data.get("assistantEnabled") else "")' "$ASSISTANT_CONFIG")
if [[ -n "$ASSISTANT_MODEL" ]]; then
if confirm $"Remove the Aphotic Assistant's pulled model ($ASSISTANT_MODEL)? Your other Ollama models are untouched. (y,n) "; then
if command -v ollama >/dev/null 2>&1; then
ollama rm "$ASSISTANT_MODEL" || echo "Could not remove $ASSISTANT_MODEL via 'ollama rm' -- it may already be gone, or Ollama may not be running."
else
echo "ollama CLI not found; remove $ASSISTANT_MODEL yourself (e.g. via Settings -> AI, or the Ollama API) if it's still pulled."
fi
"$PYTHON_BIN" -c 'import json, sys
path = sys.argv[1]
try:
data = json.load(open(path))
except (FileNotFoundError, json.JSONDecodeError):
data = {}
data["assistantEnabled"] = False
data["assistantModel"] = ""
data["assistantInstalledAt"] = ""
json.dump(data, open(path, "w"), indent=2)' "$ASSISTANT_CONFIG"
echo "Aphotic Assistant removed."
fi
fi
fi
GREETER_DIRS=(/etc/xdg/quickshell/aphotic-greeter /etc/greetd/aphotic /etc/aphotic/greeter)
# The scaffold is keyed off a shell.qml or hyprland-greeter.lua that really
# exists, which is why the branch above never ran in CI: the runner has
# neither. GREETER_PROBE_DIR lets the test point that check at a seeded tree
# so the prompt and the guard it sits behind are covered everywhere, not only
# on a box where Aphotic happens to be installed.
GREETER_PROBE_DIR="${GREETER_PROBE_DIR:-/etc}"
if [[ -f "$GREETER_PROBE_DIR/xdg/quickshell/aphotic-greeter/shell.qml" \
|| -f "$GREETER_PROBE_DIR/greetd/aphotic/hyprland-greeter.lua" ]]; then
# Refuse outright, before ever asking, if greetd is the active display
# manager -- deleting /etc/greetd/aphotic/hyprland-greeter.lua out from
# under a live greetd.service leaves its config.toml pointing at a
# compositor config that no longer exists, and the next boot/VT switch
# gets no login screen at all with no TTY-accessible warning printed in
# advance. Checked here, not just documented after the fact.
GREETD_ACTIVE=0
if systemctl is-enabled greetd.service &>/dev/null || systemctl is-active greetd.service &>/dev/null; then
GREETD_ACTIVE=1
fi
if [[ "$GREETD_ACTIVE" == "1" ]] && pacman -Qq sddm &>/dev/null; then
echo "Putting sddm back as the login screen..."
sudo systemctl disable greetd.service &>/dev/null || true
if [[ -f /etc/greetd/config.toml.aphotic-backup ]]; then
sudo mv /etc/greetd/config.toml.aphotic-backup /etc/greetd/config.toml
fi
sudo systemctl enable sddm.service &>/dev/null && GREETD_ACTIVE=0
fi
# The refusal above is a guard, not a prompt, so --yes does not reach it:
# confirm() is only ever called from this else, never in place of the check.
if [[ "$GREETD_ACTIVE" == "1" ]]; then
echo "greetd is currently enabled/active as the display manager -- not touching the greeter scaffold."
echo "Run 'aphotic displaymanager switch sddm --confirm-tested' first to restore sddm, then re-run uninstall.sh to remove the scaffold."
else
if confirm $'Remove the Aphotic greeter (/etc/xdg/quickshell/aphotic-greeter, /etc/greetd/aphotic, /etc/aphotic/greeter)? sddm is unaffected either way. (y,n) '; then
sudo rm -rf "$GREETER_PROBE_DIR/xdg/quickshell/aphotic-greeter" \
"$GREETER_PROBE_DIR/greetd/aphotic" \
"$GREETER_PROBE_DIR/aphotic/greeter"
systemctl --user disable --now aphotic-greeter-sync.timer &>/dev/null || true
echo "Removed the Aphotic greeter."
fi
fi
fi
if [[ "$PURGE_PACKAGES" == "1" ]]; then
AUR_HELPER=$("$PYTHON_BIN" -c 'import sys, tomllib; print(tomllib.load(open(sys.argv[1], "rb"))["system"]["aur_helper"])' "$APHOTIC_TOML")
if confirm $"This will run $AUR_HELPER -R against every package this profile installed (including custom_apps.lst entries). Continue? (y,n) "; then
PROFILE=$("$PYTHON_BIN" -c 'import sys, tomllib; print(tomllib.load(open(sys.argv[1], "rb"))["install"]["profile"])' "$APHOTIC_TOML")
LAYERS=$("$PYTHON_BIN" -c 'import sys, tomllib; print(",".join(tomllib.load(open(sys.argv[1], "rb"))["install"]["layers"]))' "$APHOTIC_TOML")
layer_args=""
if [[ -n "$LAYERS" ]]; then
IFS=',' read -ra layer_names <<< "$LAYERS"
paths=()
for name in "${layer_names[@]}"; do
paths+=("$ROOT_DIR/profiles/layers/$name.toml")
done
layer_args=$(IFS=,; echo "${paths[*]}")
fi
packages=$("$PYTHON_BIN" "$ROOT_DIR/lib/toml/merge.py" --base "$ROOT_DIR/profiles/base/$PROFILE.toml" --layers "$layer_args" --custom-apps "$ROOT_DIR/profiles/custom_apps.lst" --field main)
while IFS= read -r pkg; do
[[ -n "$pkg" ]] && "$AUR_HELPER" -R --noconfirm "$pkg"
done <<< "$packages"
# Flatpaks ship through Flathub, not pacman. Uninstall them separately.
flatpaks=$("$PYTHON_BIN" "$ROOT_DIR/lib/toml/merge.py" --base "$ROOT_DIR/profiles/base/$PROFILE.toml" --layers "$layer_args" --custom-flatpaks "$ROOT_DIR/profiles/custom_flatpaks.lst" --field flatpak)
while IFS= read -r pkg; do
[[ -n "$pkg" ]] && sudo flatpak uninstall --system -y "$pkg" || true
done <<< "$flatpaks"
fi
fi
echo "Uninstall complete."