-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap.sh
executable file
·565 lines (435 loc) · 14 KB
/
bootstrap.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
#!/bin/bash
#
# ScreenInvader - A shared media experience. Instant and seamless.
# Copyright (C) 2012 Amir Hassan <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
function getConf() {
cat "$1" | tr "\n" " "
}
function makepassword() {
mkpasswd -m sha-512 -s <<< "$1"
}
#KEYRINGS="`getConf config/keyrings`"
PKG_WHITE="`getConf config/packages_white`"
PKG_EXTRA="`getConf config/packages_extra`"
PKG_BLACK="`getConf config/packages_black`"
PKG_BUILD="`getConf config/packages_build`"
FILES_BLACK="`getConf config/files_black`"
export LC_ALL="C"
APTNI="apt-get -q -y --no-install-recommends --force-yes -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" ";
DEBIAN_MIRROR="http://ftp2.de.debian.org/debian/"
dir="`dirname $0`"
BOOTSTRAP_DIR="`cd $dir; pwd`"
BOOTSTRAP_LOG="$BOOTSTRAP_DIR/bootstrap.log"
ARCH=armhf
APTCACHER_PORT=
NOINSTALL=
NODEBOOT=
NOCLEANUP=
KEEP_DEPS=
CHROOT_DIR=
CHRT=
DEBUG=
function printUsage() {
cat 0>&2 <<EOUSAGE
Bootstrap a ScreenInvader file system.
$0 [-a <arch>][-g <num>][-l <logfile>][-p <apt-cacher-port>][-c <configfile>][-i -d -u -x -k -r] <bootstrapdir>
Options:
-a <arch> Bootstrap a system of the given architecture
-l <file> Specify the log file
-p <port> Enables using apt-cacher-ng on the specified port
-i Don't configure and install packages
-d Don't debootstrap
-b Don't rebuild third party
-u Combined -d, -i, -b and -l
-c <file> Specify the config file for non-interactive configuration at first boot
-x Install extra packages for debugging
-k Keep build dependencies and sources
-r Don't rebuild the kernel
EOUSAGE
exit 1
}
function absDir() {
dir="`dirname $1`"
absdir="`cd $dir; pwd`"
echo $absdir
}
function absPath() {
dir="`dirname $1`"
base="`basename $1`"
absdir="`cd $dir; pwd`"
echo $absdir/$base
}
function skip() {
echo -n "$1: "
yellow "skipped\n"
}
function doDebootstrap() {
check "Create target dir" \
"rm -rf \"$CHROOT_DIR\"; mkdir \"$CHROOT_DIR\""
BOOTSTRAP_MIRROR=$DEBIAN_MIRROR
[ -n "$APTCACHER_PORT" ] && BOOTSTRAP_MIRROR=$(
HOST="`echo $BOOTSTRAP_MIRROR | sed 's/^http*:\/\///g' | sed 's/\/.*$//g'`"
echo "http://127.0.0.1:$APTCACHER_PORT/$HOST/debian"
)
check "Bootstrap debian" \
"debootstrap --foreign --variant=minbase --exclude="`echo $PKG_BLACK | sed 's/ /,/g'`" --arch $ARCH jessie "$CHROOT_DIR" $BOOTSTRAP_MIRROR"
if [ $ARCH == "armhf" -a "$(uname -m)" != "armv7l" ]; then
check "Copy qemu-static" \
"cp /usr/bin/qemu-arm-static \"$CHROOT_DIR/usr/bin\""
fi
check "Bootstrap second stage" \
"DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot \"$CHROOT_DIR\" /debootstrap/debootstrap --second-stage"
check "Trigger post install" \
"DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot \"$CHROOT_DIR\" dpkg --configure -a"
}
function doPackageConf() {
export DEBIAN_FRONTEND=noninteractive
check "Prune debconf cache" \
"$CHRT mkdir -p /var/cache/debconf/"
check "Prepare package manager" \
"$CHRT dpkg --configure -a"
pass=$(makepassword "lounge")
check "Add user lounge" \
"$CHRT bash -c \"grep ^lounge: /etc/passwd || useradd -p '$pass' -s /bin/bash -b / -m -g users lounge\""
check "Set root shell to firstboot" \
"$CHRT usermod -p '$pass' -s /setup/firstboot.sh root"
check "Fix dependencies" \
"$CHRT $APTNI install -f"
check "Update Repositories" \
"$CHRT $APTNI update"
check "Copy ScreenInvader repo key" \
"cp $BOOTSTRAP_DIR/repo/ScreenInvaderRepoKey.gpg $CHROOT_DIR/tmp/"
check "Add ScreenInvader repo key" \
"$CHRT apt-key add /tmp/ScreenInvaderRepoKey.gpg"
# check "Install keyrings" \
# "$CHRT $APTNI install $KEYRINGS"
check "Update Repositories" \
"$CHRT $APTNI update"
check "Update apt policy" \
"$CHRT bash -c 'touch /var/lib/apt/lists/*; apt-cache policy'"
check "Install white packages" \
"$CHRT $APTNI install $PKG_WHITE"
if [ $ARCH == "amd64" ]; then
check "Install amd64 kernel" \
"$CHRT $APTNI install linux-image-amd64"
fi
# check "Upgrade packages" \
# "$CHRT $APTNI upgrade"
check "Remove black listed packages" \
"$CHRT $APTNI purge $PKG_BLACK"
}
function doBuildKernel() {
if [ $ARCH == "armhf" ]; then
check "Clone kernel" \
"cd $BOOTSTRAP_DIR/third/; ./clone_kernel.sh"
check "Cross compile kernel" \
"cd $BOOTSTRAP_DIR/third/; ./build_kernel.sh"
fi
}
function doInstallKernel() {
if [ $ARCH == "armhf" ]; then
check "Install modules" \
"cd $BOOTSTRAP_DIR/third/linux-sunxi; make ARCH=arm INSTALL_MOD_PATH=$CHROOT_DIR modules_install"
check "Copy uImage" \
"cp $BOOTSTRAP_DIR/third/linux-sunxi/arch/arm/boot/uImage $CHROOT_DIR/boot/"
fi
}
function doInstallOuttaSpace() {
check "Install outta_space" \
"cd $BOOTSTRAP_DIR/third/outta_space; cp -r * $CHROOT_DIR/lounge/www/"
}
function doBuildOuttaSpace() {
check "Link nodejs to node" \
"$CHRT ln -s /usr/bin/nodejs /usr/bin/node"
check "Clone outta_space" \
"cd $BOOTSTRAP_DIR/third/; ./clone_outta_space.sh"
check "Build outta_space" \
"cd $BOOTSTRAP_DIR/third/; ./build_outta_space.sh"
}
function doBuild() {
check "Update Repositories" \
"$CHRT $APTNI update"
check "Install build dependencies" \
"$CHRT $APTNI install $PKG_BUILD"
if [ $ARCH == "armhf" ]; then
check "Clone uboot-cfg" \
"cd $BOOTSTRAP_DIR/third/; ./clone_uboot-cfg.sh"
check "Clone dri2" \
"cd $BOOTSTRAP_DIR/third/; ./clone_dri2.sh"
check "Clone libvdpau" \
"cd $BOOTSTRAP_DIR/third/; ./clone_libvdpau-sunxi.sh"
check "Clone sunxi-mali" \
"cd $BOOTSTRAP_DIR/third/; ./clone_sunxi-mali.sh"
check "Clone sunxi-tools" \
"cd $BOOTSTRAP_DIR/third/; ./clone_sunxi-tools.sh"
# check "Clone sunxi-tools" \
# "cd $BOOTSTRAP_DIR/third/; ./clone_sunxi-tools.sh"
check "Clone libump" \
"cd $BOOTSTRAP_DIR/third/; ./clone_ump.sh"
check "Clone fbturbo" \
"cd $BOOTSTRAP_DIR/third/; ./clone_xf86-video-fbturbo.sh"
fi
check "Clone janosh" \
"cd $BOOTSTRAP_DIR/third/; ./clone_janosh.sh"
check "Clone SimpleOSD" \
"cd $BOOTSTRAP_DIR/third/; ./clone_simpleosd.sh"
check "Clone lanes" \
"cd $BOOTSTRAP_DIR/third/; ./clone_lanes.sh"
check "Clone luajit-rocks" \
"cd $BOOTSTRAP_DIR/third/; ./clone_luajitrocks.sh"
check "Clone shairport" \
"cd $BOOTSTRAP_DIR/third/; ./clone_shairport.sh"
check "Clone searx" \
"cd $BOOTSTRAP_DIR/third/; ./clone_searx.sh"
check "Clone mpv" \
"cd $BOOTSTRAP_DIR/third/; ./clone_mpv.sh"
check "Copy third party" \
"cp -r $BOOTSTRAP_DIR/third/ \"$CHROOT_DIR\""
if [ $ARCH == "armhf" ]; then
check "Build dri2" \
"$CHRT /third/build_dri2.sh"
check "Build sunxi-mali" \
"$CHRT /third//build_sunxi-mali.sh"
check "Build sunxi-tools" \
"$CHRT /third//build_sunxi-tools.sh"
check "Build uboot-cfg" \
"$CHRT /third//build_uboot-cfg.sh"
# check "build sunxi-tools" \
# "$CHRT /third/build_sunxi-tools.sh"
check "Build xf86-video-fbturbo" \
"$CHRT /third/build_xf86-video-fbturbo.sh"
check "Build libvdpau-sunxi" \
"$CHRT /third/build_libvdpau-sunxi.sh"
fi
check "Build luajit-rocks" \
"$CHRT /third/build_luajitrocks.sh"
check "Build lanes" \
"$CHRT /third/build_lanes.sh"
check "Build janosh" \
"$CHRT /third/build_janosh.sh"
check "Build SimpleOSD" \
"$CHRT /third/build_simpleosd.sh"
check "Build shairport" \
"$CHRT /third/build_shairport.sh"
check "Build searx" \
"$CHRT /third/build_searx.sh"
check "Build mpv" \
"$CHRT /third/build_mpv.sh"
}
function doCopy() {
check "Make install directory" \
"mkdir -p $CHROOT_DIR/install/"
check "Rebuild debian packages" \
"cd $BOOTSTRAP_DIR/packaging/; ./makeall.sh 2.0 $ARCH"
check "Copy debian packages" \
"cp $BOOTSTRAP_DIR/packaging/*.deb $CHROOT_DIR/install/"
check "install core package" \
"$CHRT dpkg -i /install/screeninvader-core-all.deb"
check "install config package" \
"$CHRT dpkg -i --force-all /install/screeninvader-config-all.deb"
check "install misc package" \
"$CHRT dpkg -i --force-all /install/screeninvader-misc-all.deb"
check "install arch package" \
"$CHRT dpkg -i --force-all /install/screeninvader-arch-all.deb"
check "Remove install directory" \
"rm -r $CHROOT_DIR/install/"
# check "Copy plymouth theme" \
# "cp -a $BOOTSTRAP_DIR/themes/screeninvader $CHROOT_DIR/usr/share/plymouth/themes/"
check "ldconfig" \
"$CHRT ldconfig"
# check "Update plymouth theme" \
# "$CHRT plymouth-set-default-theme -R screeninvader"
if [ -n "$CONFIG_FILE" ]; then
check "Copy firstboot config file" \
"cp $CONFIG_FILE \"$CHROOT_DIR/setup/answer.sh\""
fi
}
function doCleanupPackages() {
check "Update Repositories" \
"$CHRT $APTNI update"
check "Autoremove packages" \
"$CHRT $APTNI autoremove"
check "Clean apt cache" \
"$CHRT $APTNI clean"
}
function doCleanupBuildDeps() {
check "remove build dependencies" \
"$CHRT $APTNI remove $PKG_BUILD"
check "remove third " \
"rm -rf \"$CHROOT_DIR/third\""
}
function doCleanupFiles() {
check "Remove black listed files" \
"$CHRT bash -c \"rm -fr $FILES_BLACK\""
}
function doSetupCrontab {
check "Setup crontab" \
"$CHRT bash -c '(crontab -l 2>/dev/null; echo \" 0 * * * * pip install -U youtube-dl\") | crontab -'"
}
function doInstallYoutubeDL {
check "Install youtube-dl" \
"$CHRT pip install youtube-dl"
}
function doPrepareChroot() {
cd "$CHROOT_DIR"
check "Bind chroot dev fs" \
"mount --bind /dev/ dev"
check "Create chroot procs fs" \
"mount -t proc none proc"
check "Create chroot sys fs" \
"mount -t sysfs none sys"
check "Create chroot tmpfs fs" \
"mount -t tmpfs none tmp"
check "Create chroot devpts fs" \
"mount -t devpts none dev/pts"
check "Prune apt directories" \
"mkdir -p \"$CHROOT_DIR/etc/apt/\" \"$CHROOT_DIR/etc/apt/preferences.d/\" \"$CHROOT_DIR/etc/apt/apt.conf.d/\""
check "Make apt sources list" \
"\"$BOOTSTRAP_DIR/templates/sources_list\" \"$DEBIAN_MIRROR\" > \"$CHROOT_DIR/etc/apt/sources.list\""
if [ -n "$APTCACHER_PORT" ]; then
# use apt-cacher-ng to cache packages during install
check "Make apt cacher conf" \
"\"$BOOTSTRAP_DIR/templates/00aptcacher\" \"$APTCACHER_PORT\" > \"$CHROOT_DIR/etc/apt/apt.conf.d/00aptcacher\""
fi
# disable starting daemons after install
check "Prune /usr/sbin" \
"mkdir -p \"$CHROOT_DIR/usr/sbin\""
check "Make policy-rd.d" \
"$BOOTSTRAP_DIR/templates/policy-rc_d > $CHROOT_DIR/usr/sbin/policy-rc.d"
check "Fix policy-rd.d permissions" \
"chmod 755 \"$CHROOT_DIR/usr/sbin/policy-rc.d\""
}
function doFreeChroot() {
pkill -KILL -P $$ &> /dev/null
(
cd "$CHROOT_DIR"
umount dev/pts
umount tmp
umount sys
umount proc
umount dev
umount -l dev
) &>/dev/null
rm -rf "$CHROOT_DIR/etc/apt/apt.conf.d/00aptcacher"
rm -rf "$CHROOT_DIR/usr/sbin/policy-rc.d"
exit
}
function doCheckPreCond() {
check "'debootstrap' installed" \
"which debootstrap"
if [ -n "${CONFIG_FILE}" ]; then
check "Check firstboot config file" \
"[ -f \"${CONFIG_FILE}\" ]"
fi
}
function doCreateBuildHtml() {
cat > $CHROOT_DIR/lounge/www/build.html <<EOHTML
<html>
<head>
<title>ScreenInvader</title>
</head>
<body style="background-color: #000000">
<h3 style="padding: 20px; color: #ff6600;">You are using ScreenInvader version</h3>
<table>
<tr>
<td colspan="2" style="padding: 20px; width:100%; color: #ffffff; font-variant:bold;">
`date`
</td>
</tr>
</table>
</body>
</html>
EOHTML
}
###### main
while getopts 'a:l:p:g:c:iduxbzkr' c
do
case $c in
a) ARCH="$OPTARG";;
c) CONFIG_FILE="`absPath $OPTARG`";;
l) BOOTSTRAP_LOG="`absPath $OPTARG`";;
p) APTCACHER_PORT="$OPTARG";;
i) NOINSTALL="YES";;
d) NODEBOOT="YES";;
z) NOCLEANUP="YES";;
u) NOINSTALL="YES"; NODEBOOT="YES"; NOCLEANUP="YES"; DONT_REBUILD="YES"; DONT_REBUILD_KERNEL="YES";;
x) INSTALL_EXTRA="YES";;
b) DONT_REBUILD="YES";;
k) KEEP_DEPS="YES";;
r) DONT_REBUILD_KERNEL="YES";;
\?) printUsage;;
esac
done
shift $(($OPTIND - 1))
echo > "$BOOTSTRAP_LOG"
export BOOTSTRAP_LOG
source "$BOOTSTRAP_DIR/.functions.sh"
if [ $# -ne 1 ]; then
printUsage
else
export CHROOT_DIR="`absPath $1`"
export CHRT="chroot \"$CHROOT_DIR\" "
doCheckPreCond
[ -n "$INSTALL_EXTRA" ] && PKG_WHITE="$PKG_WHITE $PKG_EXTRA"
if [ -z "$NODEBOOT" ]; then
doDebootstrap
else
skip "debootstrap"
fi
doPrepareChroot
# make sure we're cleaning up eventually
trap doFreeChroot SIGINT SIGTERM EXIT
if [ -z "$NOINSTALL" ]; then
doPackageConf
else
skip "package configuration"
fi
if [ -z "$DONT_REBUILD_KERNEL" ]; then
doBuildKernel
else
skip "build kernel"
fi
if [ -z "$DONT_REBUILD" ]; then
doBuild
else
skip "build"
fi
if [ -z "$DONT_REBUILD_KERNEL" ]; then
doInstallKernel
else
skip "install kernel"
fi
if [ -z "$KEEP_DEPS" ]; then
doCleanupBuildDeps
else
skip "cleanup build dependencies"
fi
if [ -z "$NOCLEANUP" ]; then
doCleanupPackages
else
skip "cleanup packages"
fi
doCleanupFiles
doCopy
doBuildOuttaSpace
doInstallOuttaSpace
doSetupCrontab
doInstallYoutubeDL
doCreateBuildHtml
fi
exit 0