Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
87 lines (72 loc) · 2.65 KB
/
Copy pathuninstall.sh
File metadata and controls
87 lines (72 loc) · 2.65 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
#!/usr/bin/env bash
# scripts/linux/uninstall.sh
#
# Idempotent uninstaller for dev-setup.
# - Restores dotfile .bak files created by config/dotfiles/install.sh
# - Removes dev-setup managed blocks from ~/.zshrc and ~/.bashrc
# - Does NOT remove installed tools (nvm, gh, vim, copilot, etc.)
#
# Usage:
# ./scripts/linux/uninstall.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
. "${SCRIPT_DIR}/lib/log.sh"
# -- Restore dotfile .bak files -----------------------------------------------
# Restores the newest timestamped backup (.bak.YYYYMMDD-HHMMSS).
# That is the state just before the most recent install run.
# To recover the original-original, use the oldest .bak.* file manually.
restore_backup() {
local target="$1"
# Prefer newest timestamped backup; fall back to legacy .bak
local newest
# shellcheck disable=SC2012
newest=$(ls -t "${target}.bak."* 2>/dev/null | head -n 1) || newest=''
if [[ -n "$newest" ]]; then
mv "$newest" "$target"
log_ok "Restored $target from $(basename "$newest")"
elif [[ -f "${target}.bak" ]]; then
mv "${target}.bak" "$target"
log_ok "Restored $target from ${target}.bak (legacy)"
else
log_warn "No backup found for $target"
fi
}
printf '\ndev-setup uninstaller\n\n'
# Dotfiles that install.sh may have backed up
DOTFILES=(
"$HOME/.gitconfig"
"$HOME/.npmrc"
"$HOME/.editorconfig"
"$HOME/.aliases"
"$HOME/.vimrc"
)
for dotfile in "${DOTFILES[@]}"; do
restore_backup "$dotfile"
done
# -- Remove managed blocks from shell rc files --------------------------------
remove_managed_block() {
local file="$1"
local begin_marker="# --- dev-setup managed block (do not edit) ---"
local end_marker="# --- end dev-setup managed block ---"
if [[ ! -f "$file" ]]; then
log_warn "$file does not exist"
return
fi
if ! grep -qF "$begin_marker" "$file"; then
log_warn "No dev-setup block in $file"
return
fi
# Remove the managed block (inclusive of markers) and any leading blank line
sed -i.tmp "/$begin_marker/,/$end_marker/d" "$file"
# Clean up the temp file sed creates with -i
rm -f "${file}.tmp"
log_ok "Removed dev-setup block from $file"
}
remove_managed_block "$HOME/.zshrc"
remove_managed_block "$HOME/.bashrc"
# -- Unset core.hooksPath -----------------------------------------------------
git config --unset-all core.hooksPath 2>/dev/null || true
log_ok "core.hooksPath unset (git falls back to per-repo .git/hooks)"
# -- Summary ------------------------------------------------------------------
printf '\n'; log_ok "Uninstalled. Tools (nvm, gh, etc.) remain. Remove them manually if you wish."; printf '\n'