forked from telmomarques/xiaomi-360-1080p-hacks
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbuild
executable file
·151 lines (122 loc) · 2.86 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
#!/bin/bash
github_download_release_asset() {
local owner=$1
local repository=$2
local tagName=$3
local assetName=$4
is_200_ok=$(wget -q --show-progress --server-response https://github.com/${owner}/${repository}/releases/download/${tagName}/${assetName} 2>&1 | grep -c 'HTTP/1.1 200 OK')
if [ $is_200_ok != "1" ]; then
echo "Failed to get ${assetName}"
exit 1
fi
}
download_from_url() {
local assetName=$1
is_200_ok=$(wget -q --show-progress --server-response ${1} 2>&1 | grep -c 'HTTP/1.1 200 OK')
if [ $is_200_ok != "1" ]; then
echo "Failed to get ${assetName}"
exit 1
fi
}
process_external_download() {
local url=$1
local filename=$2
echo Downloading \"${url}\"
download_from_url ${url}
}
process_github_release_asset_download() {
local owner=$1
local repository=$2
local assetName=$3
if [ $releaseType == "dev" ]; then
tagName="latest-rc"
fi
if [ $releaseType == "final" ]; then
tagName="latest"
fi
echo Downloading \"${owner}/${repository}@${tagName}/${assetName}\"
github_download_release_asset ${owner} ${repository} ${tagName} ${assetName}
}
extract() {
local fileName=${1}
case "$fileName" in
*.zip)
echo Extracting ${fileName}
extract_zip ${fileName}
rm -f ${assetFilename}
;;
*.tar)
echo Extracting ${fileName}
extract_tar ${fileName}
rm -f ${assetFilename}
;;
esac
}
extract_zip() {
unzip -qq ${1}
}
extract_tar() {
tar -xf ${1}
}
process_build_file() {
local buildType=$1
local buildFilePath=.build
local source=$(cat ${buildFilePath} | jq -r ".source")
local assetFilename=""
if [ "${source}" == "external" ]; then
local url=$(cat ${buildFilePath} | jq -r ".url")
assetFilename=$(cat ${buildFilePath} | jq -r ".filename")
process_external_download ${url} ${assetFilename}
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}
fi
rm $buildFilePath
if [[ ! -z ${assetFilename} ]]; then
extract ${assetFilename}
fi
if [ -d "uclibc" ]; then
cp uclibc/* .
rm -rf libc uclibc
fi
}
clean() {
echo "Cleaning..."
rm -rf dist
}
build() {
echo "Building..."
test -d dist || mkdir dist
cp -r sdcard/* dist/
shopt -s globstar
for buildFile in dist/**/.build; do
pushd $(dirname ${buildFile})
process_build_file ${1}
popd
done
}
package() {
pushd dist
zip -r sdcard.zip * -x hacks/**/libc -x hacks/**/uclibc
popd
}
main() {
local target=$1
case ${target} in
clean)
clean
;;
dev | rc | final)
releaseType=$1
clean
build
package
;;
*)
echo "Invalid target '${1}'"
;;
esac
}
main $1