forked from davecrump/winterhill
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·247 lines (203 loc) · 7.94 KB
/
update.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
#!/bin/bash
# Updated by davecrump 202103080 for WinterHill
reset
echo "------------------------------------------------"
echo "------ Commencing WinterHill Update ------------"
echo "------------------------------------------------"
echo
cd /home/pi
## Check which update to load
GIT_SRC_FILE=".wh_gitsrc"
if [ -e ${GIT_SRC_FILE} ]; then
GIT_SRC=$(</home/pi/${GIT_SRC_FILE})
else
GIT_SRC="BritishAmateurTelevisionClub"
fi
# Define Location of Dev version
GIT_DEV="davecrump" # G8GKQ
#GIT_DEV="foxcube" # G4EWJ
## If previous version was Dev, load production by default
if [ "$GIT_SRC" == "$GIT_DEV" ]; then
GIT_SRC="BritishAmateurTelevisionClub"
fi
if [ "$1" == "-d" ]; then
echo "Overriding to update to latest development version"
GIT_SRC=$GIT_DEV
fi
if [ "$GIT_SRC" == "BritishAmateurTelevisionClub" ]; then
echo "Updating to latest Production WinterHill build";
elif [ "$GIT_SRC" == "$GIT_DEV" ]; then
echo "Updating to latest development WinterHill build";
else
echo "Updating to latest ${GIT_SRC} development WinterHill build";
fi
echo
echo "------------------------------------------------"
echo "-- Making Sure that WinterHill is not running --"
echo "------------------------------------------------"
echo
pgrep winterhill
WHRUNS=$?
while [ $WHRUNS = 0 ]
do
PID=$(pgrep winterhill | head -n 1)
echo $PID
sudo kill "$PID"
sleep 1
PID=$(pgrep winterhill | head -n 1)
echo $PID
sudo kill -9 "$PID"
pgrep winterhill
WHRUNS=$?
done
echo "------------------------------------------------"
echo "-- Making a Back-up of the User Configuration --"
echo "------------------------------------------------"
echo
PATHINI="/home/pi/winterhill"
PATHUBACKUP="/home/pi/user_backups"
mkdir "$PATHUBACKUP" >/dev/null 2>/dev/null
# Note previous version number
cp -f -r /home/pi/winterhill/installed_version.txt "$PATHUBACKUP"/prev_installed_version.txt
# Make a safe copy of the user .ini file
cp -f -r "$PATHINI"/winterhill.ini "$PATHUBACKUP"/winterhill.ini
echo
echo "Updating the OS and Installed Packages"
echo
sudo dpkg --configure -a # Make sure that all the packages are properly configured
sudo apt-get clean # Clean up the old archived packages
sudo apt-get update --allow-releaseinfo-change # Update the package list
sudo apt-get -y dist-upgrade # Upgrade all the installed packages to their latest version
# --------- Install new packages as Required ---------
# Add code here to install any new packages required by updates
# --------- Now update WinterHill ---------
echo
echo "Updating the WinterHill Software"
echo
cd /home/pi
# Delete the previous winterhill code
rm -rf winterhill >/dev/null 2>/dev/null
echo "--------------------------------------------------"
echo "---- Downloading the new WinterHill Software -----"
echo "--------------------------------------------------"
echo
cd /home/pi
wget https://github.com/${GIT_SRC}/winterhill/archive/main.zip
unzip -o main.zip
mv winterhill-main winterhill
rm main.zip
BUILD_VERSION=$(</home/pi/winterhill/latest_version.txt)
sudo chown pi /home/pi/winterhill/whlog.txt # Will be owned by root in some conditions
echo UPDATE WinterHill update started version $BUILD_VERSION >> /home/pi/winterhill/whlog.txt
echo UPDATE from $GIT_SRC repository >> /home/pi/winterhill/whlog.txt
# spi driver may need rebuilding after OS update
echo "--------------------------------------------"
echo "---- Rebuilding spi driver for install -----"
echo "--------------------------------------------"
echo
cd /home/pi/winterhill/whsource-3v20/whdriver-3v20
make
if [ $? != 0 ]; then
echo "------------------------------------------"
echo "- Failed to build the WinterHill Driver --"
echo "------------------------------------------"
echo UPDATE Failed to build the WinterHill Driver >> /home/pi/winterhill/whlog.txt
exit
fi
# Remove any old drivers, and the current one
# Add current driver to this list after a driver update
sudo rmmod whdriver-2v22.ko >/dev/null 2>/dev/null
sudo rmmod whdriver-3v20.ko >/dev/null 2>/dev/null
# Load the new driver
sudo insmod whdriver-3v20.ko
if [ $? != 0 ]; then
echo "------------------------------------------"
echo "--- Failed to load WinterHill Driver -----"
echo "------------------------------------------"
echo UPDATE Failed to load the WinterHill Driver >> /home/pi/winterhill/whlog.txt
exit
fi
cat /proc/modules | grep -q 'whdriver_3v20'
if [ $? != 0 ]; then
echo "-----------------------------------------------------"
echo "--- Failed to find new loaded WinterHill Driver -----"
echo "-----------------------------------------------------"
echo UPDATE Failed to find the new loaded WinterHill Driver >> /home/pi/winterhill/whlog.txt
exit
else
echo
echo "------------------------------------------------"
echo "--- Successfully loaded WinterHill Driver -----"
echo "------------------------------------------------"
echo UPDATE Successfully loaded WinterHill Driver >> /home/pi/winterhill/whlog.txt
echo
fi
cd /home/pi
#echo "----------------------------------------------------"
#echo "---- Set up to load the new spi driver at boot -----"
#echo "----------------------------------------------------"
#echo
# A new sed line will be required here when the driver name is changed
# sudo sed -i "/^exit 0/c\cd /home/pi/winterhill/whsource-3v20/whdriver-3v20\nsudo insmod whdriver-3v20.ko\nexit 0" /etc/rc.local
echo "---------------------------------------------------"
echo "---- Building the main WinterHill Application -----"
echo "---------------------------------------------------"
echo
cd /home/pi/winterhill/whsource-3v20/whmain-3v20
make
if [ $? != 0 ]; then
echo "----------------------------------------------"
echo "- Failed to build the WinterHill Application -"
echo "----------------------------------------------"
echo UPDATE Failed to build the WinterHill Application >> /home/pi/winterhill/whlog.txt
exit
fi
cp winterhill-3v20 /home/pi/winterhill/RPi-3v20/winterhill-3v20
cd /home/pi
echo "--------------------------------------"
echo "---- Building the PIC Programmer -----"
echo "--------------------------------------"
echo
cd /home/pi/winterhill/whsource-3v20/whpicprog-3v20
./make.sh
if [ $? != 0 ]; then
echo "--------------------------------------"
echo "- Failed to build the PIC Programmer -"
echo "--------------------------------------"
echo UPDATE Failed to build the PIC Programmer >> /home/pi/winterhill/whlog.txt
exit
fi
cp whpicprog-3v20 /home/pi/winterhill/PIC-3v20/whpicprog-3v20
cd /home/pi
# Any desktop shortcuts needing replacement will need deleting here
# rm /home/pi/Desktop/WH_Local
# rm /home/pi/Desktop/WH_Anyhub
# rm /home/pi/Desktop/WH_Anywhere
# rm /home/pi/Desktop/WH_Multihub
# rm /home/pi/Desktop/PIC_Prog
#echo "------------------------------------------------"
#echo "---- Copy the new shortcuts to the desktop -----"
#echo "------------------------------------------------"
#echo
#cp /home/pi/winterhill/configs/WH_Local /home/pi/Desktop/WH_Local
#cp /home/pi/winterhill/configs/WH_Anyhub /home/pi/Desktop/WH_Anyhub
#cp /home/pi/winterhill/configs/WH_Anywhere /home/pi/Desktop/WH_Anywhere
#cp /home/pi/winterhill/configs/WH_Multihub /home/pi/Desktop/WH_Multihub
#cp /home/pi/winterhill/configs/PIC_Prog /home/pi/Desktop/PIC_Prog
# Note previous version number
cp -f -r "$PATHUBACKUP"/prev_installed_version.txt /home/pi/winterhill//prev_installed_version.txt
# Restore the user .ini file
cp -f -r "$PATHUBACKUP"/winterhill.ini "$PATHINI"/winterhill.ini
# Update the version number
cp -f -r /home/pi/winterhill/latest_version.txt /home/pi/winterhill/installed_version.txt
# Save (overwrite) the git source used
echo "${GIT_SRC}" > /home/pi/${GIT_SRC_FILE}
echo "--------------------"
echo "---- Rebooting -----"
echo "--------------------"
echo UPDATE Reached the end of the update script >> /home/pi/winterhill/whlog.txt
sleep 1
# Turn off swap to prevent reboot hang
sudo swapoff -a
sudo shutdown -r now # Seems to be more reliable than reboot
exit