-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck_for_update.sh
executable file
·137 lines (126 loc) · 5.17 KB
/
check_for_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
#!/bin/bash
reset
## Check which version number to look up. From M0DNY 201905090
GIT_SRC_FILE=".ryde_gitsrc"
if [ -e ${GIT_SRC_FILE} ]; then
GIT_SRC=$(</home/pi/${GIT_SRC_FILE})
else
GIT_SRC="BritishAmateurTelevisionClub"
fi
## If version was Dev (davecrump), check production version number
if [ "$GIT_SRC" == "davecrump" ]; then
GIT_SRC="BritishAmateurTelevisionClub"
fi
## Download the latest_version file
cd /home/pi/ryde-build
rm /home/pi/ryde-build/latest_version.txt >/dev/null 2>/dev/null
wget --timeout=2 https://raw.githubusercontent.com/${GIT_SRC}/ryde-build/master/latest_version.txt
## Create the file if it doesn't exist
if [ ! -f "latest_version.txt" ]; then
echo '000000000' > latest_version.txt
fi
## Check the file has a valid format (first 2 characters are 20)
CHECK=$(head -c 2 latest_version.txt)
if [ $CHECK -ne "20" ]; ## If not a valid version number
then ## then check the internet connection
ping 8.8.8.8 -c1 >/dev/null 2>/dev/null
if [ $? -eq "0" ]; ## If ping to Google successful
then
printf "Unable to connect to GitHub to check the latest version.\n\n"
printf "There is a working internet connection,\n"
printf "but GitHub is not responding or being blocked.\n\n"
printf "Try connecting to: \n\nhttps://raw.githubusercontent.com/BritishAmateurTelevisionClub/ryde-build/master/latest_version.txt\n\n"
printf "in a web browser on another computer on the same network to diagnose the fault.\n"
else ## If ping to Google unsuccesful
printf "Unable to connect to the internet\n"
printf "Please check your internet connection and then try again\n"
fi
printf "\nPress any key to return to the main menu\n"
read -n 1
exit
fi
## Format OK, so check against installed version
LATESTVERSION=$(head -c 9 latest_version.txt)
rm /home/pi/ryde-build/latest_version.txt >/dev/null 2>/dev/null
## Check installed version
INSTALLEDVERSION=$(head -c 9 /home/pi/ryde-build/installed_version.txt)
cd /home/pi
## Compare versions
if [ $LATESTVERSION -eq $INSTALLEDVERSION ]; ## No need for upgrade
then
printf "The installed version "$INSTALLEDVERSION" is the latest available\n\n"
printf "Do you want to force an upgrade now? (y/n)\n"
read -n 1
printf "\n"
if [[ "$REPLY" = "y" || "$REPLY" = "Y" ]]; then ## Force upgrade requested
printf "\nUpgrading now...\n"
cd /home/pi
rm update.sh >/dev/null 2>/dev/null
wget https://raw.githubusercontent.com/BritishAmateurTelevisionClub/ryde-build/master/update.sh
chmod +x update.sh
/home/pi/update.sh
exit
elif [[ "$REPLY" = "d" || "$REPLY" = "D" ]]; then ## Development upgrade requested
printf "\nUpgrading now to the Development Version...\n"
cd /home/pi
rm update.sh >/dev/null 2>/dev/null
wget https://raw.githubusercontent.com/davecrump/ryde-build/master/update.sh
chmod +x update.sh
/home/pi/update.sh -d
exit
else ## Force upgrade not required
printf "Not upgrading\n"
sleep 2
fi
exit
fi
if [ $LATESTVERSION -gt $INSTALLEDVERSION ]; ## Upgrade available
then
printf "The installed version is "$INSTALLEDVERSION".\n"
printf "The latest version is "$LATESTVERSION" do you want to upgrade now? (y/n)\n"
read -n 1
printf "\n"
if [[ "$REPLY" = "y" || "$REPLY" = "Y" ]]; ## Upgrade requested
then
printf "\nUpgrading now...\n"
cd /home/pi
rm update.sh >/dev/null 2>/dev/null
wget https://raw.githubusercontent.com/BritishAmateurTelevisionClub/ryde-build/master/update.sh
chmod +x update.sh
source /home/pi/update.sh
exit
else ## Upgrade available, but rejected
printf "Not upgrading\n"
printf "The installed version is "$INSTALLEDVERSION".\n"
printf "The latest version is "$LATESTVERSION".\n"
sleep 2
fi
else ## Version Error
printf "There has been an error, or the installed version is newer than the published version\n"
printf "The installed version is "$INSTALLEDVERSION".\n"
printf "The latest version is "$LATESTVERSION".\n\n"
printf "Do you want to force an upgrade now? (y/n)\n"
read -n 1
printf "\n"
if [[ "$REPLY" = "y" || "$REPLY" = "Y" ]]; then ## Force upgrade requested
printf "\nUpgrading now...\n"
cd /home/pi
rm update.sh >/dev/null 2>/dev/null
wget https://raw.githubusercontent.com/BritishAmateurTelevisionClub/ryde-build/master/update.sh
chmod +x update.sh
/home/pi/update.sh
exit
elif [[ "$REPLY" = "d" || "$REPLY" = "D" ]]; then ## Development upgrade requested
printf "\nUpgrading now to the Development Version...\n"
cd /home/pi
rm update.sh >/dev/null 2>/dev/null
wget https://raw.githubusercontent.com/davecrump/ryde-build/master/update.sh
chmod +x update.sh
/home/pi/update.sh -d
exit
else ## Force upgrade not required
printf "Not upgrading\n"
sleep 2
fi
exit
fi