-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathuninstall.sh
209 lines (186 loc) · 5.69 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
mudpi_dir="/home/mudpi"
mudpi_user="www-data"
rasp_version=`sed 's/\..*//' /etc/debian_version`
webroot_dir="/var/www/html"
user=$(whoami)
# Determine Raspbian version
version_msg="Unknown Raspbian Version"
if [ "$rasp_version" -eq "10" ]; then
version_msg="Raspbian 10.0 (Buster)"
php_package="php7.3-cgi"
elif [ "$rasp_version" -eq "9" ]; then
version_msg="Raspbian 9.0 (Stretch)"
php_package="php7.2-cgi" # might be version 7.0 CHECK ME
elif [ "$rasp_version" -lt "9" ]; then
echo "Raspbian ${rasp_version} is unsupported. Please upgrade."
exit 1
fi
function log_info() {
echo -e "\033[1;32mMudPi Uninstall: $*\033[m"
}
function log_error() {
echo -e "\033[1;37;41mMudPi Uninstall Error: $*\033[m"
exit 1
}
function confirm_uninstall() {
log_info "The Following System Info was Detected"
echo "Detected ${version_msg}"
echo "Install directory: ${mudpi_dir}"
echo "Web directory: ${webroot_dir}"
echo -n "Proceed with MudPi Uninstall? [y/N]: "
read answer < /dev/tty
if [[ $answer != "y" ]]; then
echo "Uninstall aborted."
exit 0
fi
}
function restore_backups() {
if [ -d "$mudpi_dir/backups" ]; then
if [ -f "$mudpi_dir/backups/interfaces" ]; then
echo -n "Restore interfaces file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo cp "$mudpi_dir/backups/interfaces" /etc/network/interfaces
fi
fi
if [ -f "$mudpi_dir/backups/hostapd.conf" ]; then
echo -n "Restore hostapd configuration file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo cp "$mudpi_dir/backups/hostapd.conf" /etc/hostapd/hostapd.conf
fi
fi
if [ -f "$mudpi_dir/backups/dnsmasq.conf" ]; then
echo -n "Restore dnsmasq configuration file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo cp "$mudpi_dir/backups/dnsmasq.conf" /etc/dnsmasq.conf
fi
fi
if [ -f "$mudpi_dir/backups/dhcpcd.conf" ]; then
echo -n "Restore dhcpcd.conf file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo cp "$mudpi_dir/backups/dhcpcd.conf" /etc/dhcpcd.conf
fi
fi
if [ -f "$mudpi_dir/backups/rc.local" ]; then
echo -n "Restore rc.local file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo cp "$mudpi_dir/backups/rc.local" /etc/rc.local
fi
fi
fi
if [ -f "$mudpi_dir/backups/cron" ]; then
echo -n "Restore cron file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo crontab -u "$user" "$mudpi_dir/backups/cron"
fi
fi
if [ -f "$mudpi_dir/backups/cron_root" ]; then
echo -n "Restore root cron file from backup? [y/N]: "
read answer < /dev/tty
if [[ $answer -eq 'y' ]]; then
sudo crontab "$mudpi_dir/backups/cron_root"
fi
fi
}
function remove_mudpi_directories() {
log_info "Removing MudPi Directories..."
if [ ! -d "$mudpi_dir" ]; then
log_error "MudPi directory not found."
fi
if [ ! -d "$webroot_dir/mudpi" ]; then
echo "MudPi UI directory not found."
fi
if [ ! -d "$webroot_dir/mudpi_assistant" ]; then
echo "MudPi Assistant directory not found."
fi
sudo rm -rf "$webroot_dir"/mudpi*
sudo rm /etc/nginx/sites-enabled/mudpi_ui.conf
sudo rm /etc/nginx/sites-enabled/mudpi_assistant.conf
sudo rm /etc/nginx/sites-enabled/assistant_redirect.conf
sudo rm /etc/nginx/sites-available/mudpi_ui.conf
sudo rm /etc/nginx/sites-available/mudpi_assistant.conf
sudo rm /etc/nginx/sites-available/assistant_redirect.conf
sudo rm -rf "$mudpi_dir"
}
function remove_mudpi_scripts() {
if [ ! -f "/usr/bin/auto_hotspot" ]; then
echo "MudPi auto AP Mode not found."
fi
if [ ! -f "/usr/bin/start_hotspot" ]; then
echo "MudPi start_hotspot not found."
fi
if [ ! -f "/usr/bin/stop_hotspot" ]; then
echo "MudPi stop_hotspot not found."
fi
sudo rm -rf /usr/bin/stop_hotspot
sudo rm -rf /usr/bin/start_hotspot
sudo rm -rf /usr/bin/auto_hotspot
}
function remove_dependancy_packages() {
log_info "Removing installed dependacy packages"
echo -n "Remove the following installed packages? ffmpeg $php_package hostapd dnsmasq htop [Y/n]: "
read answer < /dev/tty
if [ "$answer" != 'n' ] && [ "$answer" != 'N' ]; then
echo "Removing packages."
sudo apt-get remove ffmpeg $php_package hostapd dnsmasq htop
sudo apt-get autoremove
else
echo "Leaving dependancy packages installed."
fi
}
function remove_nginx() {
log_info "Removing web server"
echo -n "Remove nginx and disable web server? (You may have other sites!) [Y/n]: "
read answer < /dev/tty
if [ "$answer" != 'n' ] && [ "$answer" != 'N' ]; then
echo "Removing nginx."
sudo apt-get remove nginx mariadb-server mariadb-client
sudo apt-get autoremove
else
echo "Leaving nginx installed."
fi
}
function remove_supervisor() {
log_info "Removing supervisor"
echo -n "Remove supervisor and disable running jobs? (You may have other jobs!) [Y/n]: "
read answer < /dev/tty
if [ "$answer" != 'n' ] && [ "$answer" != 'N' ]; then
echo "Removing supervisor."
sudo apt-get remove supervisor
sudo apt-get autoremove
else
sudo rm -rf /etc/supervisor/conf.d/mudpi*
echo "Leaving supervisor installed."
fi
}
function clean_sudoers_file() {
# should this check for only our commands?
sudo sed -i '/www-data/d' /etc/sudoers
}
function clean_hosts_file() {
# should this check for only our commands?
sudo sed -i '/#MUDPI/d' /etc/hosts
sudo sed -i "s/mudpi/raspberrypi/g" /etc/hosts
}
function clean_hostname_file() {
sudo sed -i "s/mudpi/raspberrypi/g" /etc/hostname
}
function uninstall_mudpi() {
confirm_uninstall
restore_backups
remove_mudpi_directories
remove_mudpi_scripts
remove_dependancy_packages
remove_nginx
remove_supervisor
clean_sudoers_file
clean_hosts_file
clean_hostname_file
}
uninstall_mudpi