-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·69 lines (50 loc) · 1.39 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
#!/bin/bash
downloadFile() {
echo "Downloading $1 to $(pwd)/$2"
curl -C - -L -k -# $1 > $2
[[ $? == 0 ]] || exit 1
}
getVariable() {
echo $(grep "$1" "$2" | tr " " "\n" | tail -n 1 | sed 's/[";]//g')
}
DIRNAME="$1"
PACKAGE="$2"
FILENAME="$3"
if [[ "$DIRNAME" != "" && "$PACKAGE" != "" && "$FILENAME" != "" ]]; then
CONSTANTS="$DIRNAME/java/$(echo $PACKAGE | sed 's/\./\//g')/$FILENAME"
PROTOCOL=$(getVariable "PROTOCOL" "$CONSTANTS")
HOST=$(getVariable "HOST" "$CONSTANTS")
INDEX=$(getVariable "PATH" "$CONSTANTS")
else
echo "Invalid parameters passed"
exit 1
fi
SERVER="$PROTOCOL//$HOST"
WWW="$DIRNAME/assets/www"
echo "Server set to $SERVER"
# Remove old files
rm -rf $WWW
mkdir -p $WWW
# Get index file
downloadFile "$SERVER/$INDEX" "$WWW/$INDEX"
# Get the manifest file
downloadFile "$SERVER/manifest.appcache" "$WWW/manifest.appcache"
# Read the manifest appcache
ISCACHE=false
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ $line =~ [A-Z]+: ]]; then
if [[ $line == "CACHE:" ]]; then
ISCACHE=true
else
if [[ $ISCACHE == true ]]; then
ISCACHE=false
break
fi
fi
continue
fi
if [[ $ISCACHE == true && $line ]]; then
mkdir -p "$WWW/${line%/*}"
downloadFile "$SERVER/$line" "$WWW/$line"
fi
done < "$WWW/manifest.appcache"