enable travis notification
[openadk.git] / scripts / install.sh
blob8ae923a8dfe85b98b328019b0d0196d503a16c07
1 #!/usr/bin/env bash
2 #-
3 # Copyright © 2010-2016
4 # Waldemar Brodkorb <wbx@openadk.org>
5 # Thorsten Glaser <tg@mirbsd.org>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un‐
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person’s immediate fault when using the work as intended.
22 # Alternatively, this work may be distributed under the terms of the
23 # General Public License, any version, as published by the Free Soft-
24 # ware Foundation.
26 # Prepare a USB stick or CF/SD/MMC card or hard disc for installation
27 # of OpenADK
29 ADK_TOPDIR=$(pwd)
30 HOST=$(gcc -dumpmachine)
31 me=$0
33 case :$PATH: in
34 (*:$ADK_TOPDIR/host_$HOST/usr/bin:*) ;;
35 (*) export PATH=$PATH:$ADK_TOPDIR/host_$HOST/usr/bin ;;
36 esac
38 test -n "$KSH_VERSION" || exec mksh "$me" "$@"
39 if test -z "$KSH_VERSION"; then
40 echo >&2 Fatal error: could not run myself with mksh!
41 exit 255
44 ### run with mksh from here onwards ###
46 me=${me##*/}
48 if (( USER_ID )); then
49 print -u2 Installation is only possible as root!
50 exit 1
53 ADK_TOPDIR=$(realpath .)
54 ostype=$(uname -s)
56 fs=ext4
57 cfgfs=1
58 datafssz=0
59 noformat=0
60 quiet=0
61 serial=0
62 speed=115200
63 panicreboot=10
64 keep=0
65 grub=0
67 function usage {
68 cat >&2 <<EOF
69 Syntax: $me [-f filesystem] [-c cfgfssize] [-d datafssize] [-k] [-n] [-g]
70 [-p panictime] [±q] [-s serialspeed] [±t] <target> <device> <archive>
71 Partition sizes are in MiB. Filesystem type is currently ignored (ext4).
72 To keep filesystem on data partition use -k.
73 Use -n to not format boot/root partition.
74 Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
75 EOF
76 exit $1
79 while getopts "c:d:f:ghknp:qs:t" ch; do
80 case $ch {
81 (c) if (( (cfgfs = OPTARG) < 0 || cfgfs > 16 )); then
82 print -u2 "$me: -c $OPTARG out of bounds"
83 exit 1
84 fi ;;
85 (d) if (( (datafssz = OPTARG) < 0 )); then
86 print -u2 "$me: -d $OPTARG out of bounds"
87 exit 1
88 fi ;;
89 (f) if [[ $OPTARG != @(ext2|ext3|ext4|xfs) ]]; then
90 print -u2 "$me: filesystem $OPTARG invalid"
91 exit 1
93 fs=$OPTARG ;;
94 (h) usage 0 ;;
95 (k) keep=1 ;;
96 (g) grub=1 ;;
97 (p) if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
98 print -u2 "$me: -p $OPTARG out of bounds"
99 exit 1
100 fi ;;
101 (q) quiet=1 ;;
102 (+q) quiet=0 ;;
103 (s) if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
104 print -u2 "$me: serial speed $OPTARG invalid"
105 exit 1
107 speed=$OPTARG ;;
108 (n) noformat=1 ;;
109 (t) serial=1 ;;
110 (+t) serial=0 ;;
111 (*) usage 1 ;;
113 done
114 shift $((OPTIND - 1))
116 (( $# == 3 )) || usage 1
119 case $ostype {
120 (Linux)
121 tools="bc mkfs.$fs tune2fs partprobe"
123 (Darwin)
124 tools="bc diskutil"
127 print -u2 Sorry, not ported to the OS "'$ostype'" yet.
128 exit 1
131 for tool in $tools; do
132 print -n Checking if $tool is installed...
133 if whence -p $tool >/dev/null; then
134 print " okay"
135 else
136 print " failed"
139 done
140 (( f )) && exit 1
142 target=$1
143 tgt=$2
144 src=$3
146 case $target {
147 (banana-pro|pcengines-apu|raspberry-pi|raspberry-pi2|raspberry-pi3|solidrun-imx6|solidrun-clearfog|default) ;;
149 print -u2 "Unknown target '$target', exiting"
150 exit 1 ;;
152 if [[ ! -b $tgt ]]; then
153 print -u2 "'$tgt' is not a block device, exiting"
154 exit 1
156 if [[ ! -f $src ]]; then
157 print -u2 "'$src' is not a file, exiting"
158 exit 1
160 (( quiet )) || print "Installing $src on $tgt."
162 case $ostype {
163 (Darwin)
164 R=/Volumes/ADKROOT; diskutil unmount $R
165 B=/Volumes/ADKBOOT; diskutil unmount $B
166 D=/Volumes/ADKDATA; diskutil unmount $D
167 basedev=$tgt
168 rootpart=${basedev}s1
169 datapart=${basedev}s2
170 if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 ]]; then
171 bootpart=${basedev}s1
172 rootpart=${basedev}s2
173 datapart=${basedev}s3
175 match=\'${basedev}\''?(s+([0-9]))'
176 function mount_fs {
178 function umount_fs {
179 diskutil unmount "$1"
181 function create_fs {
182 if [[ $3 = ext4 ]]; then
183 fstype=UFSD_EXTFS4
185 if [[ $3 = vfat ]]; then
186 fstype=fat32
188 diskutil eraseVolume $fstype "$2" "$1"
190 function tune_fs {
193 (Linux)
194 basedev=$tgt
195 rootpart=${basedev}1
196 datapart=${basedev}2
197 if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 ]]; then
198 bootpart=${basedev}1
199 rootpart=${basedev}2
200 datapart=${basedev}3
203 match=\'${basedev}\''+([0-9])'
204 function mount_fs {
205 mount -t "$3" "$1" "$2"
207 function umount_fs {
208 umount "$1"
210 function create_fs {
211 (( quiet )) || print "Creating filesystem on ${1}..."
212 mkfs.$3 "$1"
214 function tune_fs {
215 tune2fs -c 0 -i 0 "$1"
220 mount |&
221 while read -p dev rest; do
222 eval [[ \$dev = $match ]] || continue
223 print -u2 "Block device $tgt is in use, please umount first."
224 exit 1
225 done
227 if (( !quiet )); then
228 print "WARNING: This will overwrite $basedev - type Yes to continue!"
229 read x
230 [[ $x = Yes ]] || exit 0
233 if ! T=$(mktemp -d /tmp/openadk.XXXXXXXXXX); then
234 print -u2 Error creating temporary directory.
235 exit 1
237 if [[ $ostype != Darwin ]]; then
238 R=$T/rootmnt
239 B=$T/bootmnt
240 D=$T/datamnt
241 mkdir -p "$R" "$B" "$D"
244 # get disk size
245 dksz=$(dkgetsz "$tgt")
247 # partition layouts:
248 # n̲a̲m̲e̲ p̲a̲r̲t̲#̲0̲ p̲̲a̲r̲t̲#̲1̲ p̲̲a̲r̲t̲#̲2̲ p̲̲a̲r̲t̲#̲3̲
249 # default: 0x83(system) 0x83(?data) -(unused) 0x88(cfgfs)
250 # raspberry: 0x0B(boot) 0x83(system) 0x83(?data) 0x88(cfgfs)
252 syspartno=0
254 # sizes:
255 # boot(raspberry) - fixed (100 MiB)
256 # cfgfs - fixed (parameter, max. 16 MiB)
257 # data - flexible (parameter)
258 # system - everything else
260 if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 ]]; then
261 syspartno=1
262 bootfssz=100
263 if (( grub )); then
264 print -u2 "Cannot combine GRUB with $target"
265 rm -rf "$T"
266 exit 1
268 else
269 bootfssz=0
272 heads=64
273 secs=32
274 (( cyls = dksz / heads / secs ))
275 if (( cyls < (bootfssz + cfgfs + datafssz + 2) )); then
276 print -u2 "Size of $tgt is $dksz, this looks fishy?"
277 rm -rf "$T"
278 exit 1
281 if stat -qs .>/dev/null 2>&1; then
282 statcmd='stat -f %z' # BSD stat (or so we assume)
283 else
284 statcmd='stat -c %s' # GNU stat
287 if (( grub )); then
288 tar -xOf "$src" boot/grub/core.img >"$T/core.img"
289 integer coreimgsz=$($statcmd "$T/core.img")
290 else
291 coreimgsz=65024
293 if (( coreimgsz < 1024 )); then
294 print -u2 core.img is probably too small: $coreimgsz
295 rm -rf "$T"
296 exit 1
298 if (( coreimgsz > 65024 )); then
299 print -u2 core.img is larger than 64K-512: $coreimgsz
300 rm -rf "$T"
301 exit 1
303 (( coreendsec = (coreimgsz + 511) / 512 ))
304 if [[ $basedev = /dev/svnd+([0-9]) ]]; then
305 # BSD svnd0 mode: protect sector #1
306 corestartsec=2
307 (( ++coreendsec ))
308 corepatchofs=$((0x614))
309 else
310 corestartsec=1
311 corepatchofs=$((0x414))
313 # partition offset: at least coreendsec+1 but aligned on a multiple of secs
314 #(( partofs = ((coreendsec / secs) + 1) * secs ))
315 # we just use 2048 all the time, since some loaders are longer
316 partofs=2048
317 if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 ]]; then
318 (( spartofs = partofs + (100 * 2048) ))
319 else
320 spartofs=$partofs
323 (( quiet )) || if (( grub )); then
324 print Preparing MBR and GRUB2...
325 else
326 print Preparing MBR...
328 dd if=/dev/zero of="$T/firsttrack" count=$partofs 2>/dev/null
329 # add another MiB to clear the first partition
330 dd if=/dev/zero bs=1048576 count=1 >>"$T/firsttrack" 2>/dev/null
331 echo $corestartsec $coreendsec | mksh "$ADK_TOPDIR/scripts/bootgrub.mksh" \
332 -A -g $((cyls - bootfssz - cfgfs - datafssz)):$heads:$secs -M 1:0x83 \
333 -O $spartofs | dd of="$T/firsttrack" conv=notrunc 2>/dev/null
334 (( grub )) && dd if="$T/core.img" of="$T/firsttrack" conv=notrunc \
335 seek=$corestartsec 2>/dev/null
336 # set partition where it can find /boot/grub
337 (( grub )) && print -n '\0\0\0\0' | \
338 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$corepatchofs 2>/dev/null
340 # create cfgfs partition (mostly taken from bootgrub.mksh)
341 set -A thecode
342 typeset -Uui8 thecode
343 mbrpno=0
344 set -A g_code $cyls $heads $secs
345 (( psz = g_code[0] * g_code[1] * g_code[2] ))
346 (( pofs = (cyls - cfgfs) * g_code[1] * g_code[2] ))
347 set -A o_code # g_code equivalent for partition offset
348 (( o_code[2] = pofs % g_code[2] + 1 ))
349 (( o_code[1] = pofs / g_code[2] ))
350 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
351 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
352 # boot flag; C/H/S offset
353 thecode[mbrpno++]=0x00
354 (( thecode[mbrpno++] = o_code[1] - 1 ))
355 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
356 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
357 (( thecode[mbrpno++] = cylno & 0x00FF ))
358 # partition type; C/H/S end
359 (( thecode[mbrpno++] = 0x88 ))
360 (( thecode[mbrpno++] = g_code[1] - 1 ))
361 (( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
362 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
363 (( thecode[mbrpno++] = cylno & 0x00FF ))
364 # partition offset, size (LBA)
365 (( thecode[mbrpno++] = pofs & 0xFF ))
366 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
367 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
368 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
369 (( pssz = psz - pofs ))
370 (( thecode[mbrpno++] = pssz & 0xFF ))
371 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
372 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
373 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
374 # write partition table entry
375 ostr=
376 curptr=0
377 while (( curptr < 16 )); do
378 ostr=$ostr\\0${thecode[curptr++]#8#}
379 done
380 print -n "$ostr" | \
381 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1EE)) 2>/dev/null
383 if (( datafssz )); then
384 # create data partition (copy of the above :)
385 set -A thecode
386 typeset -Uui8 thecode
387 mbrpno=0
388 set -A g_code $cyls $heads $secs
389 (( psz = (cyls - cfgfs) * g_code[1] * g_code[2] ))
390 (( pofs = (cyls - cfgfs - datafssz) * g_code[1] * g_code[2] ))
391 set -A o_code # g_code equivalent for partition offset
392 (( o_code[2] = pofs % g_code[2] + 1 ))
393 (( o_code[1] = pofs / g_code[2] ))
394 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
395 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
396 # boot flag; C/H/S offset
397 thecode[mbrpno++]=0x00
398 (( thecode[mbrpno++] = o_code[1] - 1 ))
399 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
400 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
401 (( thecode[mbrpno++] = cylno & 0x00FF ))
402 # partition type; C/H/S end
403 (( thecode[mbrpno++] = 0x83 ))
404 (( thecode[mbrpno++] = g_code[1] - 1 ))
405 (( cylno = (g_code[0] - cfgfs) > 1024 ? 1023 : g_code[0] - cfgfs - 1 ))
406 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
407 (( thecode[mbrpno++] = cylno & 0x00FF ))
408 # partition offset, size (LBA)
409 (( thecode[mbrpno++] = pofs & 0xFF ))
410 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
411 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
412 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
413 (( pssz = psz - pofs ))
414 (( thecode[mbrpno++] = pssz & 0xFF ))
415 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
416 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
417 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
418 # write partition table entry
419 ostr=
420 curptr=0
421 while (( curptr < 16 )); do
422 ostr=$ostr\\0${thecode[curptr++]#8#}
423 done
424 print -n "$ostr" | \
425 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) 2>/dev/null
428 if [[ $target = raspberry-pi || $target = raspberry-pi2 || $target = raspberry-pi3 ]]; then
429 # move system and data partition from #0/#1 to #1/#2
430 dd if="$T/firsttrack" bs=1 skip=$((0x1BE)) count=32 of="$T/x" 2>/dev/null
431 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1CE)) if="$T/x" 2>/dev/null
432 # create boot partition (copy of the above :)
433 set -A thecode
434 typeset -Uui8 thecode
435 mbrpno=0
436 set -A g_code $cyls $heads $secs
437 psz=$spartofs
438 pofs=$partofs
439 set -A o_code # g_code equivalent for partition offset
440 (( o_code[2] = pofs % g_code[2] + 1 ))
441 (( o_code[1] = pofs / g_code[2] ))
442 (( o_code[0] = o_code[1] / g_code[1] + 1 ))
443 (( o_code[1] = o_code[1] % g_code[1] + 1 ))
444 # boot flag; C/H/S offset
445 thecode[mbrpno++]=0x00
446 (( thecode[mbrpno++] = o_code[1] - 1 ))
447 (( cylno = o_code[0] > 1024 ? 1023 : o_code[0] - 1 ))
448 (( thecode[mbrpno++] = o_code[2] | ((cylno & 0x0300) >> 2) ))
449 (( thecode[mbrpno++] = cylno & 0x00FF ))
450 # partition type; C/H/S end
451 (( thecode[mbrpno++] = 0x0B ))
452 (( thecode[mbrpno++] = g_code[1] - 1 ))
453 (( cylno = (spartofs / 2048) > 1024 ? 1023 : (spartofs / 2048) - 1 ))
454 (( thecode[mbrpno++] = g_code[2] | ((cylno & 0x0300) >> 2) ))
455 (( thecode[mbrpno++] = cylno & 0x00FF ))
456 # partition offset, size (LBA)
457 (( thecode[mbrpno++] = pofs & 0xFF ))
458 (( thecode[mbrpno++] = (pofs >> 8) & 0xFF ))
459 (( thecode[mbrpno++] = (pofs >> 16) & 0xFF ))
460 (( thecode[mbrpno++] = (pofs >> 24) & 0xFF ))
461 (( pssz = psz - pofs ))
462 (( thecode[mbrpno++] = pssz & 0xFF ))
463 (( thecode[mbrpno++] = (pssz >> 8) & 0xFF ))
464 (( thecode[mbrpno++] = (pssz >> 16) & 0xFF ))
465 (( thecode[mbrpno++] = (pssz >> 24) & 0xFF ))
466 # write partition table entry
467 ostr=
468 curptr=0
469 while (( curptr < 16 )); do
470 ostr=$ostr\\0${thecode[curptr++]#8#}
471 done
472 print -n "$ostr" | \
473 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BE)) 2>/dev/null
476 # disk signature
477 rnddev=/dev/urandom
478 [[ -c /dev/arandom ]] && rnddev=/dev/arandom
479 dd if=$rnddev bs=4 count=1 2>/dev/null | \
480 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1B8)) 2>/dev/null
481 print -n '\0\0' | \
482 dd of="$T/firsttrack" conv=notrunc bs=1 seek=$((0x1BC)) 2>/dev/null
483 partuuid=$(dd if="$T/firsttrack" bs=1 count=4 skip=$((0x1B8)) 2>/dev/null | \
484 hexdump -e '1/4 "%08x"')-0$((syspartno+1))
486 ((keep)) || if (( datafssz )); then
487 (( quiet )) || print Cleaning out data partition...
488 dd if=/dev/zero of="$tgt" bs=1048576 count=1 seek=$((cyls - cfgfs - datafssz)) > /dev/null 2>&1
490 (( quiet )) || print Cleaning out root partition...
491 dd if=/dev/zero bs=1048576 of="$tgt" count=1 seek=$((spartofs / 2048)) > /dev/null 2>&1
493 (( quiet )) || if (( grub )); then
494 print Writing MBR and GRUB2 to target device... system PARTUUID=$partuuid
495 else
496 print Writing MBR to target device... system PARTUUID=$partuuid
498 dd if="$T/firsttrack" of="$tgt" > /dev/null 2>&1
500 if [[ $ostype = Linux ]]; then
501 partprobe $tgt
502 sync
505 fwdir=$(dirname "$src")
507 case $target {
508 (banana-pro)
509 dd if="$fwdir/u-boot-sunxi-with-spl.bin" of="$tgt" bs=1024 seek=8 > /dev/null 2>&1
511 (solidrun-clearfog)
512 dd if="$fwdir/u-boot-spl.kwb" of="$tgt" bs=512 seek=1 > /dev/null 2>&1
514 (solidrun-imx6)
515 dd if="$fwdir/SPL" of="$tgt" bs=1024 seek=1 > /dev/null 2>&1
516 dd if="$fwdir/u-boot.img" of="$tgt" bs=1024 seek=69 > /dev/null 2>&1
518 (raspberry-pi|raspberry-pi2|raspberry-pi3)
519 (( noformat )) || create_fs "$bootpart" ADKBOOT vfat
523 (( noformat )) || create_fs "$rootpart" ADKROOT ext4
524 (( noformat )) || tune_fs "$rootpart"
526 (( quiet )) || print Extracting installation archive...
527 mount_fs "$rootpart" "$R" ext4
528 xz -dc "$src" | (cd "$R"; tar -xpf -)
530 if (( datafssz )); then
531 mkdir -m0755 "$R"/data
532 ((keep)) || create_fs "$datapart" ADKDATA ext4
533 ((keep)) || tune_fs "$datapart"
534 case $target {
535 (raspberry-pi|raspberry-pi2|raspberry-pi3)
536 echo "/dev/mmcblk0p3 /data ext4 rw 0 0" >> "$R"/etc/fstab
538 (banana-pro|solidrun-imx6|solidrun-clearfog)
539 echo "/dev/mmcblk0p2 /data ext4 rw 0 0" >> "$R"/etc/fstab
544 case $target {
545 (raspberry-pi|raspberry-pi2|raspberry-pi3)
546 mount_fs "$bootpart" "$B" vfat
547 for x in "$R"/boot/*; do
548 [[ -e "$x" ]] && mv -f "$R"/boot/* "$B/"
549 break
550 done
551 for x in "$fwdir"/*.dtb; do
552 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$B/"
553 break
554 done
555 mkdir "$B/"overlays
556 for x in "$fwdir"/overlays/*.dtb; do
557 [[ -e "$x" ]] && cp "$fwdir"/overlays/*.dtb "$B/"overlays
558 break
559 done
560 umount_fs "$B"
562 (solidrun-clearfog)
563 for x in "$fwdir"/*.dtb; do
564 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
565 break
566 done
567 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
568 -n "SolidrunClearfog" \
569 -d $fwdir/boot.script.clearfog $R/boot/boot.scr.uimg
571 (solidrun-imx6)
572 for x in "$fwdir"/*.dtb; do
573 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
574 break
575 done
576 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
577 -n "SolidrunImx6" \
578 -d $fwdir/boot.script.imx6 $R/boot/boot.scr.uimg
580 (banana-pro)
581 for x in "$fwdir"/*.dtb; do
582 [[ -e "$x" ]] && cp "$fwdir"/*.dtb "$R/boot/"
583 break
584 done
585 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
586 -n "BananaPro" \
587 -d $fwdir/boot.script.bpi $R/boot/boot.scr.uimg
591 cd "$R"
592 dd if=$rnddev bs=16 count=1 >>etc/.rnd 2>/dev/null
593 (( quiet )) || print Fixing up permissions...
594 chown 0:0 tmp
595 chmod 1777 tmp
596 [[ -f usr/bin/sudo ]] && chmod 4755 usr/bin/sudo
598 if (( grub )); then
599 (( quiet )) || print Configuring GRUB2 bootloader...
600 mkdir -p boot/grub
602 print set default=0
603 print set timeout=1
604 if (( serial )); then
605 print serial --unit=0 --speed=$speed
606 print terminal_output serial
607 print terminal_input serial
608 consargs="console=ttyS0,$speed console=tty0"
609 else
610 print terminal_output console
611 print terminal_input console
612 consargs="console=tty0"
614 print
615 print 'menuentry "GNU/Linux (OpenADK)" {'
616 linuxargs="root=PARTUUID=$partuuid $consargs"
617 (( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
618 print "\tlinux /boot/kernel $linuxargs"
619 print '}'
620 ) >boot/grub/grub.cfg
623 (( quiet )) || print Finishing up...
624 cd "$ADK_TOPDIR"
625 umount_fs "$R"
626 rm -rf "$T"
627 exit 0