-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.sh
executable file
·75 lines (60 loc) · 1.38 KB
/
upload.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
#!/bin/bash
# This file will upload built artifact to CDN
file=$1
target=$2
ost=`uname -u`
os=
if [ "$ost" == "Linux" ]; then
os="linux"
elif [ "$ost" == "Darwin" ]; then
os="darwin"
else
echo "Unsupported operating system: $ost"
exit 10
fi
if [ -z "$file" ]; then
echo "File was not specified"
exit 11
fi
if [ -z "$target" ]; then
echo "Target CDN was not specified"
exit 12
fi
if [ "$target" != "master" ] && [ "$target" != "dev" ] && [ "$target" != "HEAD" ]; then
echo "Specified target is unsupported: $target"
exit 13
fi
if [ ! -e "$file" ]; then
echo "File doesn't exists: $file"
exit 14
fi
extract_id()
{
if [ "$os" == "linux" ]; then
id_src=$(echo $json | grep -Po '"id":".*?[^\\]"')
id=${id_src:6:36}
elif [ "$os" == "darwin" ]; then
id_src=$(echo $json | grep -Po '"id":".*?[^\\]"')
id=${id_src:6:36}
else
echo "Can't extract ID of a file: Unknown OS"
fi
}
stage=
if [ "$target" == "master" ]; then
stage="master"
elif [ "$target" == "dev" ]; then
stage="dev"
elif [ "$target" == "sysnet" ]; then
stage="sysnet"
fi
filename=`basename $file`
json=`curl -k -s -X GET $cdnUrl/raw/info?name=$filename`
echo "Received: $json"
if [ "$json" != "Not Found" ]; then
extract_id
echo "Previous file ID is $id"
else
echo "File not found on CDN. Exiting"
exit 15
fi