-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.sh
executable file
·69 lines (56 loc) · 1.65 KB
/
uninstall.sh
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
#!/bin/bash
print_usage() {
echo "Usage: $0 local|system"
exit 1
}
scope=$1
local_installation=false
if [[ "$scope" == "local" ]]; then
echo "uninstalling locally"
local_installation=true
elif [[ "$scope" == "system" ]]; then
echo "uninstalling system-wide"
else
print_usage
fi
# which file to edit?
bashrc="/etc/bash.bashrc"
if $local_installation; then
bashrc="$HOME/.bashrc"
fi
echo "editing file: $bashrc"
# backup
./scripts/install/backup.sh "$scope" "$bashrc"
# Remove cd history paragraph from bashrc
echo "modifying bashrc file..."
start="# FILE HISTORY START"
end="# FILE HISTORY END"
start_found=$(cat "$bashrc" | grep --count "$start")
end_found=$(cat "$bashrc" | grep --count "$end")
# preservers ownership and permissions, uses sudo if 'root' arg is present
# usage: move src target [root]
move()
{
src="$1"
target="$2"
root="$3"
if [[ "$root" == "root" ]];then
sudo install -m "$(stat -c '%a' "$target")" -o "$(stat -c '%U' "$target")" -g "$(stat -c '%G' "$target")" "$src" "$target"
else
install -m "$(stat -c '%a' "$target")" -o "$(stat -c '%U' "$target")" -g "$(stat -c '%G' "$target")" "$src" "$target"
fi
}
if [[ $start_found -gt 0 && $end_found -gt 0 ]]; then
temp_file=$(mktemp)
sed "/$start/,/$end/d" "$bashrc" > "$temp_file"
if $local_installation; then
move "$temp_file" "$bashrc"
else
move "$temp_file" "$bashrc" root
fi
./scripts/install/remove-symlink.sh file-history $scope
echo "successfully uninstalled"
else
echo "start and end pattern not found"
echo "already uninstalled, otherwise remove paragraph manually from $bashrc"
fi