forked from telmomarques/xiaomi-360-1080p-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
175 lines (138 loc) · 3.53 KB
/
build
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
#!/bin/bash
github_download_release_asset() {
local owner=$1
local repository=$2
local tagName=$3
local assetName=$4
local destPath=$5
local query="{ \
\"query\": \" \
query { \
repository(owner:\\\"${owner}\\\" name:\\\"${repository}\\\") { \
release(tagName:\\\"${tagName}\\\") { \
releaseAssets(name:\\\"${assetName}\\\" first:1) { \
edges { \
node { \
downloadUrl \
} \
} \
} \
} \
} \
} \
\"} \
"
curl -s -H "Authorization: bearer $THAT_HASH" -X POST -d "${query}" https://api.github.com/graphql |
jq -r ".data.repository.release.releaseAssets.edges[0].node.downloadUrl" |
xargs wget -q --show-progress -P ${destPath}
}
download_from_url()
{
local url=$1
local destPath=$2
wget -q --show-progress -O "${destPath}" ${url}
}
process_external_download()
{
local url=$1
local filename=$2
local destPath=$3
local destFilename=${destPath}/${filename}
echo Downloading \"${url}\" to \"${destFilename}\"
download_from_url ${url} ${destFilename}
}
process_github_release_asset_download()
{
local owner=$1
local repository=$2
local assetName=$3
local destPath=$4
local tagName="latest"
if [ $releaseType == "rc" ]; then
tagName="latest-rc"
fi
echo Downloading \"${owner}/${repository}@${tagName}/${assetName}\" to \"${destPath}/$assetName\"
github_download_release_asset ${owner} ${repository} ${tagName} ${assetName} ${destPath}
}
extract_zip()
{
zipFile=$1
echo Extracting ${zipFile}
unzip -qq ${zipFile} -d `dirname ${zipFile}`
rm -f ${zipFile}
}
process_build_file()
{
local buildFilePath=$1
local source=`cat ${buildFilePath} | jq -r ".source"`
local destinationPath=`dirname ${buildFilePath}`
local assetFilename=""
if [ "${source}" == "external" ]; then
local url=`cat ${buildFilePath} | jq -r ".url"`
assetFilename=`cat ${buildFilePath} | jq -r ".filename"`
process_external_download ${url} ${assetFilename} ${destinationPath}
elif [ "${source}" == "github-release-asset" ]; then
local owner=`cat ${buildFilePath} | jq -r ".owner"`
local repository=`cat ${buildFilePath} | jq -r ".repository"`
assetFilename=`cat ${buildFilePath} | jq -r ".assetName"`
process_github_release_asset_download ${owner} ${repository} ${assetFilename} ${destinationPath}
fi
if [ ! -z "${assetFilename}" ]; then
local assetFileExtension="${assetFilename##*.}"
if [ "${assetFileExtension}" == "zip" ]; then
extract_zip ${destinationPath}/${assetFilename}
fi
fi
}
clean()
{
echo "Cleaning..."
shopt -s globstar
for buildFile in ./**/.build
do
local dirname=`dirname ${buildFile}`
echo "Cleaning ${dirname}"
local deleteArray=(`cat ${buildFile} | jq -c ".assetName"`)
local deleteRules=`cat ${buildFile} | jq -c ".clean"`
if [ ${deleteRules} != "null" ]; then
deleteArray=(`cat ${buildFile} | jq ".clean[]"`)
fi
for file in "${deleteArray[@]}"; do
rm -rf ${dirname}/${file:1:-1}
done
done
echo "Cleaning package"
rm -f sdcard.zip
}
build()
{
echo "Building..."
shopt -s globstar
for buildFile in ./**/.build
do
process_build_file ${buildFile}
done
}
package()
{
zip -r sdcard.zip sdcard -x sdcard/**/.build
}
main()
{
local target=$1
case ${target} in
clean)
clean
;;
rc | final)
releaseType=$1
clean
build
package
;;
*)
echo "Invalid target '${1}'"
;;
esac
}
main $1