-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathfunctions.sh
executable file
·249 lines (239 loc) · 6.01 KB
/
functions.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/bash
log() {
echo -ne "\e[1;34mSSRPARI \e[m" >&2
echo -e "[`date`] $@"
}
installlog() {
echo -ne "\e[1;34mSSRPARI \e[m" >&2
echo -e "$@"
}
YesNo() {
# Usage: YesNo "prompt"
# Returns: 0 (true) if answer is Yes
# 1 (false) if answer is No
while true
do
read -p "$1" answer
case "$answer" in
[nN]*)
answer="1"; break;
;;
[yY]*)
answer="0"; break;
;;
*)
echo "Please answer y or n"
;;
esac
done
return $answer
}
verify() {
if [ $? -ne 0 ]; then
echo "Fatal error encountered: $@"
exit 1
fi
}
tst() {
echo "===> Executing: $*"
if ! $*; then
echo "Exiting script due to error from: $*"
exit 1
fi
}
apt_install() {
log Checking $1...
INSTALLED=`dpkg -l $1 | grep ii`
if [ "$INSTALLED" ]
then
log Dependency $1 already met...
else
log Installing $1...
$INSTALL_COMMAND $1 &> /dev/null
verify "Installation of package '$1' failed"
echo $1 >> "$SSPARI_PATH/installed_deps"
verify "Adding package '$1'to $SSPARI_PATH/installed_deps failed"
fi
}
run(){
log Running $*...
$*
verify "$* failed"
}
exc(){
log Executing $*
$* &> /dev/null
verify "'$*' failed"
}
apt_update() {
log Updating via $*...
$*
verify "'$*' failed"
}
apt_upgrade() {
log Upgrading via $*...
$*
verify "'$*' failed"
}
remove_dir(){
if [ -e "$1" ]; then
if [ -d "$1" ]; then
sudo rm -R $1
else
log $1 is not a directory
fi
fi
}
restore_originals(){
if [ -e "$SSPARI_BACKUP_PATH/files" ]; then
if [ -d "$SSPARI_BACKUP_PATH/files" ]; then
log "Unable to Restore Original Files, $SSPARI_BACKUP_PATH/files is a directory"
else
log Restoring Original Files...
while IFS='' read -r line || [[ -n "$line" ]]; do
FILE=`echo $line | sed "s/=.*//"`
DIR=`echo $line | sed "s/.*=//"`
FINAL="$DIR/$FILE"
log Restoring $FILE to "$FINAL"
sudo cp "$SSPARI_BACKUP_PATH/$FILE" $FINAL
done < "$SSPARI_BACKUP_PATH/files"
fi
else
log "Unable to Restore Original Files, $SSPARI_BACKUP_PATH/files doesn't exist"
fi
}
save_original(){
if [ -e "$1" ]; then
if [ -d "$1" ]; then
log "$1 is a directory"
else
FILE=`echo $1 | sed "s/.*\///"`
echo $FILE
LOC="$SSPARI_BACKUP_PATH/$FILE"
if [ -e "$LOC" ]
then
log "File '$FILE' has been previously backed up"
else
log Saving $1...
DIR=`dirname "$1"`
DIR="$DIR/"
DIRFINAL="$SSPARI_BACKUP_PATH/files"
echo "$FILE=$DIR" | sudo tee -a "$DIRFINAL"
sudo cp $1 "$LOC"
fi
fi
else
log "$1 does not exist"
fi
}
UNINSTALL_COMMAND="sudo apt-get remove -y"
apt_uninstall(){
log Checking $1 for system dependency...
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ "$line" = "$1" ]
then
INSTALLED=`dpkg -l $1 | grep ii`
if [ "$INSTALLED" ]
then
log Uninstalling $1...
$UNINSTALL_COMMAND $1 &> /dev/null
else
log Package $1 was not installed, continuing...
fi
break
fi
done < "$SSPARI_PATH/installed_deps"
verify "Installation of package '$1' failed"
}
rem_files(){
log "Removing File $1..."
sudo rm $1
verify "Removal of file '$1' failed"
}
rem_dir(){
log "Removing Directory $1..."
sudo rm -R $1
verify "Removal of directory '$1' failed"
}
uninstall_bluetooth(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${BT_DEPS[@]}; do
apt_uninstall $_dep;
done
sudo update-rc.d pulseaudio remove
sudo update-rc.d bluetooth-agent remove
sudo rm -R ~/pulseaudio
sudo rm -R ~/libsndfile
sudo rm -R ~/json-c
cd $SSPARI_PATH
}
uninstall_airplay(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${AIRPLAY_DEPS[@]}; do
apt_uninstall $_dep;
done
sudo rm -R //root/pulseaudio
}
uninstall_ap(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${AP_DEPS[@]}; do
apt_uninstall $_dep;
done
}
uninstall_gmedia(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${GMEDIA_DEPS[@]}; do
apt_uninstall $_dep;
done
}
uninstall_kodi(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${KODI_DEPS[@]}; do
apt_uninstall $_dep;
done
rm ~/.hushlogin
}
uninstall_lirc(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${LIRC_DEPS[@]}; do
apt_uninstall $_dep;
done
}
uninstall_snap(){
source $SSPARI_PATH/dependencies.sh
for _dep in ${SNAP_DEPS[@]}; do
apt_uninstall $_dep;
done
sudo systemctl disable snapserver
sudo systemctl disable snapclient
}
remove_sspari_files(){
source $SSPARI_PATH/dependencies.sh
for _file in ${SSPARI_FILES[@]}; do
if [ -d $_file ]; then
if [ -L $_file ]; then
rem_files $_file
else
rem_dir $_file
fi
fi
done
}
full_uninstall(){
# Restore Original Files
restore_originals
# Update Bluetooth to normal system daemon
sudo update-rc.d bluetooth remove
sudo update-rc.d bluetooth defaults
sudo update-rc.d bluetooth enable
remove_sspari_files
# Uninstall Features
uninstall_lirc
uninstall_kodi
uninstall_gmedia
uninstall_ap
uninstall_airplay
uninstall_bluetooth
uninstall_snap
log Uninstall Completed. Reboot to take effect.
}