-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssistNowDownloader.sh
executable file
·72 lines (64 loc) · 1.92 KB
/
AssistNowDownloader.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
#!/bin/bash
# Saves downloaded data to $2
function getOnlineData() {
sv1="https://${1}-live1.services.u-blox.com/GetOnlineData.ashx?token=${token};gnss=${gnss};datatype=${datatype};format=$format;";
sv2="https://${1}-live2.services.u-blox.com/GetOnlineData.ashx?token=${token};gnss=${gnss};datatype=${datatype};format=$format;";
if ( curl "$sv1" -o "$2" 2> /dev/null ); then
header=$(dd if="$2" ibs=2 count=1 2> /dev/null | xxd -ps);
echo "$header";
if [ "$header" == "b562" ]; then
echo "File \"$2\" downloaded successfully from server1 (live1.services.u-blox.com)."
return 0;
fi
elif ( curl "$sv2" -o "$2" 2> /dev/null ); then
header=$(dd if="$2" ibs=2 count=1 2> /dev/null | xxd -ps);
if [ "$header" == "b562" ]; then
echo "File \"$2\" downloaded successfully from server2 (live1.services.u-blox.com)."
return 0;
fi
else
echo "Download failed, please check your internet connection and try again.";
return 1;
fi
}
function checkAndDownload() {
if ! [[ -f "$2" ]]; then
echo "File doesnt exist";
getOnlineData $1 $2;
return 1;
elif [[ $(date +%s -r "$2") -gt $(date +%s --date="2 hours ago") ]]; then
echo "File exists and is less than 2 hours old, use -f to force the download anyway";
return 1;
else
getOnlineData $1 $2;
fi
return 0;
}
token="IzTVkQZ8EUyTEfHy5qPGuQ";
gnss="gps,glo";
datatype="eph,alm,aux";
format="mga";
FORCE=false;
while getopts t:f opt
do case "$opt" in
t) TYPE="$OPTARG";;
f) FORCE=true;;
[?])
printf "Usage: $0\n\t-f: Force re-download\n\t-t [online|offline]: set type\n";
exit 1;;
esac
done
if [[ "$TYPE" != "online" && "$TYPE" != "offline" ]]; then
echo "Type must be either \"online\" or \"offline\", closing.";
exit 1;
else
FILE="AssistNow_$TYPE.bin";
echo "$FORCE"
if [ "$FORCE" == true ]; then
getOnlineData $TYPE $FILE;
exit $?;
else
checkAndDownload $TYPE $FILE;
exit $?;
fi
fi