This repository has been archived by the owner on Oct 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versionscheck.sh
199 lines (166 loc) · 4.59 KB
/
versionscheck.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
#!/bin/bash
#versions url
URL="http://phobos.apple.com/versions"
#working directory
#wd="/Users/localadmin/Desktop/iOS"
wd="/Users/Shared/.iOS"
#Save directory
#Sd="/Volumes/Data/ServiceData/%%%%%/iOS/"
#final directory (for sorting with Hazel https://www.noodlesoft.com/ when not using ^Sd^)
Dd=/Users/ladmin/Downloads
#temporary working directory
td="/var/tmp/.iOS"
#Proxy:P0rt
export http_proxy=http://10.xx.yy.zz:8080
export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
#Awesome function for curl retries from http://stackoverflow.com/questions/8350942/how-to-re-run-the-curl-command-automatically-when-the-error-occurs
#credit to https://github.com/phs
function with_backoff {
local max_attempts=${ATTEMPTS-5}
local timeout=${TIMEOUT-1}
local attempt=0
local exitCode=0
while (( $attempt < $max_attempts ))
do
set +e
"$@"
exitCode=$?
set -e
if [[ $exitCode == 0 ]]
then
break
fi
echo "Failure! Retrying in $timeout.." 1>&2
sleep $timeout
attempt=$(( attempt + 1 ))
timeout=$(( timeout * 2 ))
done
if [[ $exitCode != 0 ]]
then
echo "You've failed me for the last time! ($@)" 1>&2
fi
return $exitCode
}
#create working and temporary directories if not there already
if [ ! -d $wd ]; then
mkdir -p $wd;
fi;
chmod -fR 777 $wd
if [ ! -d $td ]; then
mkdir -p $td;
fi;
chmod -fR 777 $td
cd $wd
#check for new versions
if [ ! -f old_versions.xml ]; then
curl -L -o old_versions.xml -s $URL --connect-timeout 20 2>&1;
exit 0
else
curl -L -o new_versions.xml -s $URL --connect-timeout 20 2>&1;
fi
#add file size check to see if it has been updated.
diff new_versions.xml old_versions.xml > /dev/null 2>&1;
if [[ $? -ne 0 ]]; then
echo "updated XML. proceeding."
#Used in testing to remove ispws for download
#sed -i '' "/_9.3.2_/d" old_versions.xml
#List iOS iPads
xmllint --c14n old_versions.xml > 1.xml
xmllint --c14n new_versions.xml > 2.xml
diff 1.xml 2.xml > diff.xml
if [[ $? -ne 0 ]]; then
echo "updated XML. proceeding."
#List iOS iPads
cat ./diff.xml | grep 'http' | grep 'ipsw' | grep 'iPad' | sort -u | cut -d '>' -f 3 | cut -d '<' -f 1 > iPadNewToDownload.txt
#read new links
iPadLinks=`cat iPadNewToDownload.txt`
#List iOS ATVs
cat ./diff.xml | grep 'http' | grep 'ipsw' | grep 'ATV' | sort -u | cut -d '>' -f 3 | cut -d '<' -f 1 > ATVNewToDownload.txt
#read new links
ATVLinks=`cat ATVNewToDownload.txt`
#List iOS iPhones
cat ./diff.xml | grep 'http' | grep 'ipsw' | grep 'iPhone' | sort -u | cut -d '>' -f 3 | cut -d '<' -f 1 > iPhoneNewToDownload.txt
#read new links
iPhoneLinks=`cat iPhoneNewToDownload.txt`
#List iOS iPod
cat ./diff.xml | grep 'http' | grep 'ipsw' | grep 'iPod' | sort -u | cut -d '>' -f 3 | cut -d '<' -f 1 > iPodNewToDownload.txt
#read new links
iPodLinks=`cat iPodNewToDownload.txt`
#List iOS watch
# cat ./diff.xml | grep 'http' | grep 'ipsw' | grep 'watch' | sort -u | cut -d '>' -f 3 | cut -d '<' -f 1 > iwatchNewToDownload.txt
#read new links
#iwatchLinks=`cat iwatchNewToDownload.txt`
#cleanup diffs and xml
if [ -f 1.xml ]; then
rm 1.xml
fi
if [ -f 2.xml ]; then
rm 2.xml
fi
if [ -f diff.xml ]; then
rm diff.xml
fi
if [ -f iPadNewToDownload.xml ]; then
rm iPadNewToDownload.txt
fi
if [ -f ATVNewToDownload.xml ]; then
rm ATVNewToDownload.txt
fi
if [ -f iPhoneNewToDownload.xml ]; then
rm iPhoneNewToDownload.txt
fi
if [ -f iPodNewToDownload.xml ]; then
rm iPodNewToDownload.txt
fi
#if [ -f 2.xml ]; then
#rm iwatchNewToDownload.txt
#fi
mv new_versions.xml old_versions.xml
#Move to tepmorary directory to download. If we loose power, we dont want half downloaded files taking up space.
#My site always looses power
cd $td
#download links list
#move ipsw's to folder for auto sorting with Hazel https://www.noodlesoft.com/
for url in $iPadLinks; do
with_backoff curl -O "$url" -s --connect-timeout 20 2>&1
file=`echo ${url##*/}`
mv $td/$file $Dd/
chmod 777 $Dd/$file
done
for url in $ATVLinks; do
with_backoff curl -O "$url" -s --connect-timeout 20 2>&1
file=`echo ${url##*/}`
mv $td/$file $Dd/
chmod 777 $Dd/$file
done
#for url in $iPodLinks; do
#with_backoff curl -O "$url" -s --connect-timeout 20 2>&1
#file=`echo ${url##*/}`
#mv $td/$file $Dd/
#chmod 777 $Dd/$file
#done
#for url in $iPhoneLinks; do
#with_backoff curl -O "$url" -s --connect-timeout 20 2>&1
#file=`echo ${url##*/}`
#mv $td/$file $Dd/
#chmod 777 $Dd/$file
#done
#for url in $iwatchLinks; do
#with_backoff curl -O "$url" -s --connect-timeout 20 2>&1
#file=`echo ${url##*/}`
#mv $td/$file $Dd/
#chmod 777 $Dd/$file
#done
else
echo "No change"
date
exit 0
fi
else
echo "No change"
date
exit 0
fi
exit 0