-
Notifications
You must be signed in to change notification settings - Fork 102
/
build.sh
executable file
·391 lines (361 loc) · 13.7 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
#!/bin/bash
# Volumio Image Builder
# Copyright Michelangelo Guarise - Volumio.org
#
# TODO: Add gé credits
#
# Dependencies:
# parted squashfs-tools dosfstools multistrap qemu binfmt-support qemu-user-static kpartx
#Set fonts for Help.
NORM=$(tput sgr0)
BOLD=$(tput bold)
REV=$(tput smso)
ARCH=none
PACKAGES="git squashfs-tools kpartx multistrap qemu-user-static samba debootstrap parted dosfstools qemu binfmt-support qemu-utils docker.io md5deep"
#Help function
function HELP {
echo "
Help documentation for Volumio Image Builder
Basic usage: ./build.sh -b arm -d pi -v 2.0
Switches:
-b <arch> Build a full system image with Multistrap.
Options for the target architecture are 'arm' (Raspbian), 'armv7' (Debian arm64), 'armv8' (Debian arm64) or 'x86' (Debian i386).
-d Create Image for Specific Devices. Supported device names:
pi, udooneo, udooqdl, cuboxi, cubietruck, compulab,
odroidc1, odroidc2, odroidxu4, sparky, bbb, pine64,
bpim2u, bpipro, tinkerboard, sopine64, rock64, voltastream0, nanopi64,
nanopineo2, nanopineo, nanopineo
-v <vers> Version must be a dot separated number. Example 1.102 .
-l <repo> Create docker layer. Give a Docker Repository name as the argument.
-p <dir> Optionally patch the builder. <dir> should contain a tree of
files you want to replace within the build tree. Experts only.
Example: Build a Raspberry PI image from scratch, version 2.0 :
./build.sh -b arm -d pi -v 2.0 -l reponame
"
exit 1
}
# Auto check and install prerequisite packages
function check_sysreq {
echo "Auto check and install prerequisite packages"
REQ_STATE=$(dpkg -l $PACKAGES | grep "un ")
if [ -n "$REQ_STATE" ]; then
echo "Start installing packages."
apt update
apt -y install $PACKAGES
fi
echo "Build continues."
}
#$1 = ${BUILD} $2 = ${VERSION} $3 = ${DEVICE}"
function check_os_release {
ARCH_BUILD=$1
HAS_VERSION=$(grep -c VOLUMIO_VERSION "build/${ARCH_BUILD}/root/etc/os-release")
VERSION=$2
DEVICE=$3
if [ "$HAS_VERSION" -ne "0" ]; then
# os-release already has a VERSION number
# cut the last 2 lines in case other devices are being built from the same rootfs
head -n -2 "build/${ARCH_BUILD}/root/etc/os-release" > "build/${ARCH_BUILD}/root/etc/tmp-release"
mv "build/${ARCH_BUILD}/root/etc/tmp-release" "build/${ARCH_BUILD}/root/etc/os-release"
fi
echo "VOLUMIO_VERSION=\"${VERSION}\"" >> "build/${ARCH_BUILD}/root/etc/os-release"
echo "VOLUMIO_HARDWARE=\"${DEVICE}\"" >> "build/${ARCH_BUILD}/root/etc/os-release"
}
#Check the number of arguments. If none are passed, print help and exit.
NUMARGS=$#
if [ "$NUMARGS" -eq 0 ]; then
HELP
fi
while getopts b:v:d:l:p:t:e FLAG; do
case $FLAG in
b)
BUILD=$OPTARG
;;
d)
DEVICE=$OPTARG
;;
v)
VERSION=$OPTARG
;;
l)
#Create docker layer
CREATE_DOCKER_LAYER=1
DOCKER_REPOSITORY_NAME=$OPTARG
;;
p)
PATCH=$OPTARG
;;
h) #show help
HELP
;;
t)
VARIANT=$OPTARG
;;
/?) #unrecognized option - show help
echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed."
HELP
;;
esac
done
shift $((OPTIND-1))
echo "Checking whether we are running as root"
if [ "$(id -u)" -ne 0 ]; then
echo "Please run the build script as root"
exit
fi
if [ -z "${VARIANT}" ]; then
VARIANT="volumio"
fi
if [ -n "$BUILD" ]; then
check_sysreq
CONF="recipes/$BUILD.conf"
if [ "$BUILD" = arm ] || [ "$BUILD" = arm-dev ]; then
ARCH="armhf"
BUILD="arm"
echo "Building ARM Base System with Raspbian"
elif [ "$BUILD" = armv7 ] || [ "$BUILD" = armv7-dev ]; then
ARCH="armhf"
BUILD="armv7"
echo "Building ARMV7 Base System with Debian"
elif [ "$BUILD" = armv8 ] || [ "$BUILD" = armv8-dev ]; then
ARCH="arm64"
BUILD="armv8"
echo "Building ARMV8 (arm64) Base System with Debian"
elif [ "$BUILD" = x86 ] || [ "$BUILD" = x86-dev ]; then
echo 'Building X86 Base System with Debian'
ARCH="i386"
BUILD="x86"
elif [ ! -f recipes/$BUILD.conf ]; then
echo "Unexpected Base System architecture '$BUILD' - aborting."
exit
fi
if [ -d "build/$BUILD" ]; then
echo "Build folder exists, cleaning it"
rm -rf "build/$BUILD"
elif [ -d build ]; then
echo "Build folder exists, leaving it"
else
echo "Creating build folder"
mkdir build
fi
mkdir "build/$BUILD"
mkdir "build/$BUILD/root"
multistrap -a "$ARCH" -f "$CONF"
if [ ! "$BUILD" = x86 ]; then
echo "Build for arm/armv7/armv8 platform, copying qemu"
cp /usr/bin/qemu-arm-static "build/$BUILD/root/usr/bin/"
fi
cp scripts/volumioconfig.sh "build/$BUILD/root"
mount /dev "build/$BUILD/root/dev" -o bind
mount /proc "build/$BUILD/root/proc" -t proc
mount /sys "build/$BUILD/root/sys" -t sysfs
echo 'Cloning Volumio Node Backend'
if [ -n "$PATCH" ]; then
echo "Cloning Volumio with all its history"
git clone https://github.com/volumio/Volumio2.git build/$BUILD/root/volumio
else
git clone --depth 1 -b master --single-branch https://github.com/volumio/Volumio2.git build/$BUILD/root/volumio
fi
echo "Pre-commit hooks"
echo '#!/bin/sh
# Pre-commit hook, uncomment when finished linting all codebase
#npm run lint-staged' > "build/$BUILD/root/volumio/.git/hooks/pre-commit"
echo 'Cloning Volumio Classic UI'
git clone --depth 1 -b dist --single-branch https://github.com/volumio/Volumio2-UI.git "build/$BUILD/root/volumio/http/www"
echo 'Cloning Volumio Contemporary UI'
git clone --depth 1 -b dist3 --single-branch https://github.com/volumio/Volumio2-UI.git "build/$BUILD/root/volumio/http/www3"
echo "Adding os-release infos"
{
echo "VOLUMIO_BUILD_VERSION=\"$(git rev-parse HEAD)\""
echo "VOLUMIO_FE_VERSION=\"$(git --git-dir "build/$BUILD/root/volumio/http/www/.git" rev-parse HEAD)\""
echo "VOLUMIO_BE_VERSION=\"$(git --git-dir "build/$BUILD/root/volumio/.git" rev-parse HEAD)\""
echo "VOLUMIO_ARCH=\"${BUILD}\""
} >> "build/$BUILD/root/etc/os-release"
rm -rf build/$BUILD/root/volumio/http/www/.git
rm -rf build/$BUILD/root/volumio/http/www3/.git
if [ ! "$BUILD" = x86 ]; then
chroot "build/$BUILD/root" /bin/bash -x <<'EOF'
su -
./volumioconfig.sh
EOF
else
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
chroot "build/$BUILD/root" /volumioconfig.sh
fi
echo "Base System Installed"
rm "build/$BUILD/root/volumioconfig.sh"
###Dirty fix for mpd.conf TODO use volumio repo
cp volumio/etc/mpd.conf "build/$BUILD/root/etc/mpd.conf"
CUR_DATE=$(date)
#Write some Version informations
echo "Writing system information"
echo "VOLUMIO_VARIANT=\"${VARIANT}\"
VOLUMIO_TEST=\"FALSE\"
VOLUMIO_BUILD_DATE=\"${CUR_DATE}\"
" >> "build/${BUILD}/root/etc/os-release"
echo "Unmounting Temp devices"
umount -l "build/$BUILD/root/dev"
umount -l "build/$BUILD/root/proc"
umount -l "build/$BUILD/root/sys"
# Setting up cgmanager under chroot/qemu leaves a mounted fs behind, clean it up
umount -l "build/$BUILD/root/run/cgmanager/fs"
sh scripts/configure.sh -b "$BUILD"
fi
if [ -n "$PATCH" ]; then
echo "Copying Patch to Rootfs"
cp -rp "$PATCH" "build/$BUILD/root/"
else
PATCH='volumio'
fi
case "$DEVICE" in
pi) echo 'Writing Raspberry Pi Image File'
check_os_release "arm" "$VERSION" "$DEVICE"
sh scripts/raspberryimage.sh -v "$VERSION" -p "$PATCH"
;;
cuboxi) echo 'Writing Cubox-i Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/cuboxiimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
cuboxp) echo 'Writing Cubox Pulse Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/cuboxpimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidc1) echo 'Writing Odroid-C1/C1+ Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidc1image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidc2) echo 'Writing Odroid-C2 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidc2image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidc4) echo 'Writing Odroid-C4 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidc4image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidn2) echo 'Writing Odroid-N2 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidn2image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidxu4) echo 'Writing Odroid-XU4 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidxu4image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
odroidx2) echo 'Writing Odroid-X2 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/odroidx2image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
sparky) echo 'Writing Sparky Image File'
check_os_release "arm" "$VERSION" "$DEVICE"
sh scripts/sparkyimage.sh -v "$VERSION" -p "$PATCH" -a arm
;;
bbb) echo 'Writing BeagleBone Black Image File'
check_os_release "arm" "$VERSION" "$DEVICE"
sh scripts/bbbimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
udooneo) echo 'Writing UDOO NEO Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/udooneoimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
udooqdl) echo 'Writing UDOO Quad/Dual Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/udooqdlimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
pine64plus|pine64solts) echo 'Writing Pine64 Model Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/pine64image.sh -v "$VERSION" -p "$PATCH" -a armv7 -m ${DEVICE}
;;
nanopi64) echo 'Writing NanoPI A64 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/nanopi64image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
bpim2u) echo 'Writing BPI-M2U Image File'
check_os_release "arm" "$VERSION" "$DEVICE"
sh scripts/bpim2uimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
bpipro) echo 'Writing Banana PI PRO Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/bpiproimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
armbian_*)
echo 'Writing armbian-based Image File'
check_os_release "arm" "$VERSION" "$DEVICE"
sh scripts/armbianimage.sh -v "$VERSION" -d "$DEVICE" -p "$PATCH"
;;
tinkerboard) echo 'Writing Ausus Tinkerboard Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/tinkerimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
primo) echo 'Writing Volumio Primo Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/primoimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
rock64) echo 'Writing Rock64 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/rock64image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
voltastream0) echo 'Writing PV Voltastream0 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/vszeroimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
aml805armv7) echo 'Writing Amlogic S805 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/aml805armv7image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
aml812armv7) echo 'Writing Amlogic S812 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/aml812armv7image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
aml9xxxarmv7) echo 'Writing AmlogicS9xxx Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/aml9xxxarmv7image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
orangepione|orangepilite|orangepipc) echo 'Writing OrangePi Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/orangepiimage.sh -v "$VERSION" -p "$PATCH" -d "$DEVICE"
;;
x86) echo 'Writing x86 Image File'
check_os_release "x86" "$VERSION" "$DEVICE"
sh scripts/x86image.sh -v "$VERSION" -p "$PATCH";
;;
nanopineo2) echo 'Writing NanoPi-NEO2 armv7 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/nanopineo2image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
nanopineo3) echo 'Writing NanoPi-NEO3 armv7 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/nanopineo3image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
nanopineo) echo 'Writing NanoPi-NEO (Air) Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/nanopineoimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
motivo) echo 'Writing Motivo Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/motivoimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
mp1) echo 'Writing Motivo Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/kvimsimage.sh -v "$VERSION" -p "$PATCH" -a armv7 -m ${DEVICE}
;;
primo) echo 'Writing Primo Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/primoimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
vim1) echo 'Writing VIM1 Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/vim1image.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
hemx8mmini) echo 'Writing hemx8mmini Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/hemx8mminiimage.sh -v "$VERSION" -p "$PATCH" -a armv7
;;
kvim1|kvim2|kvim3) echo 'Writing Khadas Image File'
check_os_release "armv7" "$VERSION" "$DEVICE"
sh scripts/kvimsimage.sh -v "$VERSION" -p "$PATCH" -a armv7 -m ${DEVICE}
;;
esac
#When the tar is created we can build the docker layer
if [ "$CREATE_DOCKER_LAYER" = 1 ]; then
echo 'Creating docker layer'
DOCKER_UID="$(sudo docker import "VolumioRootFS$VERSION.tar.gz" "$DOCKER_REPOSITORY_NAME")"
echo "$DOCKER_UID"
fi