forked from axx8676/PLCnext-file-swap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
95 lines (81 loc) · 2.96 KB
/
install.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
#!/bin/bash
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/plcnext/appshome/bin
# check for swap folder
if [ -d /opt/plcnext/SDCardSwap ]; then
while true; do
# ask user if they want to install Swap
read -p "SDCardSwap folder detected, would you like to install Swap? {y|n} " yn
case $yn in
# install swap
y) echo "Running script to install SDCardSwap. Please wait."
# copy Swap script to more accessible folder
echo "Installing Swap and setting permissions"
cp -a /opt/plcnext/SDCardSwap/Swap.sh /opt/plcnext/
chmod 777 /opt/plcnext/Swap.sh
# copy cron job to cron folder, and add it to crontab
echo "Setting up DetectReboot cronjob"
cp -a -n /opt/plcnext/SDCardSwap/DetectReboot /var/spool/cron/
sudo crontab /var/spool/cron/DetectReboot
# copy udev rules to rules folder, and reload rules to apply changes
echo "Setting up udev rules"
cp -a /opt/plcnext/SDCardSwap/99-automount.rules /etc/udev/rules.d/
cp -a /opt/plcnext/SDCardSwap/99-swap.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
# create startup flag file, so reboot is not required before swapping
touch /var/volatile/tmp/change_flag_set
echo "Installation complete"
break
;;
# don't install swap
n) echo "Not installing SDCardSwap."
break
;;
# prompt user again
*) echo "Invalid response, please enter y or n"
;;
esac
done
fi
# check for upload folder
if [ -d /opt/plcnext/Upload ]; then
while true; do
# ask user if they want to install Upload
read -p "Upload folder detected, would you like to install Upload? {y|n} " yn
case $yn in
# install upload
y) echo "Running script to install Upload. Please wait."
# copy Upload script to more accessible folder
echo "Installing Upload and setting permissions"
cp -a /opt/plcnext/Upload/Upload.sh /opt/plcnext/
chmod 777 /opt/plcnext/Upload.sh
# copy inotify to more accessible folder
echo "Installing inotify and setting permissions"
cp -a /opt/plcnext/Upload/inotify.sh /opt/plcnext
chmod 777 /opt/plcnext/inotify.sh
# copy cron job to cron folder, and add it to crontab
echo "Setting up DetectReboot cronjob"
cp -a /opt/plcnext/Upload/DetectReboot /var/spool/cron/
sudo crontab /var/spool/cron/DetectReboot
# copy udev rule to rules folder, and reload rules to apply changes
echo "Setting up udev rules"
cp -a /opt/plcnext/Upload/99-automount.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
# install inotify package, and depends packages
echo "Installing necessary packages for inotify"
cd /opt/plcnext/Upload/packages
dpkg --install --force-all *.deb
# start inotify script, so upload can be used immediately
echo "Installation complete, starting inotify watch"
/opt/plcnext/inotify.sh
break
;;
# don't install upload
n) echo "Not installing Upload"
break
;;
# prompt user again
*) echo "Invalid response, please enter y or n"
;;
esac
done
fi