Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·45 lines (41 loc) · 1.46 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·45 lines (41 loc) · 1.46 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
#!/usr/bin/env bash
# ©AngelaMos | 2026
# uninstall.sh
set -euo pipefail
main() {
local prefix="${TEMPLATE_INSTALL_DIR:-}"
case "${1:-}" in
--prefix)
[[ $# -eq 2 && -n "$2" ]] || { printf '%s\n' '--prefix requires a directory' >&2; return 1; }
prefix="$2" ;;
-h|--help)
printf '%s\n' 'Usage: bash uninstall.sh [--prefix DIR]' 'Removes the installed release command. Local development symlinks are preserved.'
return 0 ;;
"") ;;
*) printf '%s\n' 'Unknown option' >&2; return 1 ;;
esac
python3 - "$prefix" <<'PY'
import json
from pathlib import Path
import shutil
import sys
import zipfile
located = shutil.which("template")
path = Path(sys.argv[1]).expanduser() / "template" if sys.argv[1] else Path(located or Path.home() / ".local/bin/template")
if path.is_symlink():
raise SystemExit("Local development symlink preserved")
if not path.exists():
print("template is already uninstalled")
raise SystemExit(0)
try:
with zipfile.ZipFile(path) as archive:
metadata = json.loads(archive.read("release.json"))
if "archives" not in metadata:
raise ValueError("not a template release")
except (OSError, ValueError, KeyError, zipfile.BadZipFile):
raise SystemExit(f"Refusing to remove an unrelated command: {path}") from None
path.unlink()
print("template uninstalled. Shared PATH entries and generated projects were preserved.")
PY
}
main "$@" </dev/null