forked from Zabrimus/VDRSternELEC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·403 lines (340 loc) · 13.1 KB
/
build.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/bin/bash
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
WHITE='\033[0;37m'
RESET='\033[0m'
PROGNAME=$0
ROOTDIR=`pwd`
# path to https://github.com/LibreELEC.tv/release-scripts
RELEASESCRIPTDIR="release-scripts"
# releases directory
RELEASEDIR="$ROOTDIR/releases"
usage() {
cat << EOF >&2
Usage: $PROGNAME -config <name> [Options]
-config : Build the distribution defined in directory config/distro/<name> (mandatory)
Options:
-extra <name,name> : Build additional plugins / Use optional VDR patches / Use extra from config/extras.list
(option is followed by a comma-separated list of the available extras below)
-addon <name,name> : Build additional addons which will be pre-installed / Use addon from config/addons.list
(option is followed by a comma-separated list of the available addons below)
-subdevice : Build only images for the desired subdevice. This speeds up building images.
-addononly : Build only the desired addons
-patchonly : Only apply patches and build nothing
-package <name> : Build <name> as a single package
-release <server> : Create release for update, accessible at <server>
-releaseonly : Build only the release tar and not all images
-cef : Include cef binaries into release, otherwise deploy it as an external package
-cebootlabel : Change CoreELEC bootlabel to value of "-config"
-verbose : Enable verbose outputs while building LE/CE packages
-help : Show this help
EOF
echo
echo "Available configs:"
ls config/distro
echo
echo "Available extras:"
cat config/extras.list | grep -v ^[#] | grep . | cut -d ":" -f 1
echo
echo "Available addons:"
cat config/addons.list | grep -v ^[#] | grep . | cut -d ":" -f 1
echo
exit 1
}
checkout() {
cd $ROOTDIR
if [ ! -f $DISTRO/.git ]; then
git submodule update --init -- $DISTRO
fi
cd $DISTRO
git clean -fd
git reset --hard
cd ..
git submodule update --recursive --remote $DISTRO
BUILD_SUFFIX=
cd $DISTRO
# Checkout defined commit
if [ ! "x$SHA" = "x" ]; then
git checkout $SHA
else
echo -e "${RED}ERROR: ${DISTRO} SHA not found${RESET}"
exit 1;
fi
if [ ! "x$VARIANT" = "x" ]; then
BUILD_SUFFIX="$VARIANT"
fi
}
checkout_release_script() {
cd $ROOTDIR
if [ ! -f $RELEASESCRIPTDIR/.git ]; then
git submodule update --init -- $RELEASESCRIPTDIR
fi
cd $RELEASESCRIPTDIR
git clean -fd
git reset --hard
cd ..
git submodule update --recursive --remote $RELEASESCRIPTDIR
cd $RELEASESCRIPTDIR
# Checkout defined commit
if [ ! "x$RELEASESHA" = "x" ]; then
git checkout $RELEASESHA
else
echo -e "${RED}ERROR: release-scripts SHA not found${RESET}"
exit 1;
fi
cd ..
}
apply_patches() {
cd $ROOTDIR
cd $DISTRO
rm -f ../patches/${DISTRO}/01-build-debug.patch
if [ $VERBOSEBUILD ]; then
cp ../patches/01-build-debug.patch.disabled ../patches/${DISTRO}/01-build-debug.patch
fi
# Apply patches and sed scripts in ./patches
for i in `find ../patches -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT}/devices/${DEVICE} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT}/devices/${DEVICE}/variants/${VARIANT} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT}/devices/${DEVICE} -maxdepth 1 -name '*.patch' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT}/devices/${DEVICE}/variants/${VARIANT} -maxdepth 1 -name '*.patch' 2>/dev/null`; do
echo "Apply patch $i"
patch -p1 < $i
done
for i in `find ../patches -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT}/devices/${DEVICE} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}/projects/${PROJECT}/devices/${DEVICE}/variants/${VARIANT} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT}/devices/${DEVICE} -maxdepth 1 -name '*.sh' 2>/dev/null` \
`find ../patches/${DISTRO}.${PATCHDIR}/projects/${PROJECT}/devices/${DEVICE}/variants/${VARIANT} -maxdepth 1 -name '*.sh' 2>/dev/null`; do
echo "Apply script $i"
bash $i
done
# delete patch after it was applied to not accidently push it
rm -f ../patches/${DISTRO}/01-build-debug.patch
# Copy package patches to LE/CE directory structure
cd $ROOTDIR
for i in $(find package_patches/${DISTRO} -type f 2>/dev/null) \
$(find package_patches/${DISTRO}.${PATCHDIR} -type f 2>/dev/null); do
PDIR=${i//$DISTRO.$PATCHDIR/$DISTRO}
if [ ! -d $(echo $PDIR | sed -e s/^"package_patches\/"// -e s/$(basename $PDIR)$//) ]; then
mkdir -p $(echo $PDIR | sed -e s/^"package_patches\/"// -e s/$(basename $PDIR)$//)
echo "Create directory $(echo $PDIR | sed -e s/^"package_patches\/"// -e s/$(basename $PDIR)$//)"
fi
if cp -r $i $(echo $PDIR | sed -e s/^"package_patches\/"//); then
echo "Copy $(basename $i) to $(echo $PDIR | sed -e s/^"package_patches\/"//)"
else
echo "ERROR copying $(basename $i) to $(echo $PDIR | sed -e s/^"package_patches\/"//)"
fi
done
if [ "$DISTRO" = "CoreELEC" ] && [ "$CEBOOTLABEL" = "true" ]; then
for i in $(find CoreELEC/projects/Amlogic-ce/devices -name "*_boot.ini"); do
echo "sed -i -e \"s/setenv bootlabel \"CoreELEC\"/setenv bootlabel \"$CONFIG\"/\" \"$i\""
sed -i -e "s/setenv bootlabel \"CoreELEC\"/setenv bootlabel \"$CONFIG\"/" $i
done
fi
}
prepare_sources() {
cd $ROOTDIR
if [ ! -d sources ]; then
mkdir sources
fi
if [ ! -d $DISTRO/sources ]; then
cd $DISTRO
ln -s ../sources sources
fi
}
build_addons() {
if [ ! "${PACKAGE_ONLY}" = "" ]; then
echo "Building single package, skip addons"
return
fi
cd $ROOTDIR/$DISTRO
# delete old build artifacts
rm -Rf target/*
# addons must be build before the final build is started
for i in $(env | grep ^ADDON_); do
TMP=$(echo $i | cut -d "=" -f 1)
if [ $(grep $TMP$ ../config/addons.list) ]; then
# save DISTRO before starting the build (name clash, LE/CE uses also DISTRO, but the problem exists currently only with Github Workflows)
OLD_DISTRO=$DISTRO
unset DISTRO
echo "Start building addon ${!TMP} ..."
PROJECT="$PROJECT" \
DEVICE="$DEVICE" \
ARCH="$ARCH" \
BUILD_SUFFIX="$BUILD_SUFFIX" \
scripts/create_addon ${!TMP} || echo -e "${RED}Addon ${!TMP} failed to build!${RESET}"
PROJECT="$PROJECT" \
DEVICE="$DEVICE" \
ARCH="$ARCH" \
BUILD_SUFFIX="$BUILD_SUFFIX" \
scripts/install_addon ${!TMP} || echo -e "${RED}Addon ${!TMP} failed to build!${RESET}"
DISTRO=$OLD_DISTRO
unset OLD_DISTRO
fi
done
}
build() {
# build
if [ ! "${PACKAGE_ONLY}" = "" ]; then
echo "Build ${PACKAGE_ONLY}"
scripts/build ${PACKAGE_ONLY}
else
RELEASE_STRING="Start make image"
if [ "$DORELEASE" = "true" ]; then
RELEASE_STRING="${RELEASE_STRING} and release it to ${RELEASE_SERVER}"
fi
echo "${RELEASE_STRING}"
# save DISTRO before starting the build (name clash, LE/CE uses also DISTRO, but the problem exists currently only with Github Workflows)
OLD_DISTRO=$DISTRO
unset DISTRO
if [ "$RELEASE_ONLY" = "true" ]; then
make release
else
make image
fi
DISTRO=$OLD_DISTRO
unset OLD_DISTRO
fi
}
set_env() {
# export project variables
cd $ROOTDIR/$DISTRO
echo "Build environment variables:"
echo " PROJECT=$PROJECT"
echo " DEVICE=$DEVICE"
echo " ARCH=$ARCH"
if [ "${DISTRO}" = "CoreELEC" ] && [ ! -z $SUB_DEVICE ]; then
# patch option to build only the desired subdevice
sed -i -e "s#SUBDEVICES=.*\$#SUBDEVICES=\"$SUB_DEVICE\"#" projects/Amlogic-ce/devices/Amlogic-ng/options
echo " SUBDEVICES=${SUB_DEVICE}"
elif [ "${DISTRO}" = "LibreELEC.tv" ] && [ ! -z $SUB_DEVICE ]; then
export UBOOT_SYSTEM="${SUB_DEVICE}"
echo " UBOOT_SYSTEM=${SUB_DEVICE}"
fi
echo " BUILD_SUFFIX=$BUILD_SUFFIX"
echo " VDR_OUTPUTDEVICE=$VDR_OUTPUTDEVICE"
echo " VDR_INPUTDEVICE=$VDR_INPUTDEVICE"
export PROJECT="$PROJECT"
export DEVICE="$DEVICE"
export ARCH="$ARCH"
export BUILD_SUFFIX="$BUILD_SUFFIX"
export VDR_OUTPUTDEVICE="$VDR_OUTPUTDEVICE"
export VDR_INPUTDEVICE="$VDR_INPUTDEVICE"
if [ "$DORELEASE" = "true" ]; then
echo " BUILD_PERIODIC=nightly"
export BUILD_PERIODIC="nightly"
fi
# resize system partition if we want to include the cef binaries
export CEF_BINARIES="$CEF_BINARIES"
if [ "${DISTRO}" = "CoreELEC" ] && [ ! "${CEF_BINARIES}" = "" ]; then
sed -i -e "s#SYSTEM_SIZE=.*\$#SYSTEM_SIZE=1024#" distributions/CoreELEC/options
echo " SYSTEM_SIZE=768"
elif [ "${DISTRO}" = "LibreELEC.tv" ] && [ ! "${CEF_BINARIES}" = "" ]; then
sed -i -e "s#SYSTEM_SIZE=.*\$#SYSTEM_SIZE=1024#" distributions/LibreELEC/options
echo " SYSTEM_SIZE=768"
fi
}
read_extra() {
extras=($(echo $1 | tr "," "\n"))
for i in "${extras[@]}"; do
extra=($(grep -R ^$i: config/extras.list | grep -v ^[#] | tr ":" "\n"))
if [ ! "x$extra" = "x" ]; then
export $(echo ${extra[1]})=y
echo "extras: use '$i', set environment variable $(env | grep ${extra[1]})"
else
echo -e "${RED}ERROR: extras: '$i' not found, stopping build${RESET}"
exit 1
fi
done
}
read_addon() {
addons=($(echo $1 | tr "," "\n"))
for i in "${addons[@]}"; do
addon=($(grep -R ^$i: config/addons.list | grep -v ^[#] | tr ":" "\n"))
if [ ! "x$addon" = "x" ]; then
# digital_devices can be build only for x86_64
if [ "${addon[1]}" = "ADDON_DIGITAL_DEVICES" ] && [ ! "$ARCH" = "x86_64" ]; then
echo -e "${RED}Addon digital_devices is only possible for ARCH x86_64. Skip build.${RESET}"
continue
fi
export $(echo ${addon[1]})=$(echo ${addon[0]})
echo "addons: use '$i', set environment variable $(env | grep ${addon[1]})"
else
echo -e "${RED}ERROR: addons: '$i' not found, stopping build${RESET}"
exit 1
fi
done
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-config) shift; CONFIG=$1 ;;
-extra) shift; read_extra $1 ;;
-addon) shift; read_addon $1 ;;
-subdevice) shift; SUB_DEVICE=$1 ;;
-addononly) ADDON_ONLY=true ;;
-patchonly) PATCH_ONLY=true ;;
-package) shift; PACKAGE_ONLY=$1 ;;
-release) shift; RELEASE_SERVER=$1; DORELEASE=true ;;
-releaseonly) RELEASE_ONLY=true ;;
-cef) CEF_BINARIES=true ;;
-cebootlabel) CEBOOTLABEL=true ;;
-verbose) VERBOSEBUILD=true ;;
-help) usage ;;
*) echo "Unknown parameter passed: $1"; usage ;;
esac
shift || continue
done
if [ "x$CONFIG" = "x" ]; then
usage
fi
if [ ! -f config/distro/$CONFIG ]; then
echo -e "${RED}Config file '$CONFIG' not found${RESET}"
echo
usage
fi
. config/versions
echo "Read config $CONFIG"
. config/distro/$CONFIG
if [ ! -d $DISTRO ]; then
echo -e "${RED}ERROR: Distribution '$DISTRO' cannot be found.${RESET}"
exit 1
fi
if [ "$DORELEASE" = "true" ] && [ -z "${RELEASE_SERVER}" ]; then
echo -e "${RED}ERROR: Building a release was triggered, but RELEASE_SERVER is missing. Stopping build!${RESET}"
exit 1
fi
echo "Build $SHA on $DISTRO"
checkout
apply_patches
prepare_sources
set_env
if [ ! "${PATCH_ONLY}" = "true" ]; then
build_addons
if [ ! "${ADDON_ONLY}" = "true" ]; then
build
fi
if [ "$DORELEASE" = "true" ]; then
checkout_release_script
if [ -e "$RELEASESCRIPTDIR/releases.py" ]; then
echo "Prepare Release for $RELEASE_SERVER in $RELEASEDIR"
mkdir -p $RELEASEDIR
for i in `find $DISTRO/target -name '*.tar' 2>/dev/null` \
`find $DISTRO/target -name '*.tar.sha256' 2>/dev/null` \
`find $DISTRO/target -name '*.img.gz' 2>/dev/null` \
`find $DISTRO/target -name '*.img.gz.sha256' 2>/dev/null` \
`find $DISTRO/target/addons -name '*.zip' 2>/dev/null`; do
mv -f $i $RELEASEDIR
done
python3 $RELEASESCRIPTDIR/releases.py -i $RELEASEDIR -u $RELEASE_SERVER -o $RELEASEDIR
fi
fi
fi