forked from axx8676/PLCnext-file-swap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
96 lines (82 loc) · 2.91 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
#!/bin/bash
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/plcnext/appshome/bin
# check for any files created by Swap installation, and try to delete relevant files
if [ -e /opt/plcnext/Swap.sh ] || [ -e /var/spool/cron/DetectReboot_Swap ] || [ -e /etc/udev/rules.d/99-swap.rules ]; then
while true; do
# ask user if they want to uninstall Swap
read -p "SDCardSwap is currently installed, would you like to uninstall Swap? {y|n} " yn
case $yn in
# uninstall swap
y) echo "Running script to uninstall SDCardSwap. Please wait."
# remove script
echo "Removing Swap.sh"
rm /opt/plcnext/Swap.sh
# remove udev rules and reload rules to apply changes
echo "Removing udev swap rule"
rm /etc/udev/rules.d/99-swap.rules
sudo udevadm control --reload-rules
# remove flag file (may fail if PLC not rebooted)
echo "Removing flag file"
rm /opt/plcnext/just_rebooted
echo "Uninstall complete"
break
;;
# don't uninstall swap
n) echo "Not uninstalling SDCardSwap"
break
;;
# prompt user again
*) echo "Invalid response, please enter y or n"
;;
esac
done
fi
# check for any files created by Upload installation, and try to delete relevant files
if [ -e /opt/plcnext/Upload.sh ] || [ -e /var/spool/cron/DetectReboot_Upload ] || [ -e /opt/plcnext/inotify.sh ]; then
while true; do
# ask user if they want to uninstall Upload
read -p "Upload is currently installed, would you like to uninstall Upload? {y|n} " yn
case $yn in
# uninstall upload
y) echo "Running script to uninstall Upload. Please wait."
# stop inotify
echo "Stopping inotify"
killall inotifywait
# remove scripts
echo "Removing Upload.sh"
rm /opt/plcnext/Upload.sh
echo "Removing inotify.sh"
rm /opt/plcnext/inotify.sh
# remove flag file (may fail if PLC not rebooted since SD card inserted/removed)
echo "Removing flag file"
rm /opt/plcnext/just_rebooted
# uninstall deb packages
dpkg --purge --force-all gcc-10-base:armel
dpkg --purge --force-all inotify-tools
dpkg --purge --force-all libc6:armel
dpkg --purge --force-all libcrypt1:armel
dpkg --purge --force-all libgcc-s1:armel
dpkg --purge --force-all libinotifytools0:armel
echo "Uninstall complete"
break
;;
# don't uninstall upload
n) echo "Not uninstalling Upload"
break
;;
# prompt user again
*) echo "Invalid response, please enter y or n"
;;
esac
done
fi
if [ -e /etc/udev/rules.d/99-automount.rules ] && [ ! -e /opt/plcnext/Swap.sh ] && [ ! -e /opt/plcnext/Upload.sh ]; then
echo "Swap and Upload both uninstalled, removing automount rule"
rm /etc/udev/rules.d/99-automount.rules
sudo udevadm control --reload-rules
fi
if [ -e /var/spool/cron/DetectReboot ] && [ ! -e /opt/plcnext/Swap.sh ] && [ ! -e /opt/plcnext/Upload.sh ]; then
echo "Swap and Upload both uninstalled, removing cronjobs"
rm /var/spool/cron/DetectReboot
rm /var/spool/cron/root
fi