Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·98 lines (85 loc) · 1.95 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·98 lines (85 loc) · 1.95 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
#!/usr/bin/env bash
set -Eeuo pipefail
DRY_RUN=0
YES=0
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/thetruezerotwo-dotfiles"
STATE_FILE="$STATE_DIR/install.state"
usage() {
cat <<USAGE
Usage: ./uninstall.sh [options]
Options:
--dry-run Show what would be removed without changing files
--yes Do not ask for confirmation
--help Show this help
USAGE
}
log() { printf '[+] %s\n' "$*"; }
warn() { printf '[!] %s\n' "$*" >&2; }
run() {
if [ "$DRY_RUN" -eq 1 ]; then
printf '[dry-run]'
printf ' %q' "$@"
printf '\n'
else
"$@"
fi
}
confirm() {
if [ "$YES" -eq 1 ]; then
return 0
fi
if [ ! -t 0 ]; then
return 1
fi
local answer
printf '%s [y/N]: ' "$1"
read -r answer
case "$answer" in
y|Y|yes|YES) return 0 ;;
*) return 1 ;;
esac
}
remove_block() {
local file="$1"
[ -f "$file" ] || return 0
if ! grep -q '# >>> TheTrueZeroTwo DotFiles >>>' "$file"; then
return 0
fi
log "Removing source block from $file"
if [ "$DRY_RUN" -eq 1 ]; then
printf '[dry-run] remove managed block from %s\n' "$file"
else
awk '
/# >>> TheTrueZeroTwo DotFiles >>>/ { skip=1; next }
/# <<< TheTrueZeroTwo DotFiles <<</ { skip=0; next }
skip != 1 { print }
' "$file" > "$file.tmp"
mv "$file.tmp" "$file"
fi
}
while [ "$#" -gt 0 ]; do
case "$1" in
--dry-run) DRY_RUN=1 ;;
--yes|-y) YES=1 ;;
--help|-h) usage; exit 0 ;;
*) warn "Unknown option: $1"; usage; exit 1 ;;
esac
shift
done
if ! confirm "Remove TheTrueZeroTwo managed alias files and shell source blocks?"; then
warn "Canceled"
exit 1
fi
remove_block "$HOME/.bashrc"
remove_block "$HOME/.zshrc"
for file in "$HOME/.bash_aliases" "$HOME/.pentesting_aliases"; do
if [ -e "$file" ]; then
log "Removing $file"
run rm -f "$file"
fi
done
if [ -e "$STATE_FILE" ]; then
log "Removing state file $STATE_FILE"
run rm -f "$STATE_FILE"
fi
log "Done. Backups, if any, remain in $STATE_DIR/backups"