penguins-eggs 10.0.33 → 10.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1039 @@
1
+ #!/bin/sh
2
+
3
+ # this is the init script version
4
+ VERSION=@VERSION@
5
+ SINGLEMODE=no
6
+ sysroot="$ROOT"/sysroot
7
+ splashfile=/.splash.ctrl
8
+ repofile="$ROOT"/tmp/repositories
9
+
10
+ # some helpers
11
+ ebegin() {
12
+ last_emsg="$*"
13
+ echo "$last_emsg..." > "$ROOT"/dev/kmsg
14
+ [ "$KOPT_quiet" = yes ] && return 0
15
+ echo -n " * $last_emsg: "
16
+ }
17
+ eend() {
18
+ local msg
19
+ if [ "$1" = 0 ] || [ $# -lt 1 ] ; then
20
+ echo "$last_emsg: ok." > "$ROOT"/dev/kmsg
21
+ [ "$KOPT_quiet" = yes ] && return 0
22
+ echo "ok."
23
+ else
24
+ shift
25
+ echo "$last_emsg: failed. $*" > "$ROOT"/dev/kmsg
26
+ if [ "$KOPT_quiet" = "yes" ]; then
27
+ echo -n "$last_emsg "
28
+ fi
29
+ echo "failed. $*"
30
+ echo "initramfs emergency recovery shell launched. Type 'exit' to continue boot"
31
+ /bin/busybox sh
32
+ fi
33
+ }
34
+
35
+ unpack_apkovl() {
36
+ local ovl="$1"
37
+ local dest="$2"
38
+ local suffix=${ovl##*.}
39
+ local i
40
+ ovlfiles=/tmp/ovlfiles
41
+ if [ "$suffix" = "gz" ]; then
42
+ tar -C "$dest" -zxvf "$ovl" > $ovlfiles
43
+ return $?
44
+ fi
45
+
46
+ # we need openssl. let apk handle deps
47
+ apk add --quiet --initdb --repositories-file $repofile openssl || return 1
48
+
49
+ if ! openssl list -1 -cipher-commands | grep "^$suffix$" > /dev/null; then
50
+ errstr="Cipher $suffix is not supported"
51
+ return 1
52
+ fi
53
+ local count=0
54
+ # beep
55
+ echo -e "\007"
56
+ while [ $count -lt 3 ]; do
57
+ openssl enc -d -$suffix -in "$ovl" | tar --numeric-owner \
58
+ -C "$dest" -zxv >$ovlfiles 2>/dev/null && return 0
59
+ count=$(( $count + 1 ))
60
+ done
61
+ ovlfiles=
62
+ return 1
63
+ }
64
+
65
+ # find mount dir and mount opts for given device in an fstab
66
+ get_fstab_mount_info() {
67
+ local search_dev="$1"
68
+ local fstab="$2"
69
+ local mntopts=
70
+ case "$search_dev" in
71
+ UUID*|LABEL*) search_dev=$(findfs "$search_dev");;
72
+ esac
73
+ [ -r "$fstab" ] || return 1
74
+ local search_maj_min=$(stat -L -c '%t,%T' $search_dev)
75
+ while read dev mnt fs mntopts chk; do
76
+ case "$dev" in
77
+ UUID*|LABEL*) dev=$(findfs "$dev");;
78
+ esac
79
+ if [ -b "$dev" ] || [ -n "$ROOT" ]; then
80
+ local maj_min=$(stat -L -c '%t,%T' $dev)
81
+ if [ "$maj_min" = "$search_maj_min" ]; then
82
+ echo "$mnt $mntopts"
83
+ return
84
+ fi
85
+ fi
86
+ done < $fstab
87
+ }
88
+
89
+ # add a boot service to $sysroot
90
+ rc_add() {
91
+ mkdir -p $sysroot/etc/runlevels/$2
92
+ ln -sf /etc/init.d/$1 $sysroot/etc/runlevels/$2/$1
93
+ }
94
+
95
+ # Recursively resolve tty aliases like console or tty0
96
+ list_console_devices() {
97
+ if ! [ -e "$ROOT"/sys/class/tty/$1/active ]; then
98
+ echo $1
99
+ return
100
+ fi
101
+
102
+ for dev in $(cat "$ROOT"/sys/class/tty/$1/active); do
103
+ list_console_devices $dev
104
+ done
105
+ }
106
+
107
+ detect_serial_consoles() {
108
+ if [ -f "$ovl" ] || [ "$KOPT_autodetect_serial" = "no" ]; then
109
+ return
110
+ fi
111
+ local n=$(awk '$7 ~ /CTS/ || $7 ~ /DSR/ { print $1 }' "$ROOT"/proc/tty/driver/serial 2>/dev/null)
112
+ if [ -n "$n" ]; then
113
+ echo ttyS${n%:}
114
+ fi
115
+ for i in "$ROOT"/sys/class/tty/*; do
116
+ if [ -e "$i"/device ]; then
117
+ echo ${i##*/}
118
+ fi
119
+ done
120
+ }
121
+
122
+ setup_inittab_console() {
123
+ term=vt100
124
+ # Inquire the kernel for list of console= devices
125
+ consoles="$(for c in console $KOPT_consoles $(detect_serial_consoles); do list_console_devices $c; done)"
126
+ for tty in $consoles; do
127
+ # ignore tty devices that gives I/O error
128
+ if ! stty -g -F /dev/$tty >/dev/null 2>/dev/null; then
129
+ continue
130
+ fi
131
+ # do nothing if inittab already have the tty set up
132
+ if ! grep -q "^$tty:" $sysroot/etc/inittab 2>/dev/null; then
133
+ echo "# enable login on alternative console" \
134
+ >> $sysroot/etc/inittab
135
+ # Baudrate of 0 keeps settings from kernel
136
+ echo "$tty::respawn:/sbin/getty -L 0 $tty $term" \
137
+ >> $sysroot/etc/inittab
138
+ fi
139
+ if [ -e "$sysroot"/etc/securetty ] && ! grep -q -w "$tty" "$sysroot"/etc/securetty; then
140
+ echo "$tty" >> "$sysroot"/etc/securetty
141
+ fi
142
+ done
143
+ }
144
+
145
+ # collect ethernet interfaces, sorted by index
146
+ ethernets() {
147
+ for i in "$ROOT/sys/class/net/"*; do
148
+ local iface="${i##*/}"
149
+ if [ -d "$i/device" ]; then
150
+ echo "$(cat "$i/ifindex") $iface"
151
+ fi
152
+ done | sort -n | awk '{print $2}'
153
+ }
154
+
155
+ # find the interface that is has operstate up
156
+ find_first_interface_up() {
157
+ local n=0
158
+ [ $# -eq 0 ] && return 0
159
+ while [ "$n" -le "${LINK_WAIT_MAX:-40}" ]; do
160
+ for i in "$@"; do
161
+ if grep -q -F -x "up" "$ROOT/sys/class/net/$i/operstate"; then
162
+ echo "$i"
163
+ return
164
+ fi
165
+ done
166
+ sleep 0.1
167
+ n=$((n+1))
168
+ done
169
+ return 1
170
+ }
171
+
172
+ # if "ip=dhcp" is specified on the command line, we obtain an IP address
173
+ # using udhcpc. we do this now and not by enabling kernel-mode DHCP because
174
+ # kernel-model DHCP appears to require that network drivers be built into
175
+ # the kernel rather than as modules. At this point all applicable modules
176
+ # in the initrd should have been loaded.
177
+ #
178
+ # You need af_packet.ko available as well modules for your Ethernet card.
179
+ #
180
+ # See https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
181
+ # for documentation on the format.
182
+ #
183
+ # Valid syntaxes:
184
+ # ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf:
185
+ # :dns0-ip:dns1-ip:ntp0-ip
186
+ # ip=dhcp
187
+ # "server-ip", "hostname" and "ntp0-ip" are not supported here.
188
+ # Default (when configure_ip is called without setting ip=):
189
+ # ip=dhcp
190
+ #
191
+ configure_ip() {
192
+ [ -n "$MAC_ADDRESS" ] && return
193
+
194
+ local IFS=':'
195
+ # shellcheck disable=SC2086
196
+ set -- ${KOPT_ip:-dhcp}
197
+ unset IFS
198
+
199
+ local client_ip="$1"
200
+ local gw_ip="$3"
201
+ local netmask="$4"
202
+ local iface="$6"
203
+ local autoconf="$7"
204
+ local dns1="$8"
205
+ local dns2="$9"
206
+
207
+ case "$client_ip" in
208
+ off|none) return;;
209
+ dhcp) autoconf="dhcp";;
210
+ esac
211
+
212
+ if [ -e "$ROOT"/etc/mactab ]; then
213
+ $MOCK nameif -s
214
+ fi
215
+
216
+ if [ -z "$iface" ] && [ -n "$KOPT_BOOTIF" ]; then
217
+ mac=$(printf "%s\n" "$KOPT_BOOTIF"|sed 's/^01-//;s/-/:/g')
218
+ iface=$(grep -l "$mac" "$ROOT"/sys/class/net/*/address | awk -F/ '{print $(NF-1); exit}')
219
+ fi
220
+
221
+ if [ -z "$iface" ]; then
222
+ # shellcheck disable=SC2046
223
+ set -- $(ethernets)
224
+ for i in "$@"; do
225
+ $MOCK ip link set dev "$i" up
226
+ done
227
+ iface=$(find_first_interface_up "$@") || iface="$1"
228
+
229
+ # we will use the found interface later so lets keep it up
230
+ for i in "$@"; do
231
+ if [ "$i" != "$iface" ]; then
232
+ $MOCK ip link set dev "$i" down
233
+ fi
234
+ done
235
+ fi
236
+
237
+ if [ -z "$iface" ]; then
238
+ echo "ERROR: IP requested but no network interface was found"
239
+ return 1
240
+ fi
241
+
242
+ if [ "$autoconf" = "dhcp" ]; then
243
+ # automatic configuration
244
+ if [ ! -e "$ROOT"/usr/share/udhcpc/default.script ]; then
245
+ echo "ERROR: DHCP requested but not present in initrd"
246
+ return 1
247
+ fi
248
+ ebegin "Obtaining IP via DHCP ($iface)"
249
+ $MOCK ip link set dev "$iface" up
250
+ $MOCK udhcpc -i "$iface" -f -q
251
+ eend $?
252
+ else
253
+ # manual configuration
254
+ if [ -z "$client_ip" ] && [ -z "$netmask" ]; then
255
+ return
256
+ fi
257
+ ebegin "Setting IP ($iface)"
258
+ if ifconfig "$iface" "$client_ip" netmask "$netmask"; then
259
+ [ -z "$gw_ip" ] || ip route add 0.0.0.0/0 via "$gw_ip" dev "$iface"
260
+ fi
261
+ eend $?
262
+ fi
263
+
264
+ # Never executes if variables are empty
265
+ for i in $dns1 $dns2; do
266
+ echo "nameserver $i" >> /etc/resolv.conf
267
+ done
268
+
269
+ MAC_ADDRESS=$(cat "$ROOT/sys/class/net/$iface/address")
270
+ }
271
+
272
+ # relocate mountpoint according given fstab and set mount options
273
+ remount_fstab_entry() {
274
+ local fstab="${1}"
275
+ local dir=
276
+ if ! [ -e "$repofile" ]; then
277
+ return
278
+ fi
279
+ echo "$ovl" | cat - "$repofile" | while read dir; do
280
+ # skip http(s)/ftp repos for netboot
281
+ if [ -z "$dir" ] || ! [ -d "$ROOT/$dir" -o -f "$ROOT/$dir" ]; then
282
+ continue
283
+ fi
284
+ local dev=$(df -P "$dir" | tail -1 | awk '{print $1}')
285
+ local mntinfo="$(get_fstab_mount_info "$dev" "$fstab")"
286
+ local mnt="${mntinfo% *}"
287
+ local mntopts="${mntinfo#* }"
288
+ if [ -n "$mnt" ]; then
289
+ local oldmnt=$(awk -v d=$ROOT$dev '$1==d {print $2}' "$ROOT"/proc/mounts 2>/dev/null)
290
+ if [ "$oldmnt" != "$mnt" ]; then
291
+ mkdir -p "$mnt"
292
+ $MOCK mount -o move "$oldmnt" "$mnt"
293
+ fi
294
+ if [ -n "$mntopts" ]; then
295
+ $MOCK mount -o remount,"$mntopts" "$mnt"
296
+ fi
297
+ fi
298
+ done
299
+ }
300
+
301
+ # find the dirs under ALPINE_MNT that are boot repositories
302
+ find_boot_repositories() {
303
+ if [ -n "$ALPINE_REPO" ]; then
304
+ echo "$ALPINE_REPO" | tr ',' '\n'
305
+ else
306
+ find /media/* -maxdepth 3 -name .boot_repository -type f \
307
+ | sed 's:/.boot_repository$::'
308
+ fi
309
+ }
310
+
311
+ setup_nbd() {
312
+ $MOCK modprobe -q nbd max_part=8 || return 1
313
+ local IFS=, n=0
314
+ set -- $KOPT_nbd
315
+ unset IFS
316
+ for ops; do
317
+ local server="${ops%:*}"
318
+ local port="${ops#*:}"
319
+ local device="/dev/nbd${n}"
320
+ [ -b "$device" ] || continue
321
+ nbd-client "$server" "$port" "$device" && n=$((n+1))
322
+ done
323
+ [ "$n" != 0 ] || return 1
324
+ }
325
+
326
+ setup_wireguard() {
327
+ $MOCK modprobe -q wireguard || return 1
328
+ local IFS=';'
329
+ set -- $KOPT_wireguard
330
+ unset IFS
331
+
332
+ local device="$1"
333
+ local ips="$2"
334
+ local config="${3:-/etc/wireguard/initrd.conf}"
335
+
336
+ local IFS=','
337
+ set -- $ips
338
+ unset IFS
339
+
340
+ $MOCK ip link add "$device" type wireguard
341
+ $MOCK wg setconf "$device" "$config"
342
+ $MOCK ip link set dev "$device" up
343
+
344
+ for addr in $@; do
345
+ $MOCK ip addr add dev "$device" "$addr"
346
+ done
347
+ }
348
+
349
+ rtc_exists() {
350
+ local rtc=
351
+ for rtc in /dev/rtc /dev/rtc[0-9]*; do
352
+ [ -e "$rtc" ] && break
353
+ done
354
+ [ -e "$rtc" ]
355
+ }
356
+
357
+ # This is used to predict if network access will be necessary
358
+ is_url() {
359
+ case "$1" in
360
+ http://*|https://*|ftp://*)
361
+ return 0;;
362
+ *)
363
+ return 1;;
364
+ esac
365
+ }
366
+
367
+ # Do some tasks to make sure mounting the ZFS pool is A-OK
368
+ prepare_zfs_root() {
369
+ local _root_vol=${KOPT_root#ZFS=}
370
+ local _root_pool=${_root_vol%%/*}
371
+
372
+ # Force import if this has been imported on a different system previously.
373
+ # Import normally otherwise
374
+ if [ "$KOPT_zfs_force" = 1 ]; then
375
+ zpool import -N -d /dev -f $_root_pool
376
+ else
377
+ zpool import -N -d /dev $_root_pool
378
+ fi
379
+
380
+
381
+ # Ask for encryption password
382
+ if [ $(zpool list -H -o feature@encryption $_root_pool) = "active" ]; then
383
+ local _encryption_root=$(zfs get -H -o value encryptionroot $_root_vol)
384
+ if [ "$_encryption_root" != "-" ]; then
385
+ eval zfs load-key $_encryption_root
386
+ fi
387
+ fi
388
+ }
389
+
390
+ want_tiny_cloud() {
391
+ if [ -f "$sysroot/etc/tiny-cloud.disabled" ]; then
392
+ return 1
393
+ fi
394
+ case "$KOPT_ds" in
395
+ nocloud*) return 0;;
396
+ esac
397
+ if grep -q "^ds=nocloud" "$ROOT"/sys/class/dmi/id/product_serial 2>/dev/null; then
398
+ return 0
399
+ fi
400
+ findfs LABEL=cidata >/dev/null 2>&1 || findfs LABEL=CIDATA >/dev/null 2>&1
401
+ }
402
+
403
+ /bin/busybox mkdir -p "$ROOT"/usr/bin \
404
+ "$ROOT"/usr/sbin \
405
+ "$ROOT"/proc \
406
+ "$ROOT"/sys \
407
+ "$ROOT"/dev \
408
+ "$sysroot" \
409
+ "$ROOT"/media/cdrom \
410
+ "$ROOT"/media/usb \
411
+ "$ROOT"/tmp \
412
+ "$ROOT"/etc \
413
+ "$ROOT"/run/cryptsetup
414
+
415
+ # Spread out busybox symlinks and make them available without full path
416
+ /bin/busybox --install -s
417
+ export PATH="$PATH:/usr/bin:/bin:/usr/sbin:/sbin"
418
+
419
+ # Make sure /dev/null is a device node. If /dev/null does not exist yet, the command
420
+ # mounting the devtmpfs will create it implicitly as an file with the "2>" redirection.
421
+ # The -c check is required to deal with initramfs with pre-seeded device nodes without
422
+ # error message.
423
+ [ -c /dev/null ] || $MOCK mknod -m 666 /dev/null c 1 3
424
+
425
+ $MOCK mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
426
+ $MOCK mount -t devtmpfs -o exec,nosuid,mode=0755,size=2M devtmpfs /dev 2>/dev/null \
427
+ || $MOCK mount -t tmpfs -o exec,nosuid,mode=0755,size=2M tmpfs /dev
428
+
429
+ # Make sure /dev/kmsg is a device node. Writing to /dev/kmsg allows the use of the
430
+ # earlyprintk kernel option to monitor early init progress. As above, the -c check
431
+ # prevents an error if the device node has already been seeded.
432
+ [ -c /dev/kmsg ] || $MOCK mknod -m 660 /dev/kmsg c 1 11
433
+
434
+ $MOCK mount -t proc -o noexec,nosuid,nodev proc /proc
435
+ # pty device nodes (later system will need it)
436
+ [ -c /dev/ptmx ] || $MOCK mknod -m 666 /dev/ptmx c 5 2
437
+ [ -d /dev/pts ] || $MOCK mkdir -m 755 /dev/pts
438
+ $MOCK mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
439
+
440
+ # shared memory area (later system will need it)
441
+ mkdir -p "$ROOT"/dev/shm
442
+ $MOCK mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
443
+
444
+
445
+ # read the kernel options. we need surve things like:
446
+ # acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0)
447
+ set -- $(cat "$ROOT"/proc/cmdline)
448
+
449
+ myopts="alpinelivesquashfs alpinelivelabel autodetect_serial chart cow_spacesize
450
+ cryptroot cryptdm cryptheader cryptoffset cryptdiscards cryptkey debug_init
451
+ ds init init_args keep_apk_new modules pkgs quiet root_size root usbdelay ip
452
+ alpine_repo apkovl splash blacklist overlaytmpfs overlaytmpfsflags rootfstype
453
+ rootflags nbd resume resume_offset s390x_net dasd ssh_key BOOTIF zfcp
454
+ uevent_buf_size aoe aoe_iflist aoe_mtu wireguard"
455
+
456
+ for opt; do
457
+ case "$opt" in
458
+ s|single|1)
459
+ SINGLEMODE=yes
460
+ continue
461
+ ;;
462
+ console=*)
463
+ opt="${opt#*=}"
464
+ KOPT_consoles="${opt%%,*} $KOPT_consoles"
465
+ switch_root_opts="-c /dev/${opt%%,*}"
466
+ continue
467
+ ;;
468
+ esac
469
+
470
+ for i in $myopts; do
471
+ case "$opt" in
472
+ $i=*) eval "KOPT_${i}"='${opt#*=}';;
473
+ $i) eval "KOPT_${i}=yes";;
474
+ no$i) eval "KOPT_${i}=no";;
475
+ esac
476
+ done
477
+ done
478
+
479
+ echo "Alpine Init $VERSION" > "$ROOT"/dev/kmsg
480
+ [ "$KOPT_quiet" = yes ] || echo "Alpine Init $VERSION"
481
+
482
+ # enable debugging if requested
483
+ [ -n "$KOPT_debug_init" ] && set -x
484
+
485
+ # set default values
486
+ : ${KOPT_init:=/sbin/init}
487
+
488
+ # pick first keymap if found
489
+ for map in "$ROOT"/etc/keymap/*; do
490
+ if [ -f "$map" ]; then
491
+ ebegin "Setting keymap ${map##*/}"
492
+ zcat "$map" | loadkmap
493
+ eend
494
+ break
495
+ fi
496
+ done
497
+
498
+ # start bootcharting if wanted
499
+ if [ "$KOPT_chart" = yes ]; then
500
+ ebegin "Starting bootchart logging"
501
+ $MOCK /sbin/bootchartd start-initfs "$sysroot"
502
+ eend 0
503
+ fi
504
+
505
+ # The following values are supported:
506
+ # alpine_repo=auto -- default, search for .boot_repository
507
+ # alpine_repo=http://... -- network repository
508
+ ALPINE_REPO=${KOPT_alpine_repo}
509
+ [ "$ALPINE_REPO" = "auto" ] && ALPINE_REPO=
510
+
511
+ # hide kernel messages
512
+ [ "$KOPT_quiet" = yes ] && dmesg -n 1
513
+
514
+ # optional blacklist
515
+ if [ -n "$KOPT_blacklist" ]; then
516
+ mkdir -p "$ROOT"/etc/modprobe.d
517
+ for i in $(echo "$KOPT_blacklist" | tr ',' ' '); do
518
+ echo "blacklist $i" >> "$ROOT"/etc/modprobe.d/boot-opt-blacklist.conf
519
+ done
520
+ fi
521
+
522
+ # determine if we are going to need networking
523
+ if [ -n "$KOPT_ip" ] || [ -n "$KOPT_nbd" ] || \
524
+ is_url "$KOPT_apkovl" || is_url "$ALPINE_REPO"; then
525
+
526
+ do_networking=true
527
+ else
528
+ do_networking=false
529
+ fi
530
+
531
+ if [ -n "$KOPT_zfcp" ]; then
532
+ $MOCK modprobe zfcp
533
+ for _zfcp in $(echo "$KOPT_zfcp" | tr ',' ' ' | tr [A-Z] [a-z]); do
534
+ echo 1 > /sys/bus/ccw/devices/"${_zfcp%%:*}"/online
535
+ done
536
+ fi
537
+
538
+ if [ -n "$KOPT_dasd" ]; then
539
+ for mod in dasd_mod dasd_eckd_mod dasd_fba_mod; do
540
+ $MOCK modprobe $mod
541
+ done
542
+ for _dasd in $(echo "$KOPT_dasd" | tr ',' ' ' | tr [A-Z] [a-z]); do
543
+ echo 1 > /sys/bus/ccw/devices/"${_dasd%%:*}"/online
544
+ done
545
+ fi
546
+
547
+ if [ "${KOPT_s390x_net%%,*}" = "qeth_l2" ]; then
548
+ for mod in qeth qeth_l2 qeth_l3; do
549
+ $MOCK modprobe $mod
550
+ done
551
+ _channel="$(echo ${KOPT_s390x_net#*,} | tr [A-Z] [a-z])"
552
+ echo "$_channel" > /sys/bus/ccwgroup/drivers/qeth/group
553
+ echo 1 > /sys/bus/ccwgroup/drivers/qeth/"${_channel%%,*}"/layer2
554
+ echo 1 > /sys/bus/ccwgroup/drivers/qeth/"${_channel%%,*}"/online
555
+ fi
556
+
557
+ # make sure we load zfs module if root=ZFS=...
558
+ rootfstype=${KOPT_rootfstype}
559
+ if [ -z "$rootfstype" ]; then
560
+ case "$KOPT_root" in
561
+ ZFS=*) rootfstype=zfs ;;
562
+ esac
563
+ fi
564
+
565
+ # load available drivers to get access to modloop media
566
+ ebegin "Loading boot drivers"
567
+
568
+ $MOCK modprobe -a $(echo "$KOPT_modules $rootfstype" | tr ',' ' ' ) loop squashfs simpledrm 2> /dev/null
569
+ if [ -f "$ROOT"/etc/modules ] ; then
570
+ sed 's/\#.*//g' < /etc/modules |
571
+ while read module args; do
572
+ $MOCK modprobe -q $module $args
573
+ done
574
+ fi
575
+ eend 0
576
+
577
+ # workaround for vmware
578
+ if grep -q VMware "$ROOT"/sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null; then
579
+ $MOCK modprobe -a ata_piix mptspi sr-mod
580
+ fi
581
+
582
+ if [ -n "$KOPT_cryptroot" ]; then
583
+ cryptopts="-c ${KOPT_cryptroot}"
584
+ if [ "$KOPT_cryptdiscards" = "yes" ]; then
585
+ cryptopts="$cryptopts -D"
586
+ fi
587
+ if [ -n "$KOPT_cryptdm" ]; then
588
+ cryptopts="$cryptopts -m ${KOPT_cryptdm}"
589
+ fi
590
+ if [ -n "$KOPT_cryptheader" ]; then
591
+ cryptopts="$cryptopts -H ${KOPT_cryptheader}"
592
+ fi
593
+ if [ -n "$KOPT_cryptoffset" ]; then
594
+ cryptopts="$cryptopts -o ${KOPT_cryptoffset}"
595
+ fi
596
+ if [ "$KOPT_cryptkey" = "yes" ]; then
597
+ cryptopts="$cryptopts -k /crypto_keyfile.bin"
598
+ elif [ -n "$KOPT_cryptkey" ]; then
599
+ cryptopts="$cryptopts -k ${KOPT_cryptkey}"
600
+ fi
601
+ fi
602
+
603
+ if [ -n "$KOPT_wireguard" ]; then
604
+ configure_ip
605
+ setup_wireguard || echo "Failed to setup wireguard tunnel."
606
+ fi
607
+
608
+ if [ -n "$KOPT_nbd" ]; then
609
+ # TODO: Might fail because nlplug-findfs hasn't plugged eth0 yet
610
+ configure_ip
611
+ setup_nbd || echo "Failed to setup nbd device."
612
+ fi
613
+
614
+ if [ -n "$KOPT_aoe" ]; then
615
+ if [ -n "$KOPT_aoe_iflist" ]; then
616
+ for iface in $(echo "$KOPT_aoe_iflist" | tr ',' ' '); do
617
+ $MOCK ip link set dev "$iface" up
618
+ if [ -n "$KOPT_aoe_mtu" ]; then
619
+ $MOCK ip link set dev "$iface" mtu "$KOPT_aoe_mtu"
620
+ fi
621
+ done
622
+ $MOCK modprobe aoe aoe_iflist="$KOPT_aoe_iflist"
623
+ else
624
+ $MOCK modprobe aoe
625
+ fi
626
+ if [ "$KOPT_aoe" != "yes" ]; then
627
+ for target in $(echo "$KOPT_aoe" | tr ',' ' '); do
628
+ while [ ! -e /dev/etherd/e$target ]; do
629
+ echo discover "$target" >>/dev/etherd/discover
630
+ sleep 1
631
+ done
632
+ done
633
+ fi
634
+ fi
635
+
636
+ # zpool reports /dev/zfs missing if it can't read /etc/mtab
637
+ ln -s /proc/mounts "$ROOT"/etc/mtab
638
+
639
+ # check if root=... was set
640
+ if [ -n "$KOPT_root" ]; then
641
+ # run nlplug-findfs before SINGLEMODE so we load keyboard drivers
642
+ ebegin "Mounting root"
643
+ $MOCK nlplug-findfs $cryptopts -p /sbin/mdev ${KOPT_debug_init:+-d} \
644
+ ${KOPT_uevent_buf_size:+-U $KOPT_uevent_buf_size} \
645
+ $KOPT_root
646
+
647
+ if [ "$SINGLEMODE" = "yes" ]; then
648
+ echo "Entering single mode. Type 'exit' to continue booting."
649
+ sh
650
+ fi
651
+
652
+ if echo "$KOPT_modules $rootfstype" | grep -qw btrfs; then
653
+ /sbin/btrfs device scan >/dev/null || \
654
+ echo "Failed to scan devices for btrfs filesystem."
655
+ fi
656
+
657
+ if [ -n "$KOPT_resume" ]; then
658
+ echo "Resume from disk"
659
+ if [ -e $ROOT/sys/power/resume ]; then
660
+ case "$KOPT_resume" in
661
+ UUID*|LABEL*) resume_dev=$(findfs "$KOPT_resume");;
662
+ *) resume_dev="$KOPT_resume";;
663
+ esac
664
+ printf "%d:%d" $(stat -Lc "0x%t 0x%T" "$resume_dev") > $ROOT/sys/power/resume
665
+ if [ -n "$KOPT_resume_offset" ]; then
666
+ echo "$KOPT_resume_offset" > $ROOT/sys/power/resume_offset
667
+ fi
668
+ else
669
+ echo "resume: no hibernation support found"
670
+ fi
671
+ fi
672
+
673
+ if [ "$KOPT_overlaytmpfs" = "yes" ]; then
674
+ # Create mountpoints
675
+ mkdir -p /media/root-ro /media/root-rw $sysroot/media/root-ro \
676
+ $sysroot/media/root-rw
677
+ # Mount read-only underlying rootfs
678
+ rootflags="${KOPT_rootflags:+$KOPT_rootflags,}ro"
679
+ $MOCK mount ${KOPT_rootfstype:+-t $KOPT_rootfstype} -o $rootflags \
680
+ $KOPT_root /media/root-ro
681
+ # Mount writable overlay tmpfs
682
+ overlaytmpfsflags="mode=0755,${KOPT_overlaytmpfsflags:+$KOPT_overlaytmpfsflags,}rw"
683
+ $MOCK mount -t tmpfs -o $overlaytmpfsflags root-tmpfs /media/root-rw
684
+ # Create additional mountpoints and do the overlay mount
685
+ mkdir -p /media/root-rw/work /media/root-rw/root
686
+ $MOCK mount -t overlay -o \
687
+ lowerdir=/media/root-ro,upperdir=/media/root-rw/root,workdir=/media/root-rw/work \
688
+ overlayfs $sysroot
689
+ else
690
+ if [ "$rootfstype" = "zfs" ]; then
691
+ prepare_zfs_root
692
+ fi
693
+ $MOCK mount ${rootfstype:+-t} ${rootfstype} \
694
+ -o ${KOPT_rootflags:-ro} \
695
+ ${KOPT_root#ZFS=} $sysroot
696
+ fi
697
+
698
+ eend $?
699
+ cat "$ROOT"/proc/mounts 2>/dev/null | while read DEV DIR TYPE OPTS ; do
700
+ if [ "$DIR" != "/" -a "$DIR" != "$sysroot" -a -d "$DIR" ]; then
701
+ mkdir -p $sysroot/$DIR
702
+ $MOCK mount -o move $DIR $sysroot/$DIR
703
+ fi
704
+ done
705
+ $MOCK sync
706
+ exec switch_root $switch_root_opts $sysroot $chart_init "$KOPT_init" $KOPT_init_args
707
+ echo "initramfs emergency recovery shell launched"
708
+ exec /bin/busybox sh
709
+ fi
710
+
711
+ if $do_networking; then
712
+ repoopts="-n"
713
+ else
714
+ repoopts="-b $repofile"
715
+ fi
716
+
717
+ # locate boot media and mount it
718
+ ebegin "Mounting boot media"
719
+ $MOCK nlplug-findfs $cryptopts -p /sbin/mdev ${KOPT_debug_init:+-d} \
720
+ ${KOPT_usbdelay:+-t $(( $KOPT_usbdelay * 1000 ))} \
721
+ ${KOPT_uevent_buf_size:+-U $KOPT_uevent_buf_size} \
722
+ $repoopts -a "$ROOT"/tmp/apkovls
723
+ eend $?
724
+
725
+ # Setup network interfaces
726
+ if $do_networking; then
727
+ configure_ip
728
+ fi
729
+
730
+ # early console?
731
+ if [ "$SINGLEMODE" = "yes" ]; then
732
+ echo "Entering single mode. Type 'exit' to continue booting."
733
+ sh
734
+ fi
735
+
736
+ # mount tmpfs sysroot
737
+ rootflags="mode=0755"
738
+ if [ -n "$KOPT_root_size" ]; then
739
+ echo "WARNING: the boot option root_size is deprecated. Use rootflags instead"
740
+ rootflags="$rootflags,size=$KOPT_root_size"
741
+ fi
742
+ if [ -n "$KOPT_rootflags" ]; then
743
+ rootflags="$rootflags,$KOPT_rootflags"
744
+ fi
745
+
746
+ $MOCK mount -t tmpfs -o $rootflags tmpfs $sysroot
747
+
748
+ # sidecar start
749
+ #
750
+ # insert just after: $MOCK mount -t tmpfs -o $rootflags tmpfs $sysroot
751
+ # NOTE: remember to add alpinelivesquashfs alpinelivelabel cow_spacesize to myopt
752
+ # insert at live 748
753
+ ####################################################################################
754
+ if [ -n "${KOPT_alpinelivelabel}" ]; then
755
+ devicelive=$(blkid | grep "${KOPT_alpinelivelabel}" | awk -F: '{print $1}')
756
+ fstype=$(blkid | grep "${KOPT_alpinelivelabel}" | awk -F' ' '{for(i=1;i<=NF;i++) if ($i ~ /TYPE/) print $i}' | awk -F'"' '{print $2}')
757
+
758
+ clear
759
+ echo "Penguins' eggs: sidecar"
760
+ echo "======================="
761
+ echo "booting from: $devicelive"
762
+ echo "- fstype: $fstype"
763
+ echo "- label: $KOPT_alpinelivelabel"
764
+ echo "- filesystem.squashfs: $KOPT_alpinelivesquashfs"
765
+ echo "- cow_spacesize: $KOPT_cow_spacesize NOT_USED!"
766
+ sleep 5
767
+
768
+ # Creating mountpoint
769
+ mkdir /mnt
770
+
771
+ # mount /dev/sr0
772
+ mount -t $fstype ${devicelive} /mnt
773
+
774
+ # mount filesystem squashfs on /media/root-ro
775
+ mkdir -p /media/root-ro
776
+ mount -t squashfs ${KOPT_alpinelivesquashfs} /media/root-ro
777
+
778
+ # mount tmpfs on /media/root-rw
779
+ mkdir -p /media/root-rw
780
+ mount -t tmpfs root-tmpfs /media/root-rw
781
+
782
+ # creare i punti di montaggio necessari
783
+ mkdir -p /media/root-rw/work
784
+ mkdir -p /media/root-rw/root
785
+
786
+ # mount overlayfs on /sysroot
787
+ mount -t overlay overlay -o lowerdir=/media/root-ro,upperdir=/media/root-rw/root,workdir=/media/root-rw/work $sysroot
788
+
789
+ # just a dummy value for /etc/machine-id
790
+ echo 21733847458759515a19bd2466cdd5de | tee /sysroot/etc/machine-id
791
+ fi
792
+ # sidecar emd #####################################################################
793
+
794
+
795
+ if [ -z "$KOPT_apkovl" ]; then
796
+ # Not manually set, use the apkovl found by nlplug
797
+ if [ -e "$ROOT"/tmp/apkovls ]; then
798
+ ovl=$(head -n 1 "$ROOT"/tmp/apkovls)
799
+ fi
800
+ elif is_url "$KOPT_apkovl"; then
801
+ # Fetch apkovl via network
802
+ MACHINE_UUID=$(cat "$ROOT"/sys/class/dmi/id/product_uuid 2>/dev/null)
803
+ url="$(echo "$KOPT_apkovl" | sed -e "s/{MAC}/$MAC_ADDRESS/" -e "s/{UUID}/$MACHINE_UUID/")"
804
+ ovl="/tmp/${url##*/}"
805
+ ovl="${ovl%%\?*}"
806
+ $MOCK wget -O "$ovl" "$url" || ovl=
807
+ else
808
+ ovl="$KOPT_apkovl"
809
+ fi
810
+
811
+ # parse pkgs=pkg1,pkg2
812
+ if [ -n "$KOPT_pkgs" ]; then
813
+ pkgs=$(echo "$KOPT_pkgs" | tr ',' ' ' )
814
+ fi
815
+
816
+ # load apkovl or set up a minimal system
817
+ if [ -f "$ovl" ]; then
818
+ ebegin "Loading user settings from $ovl"
819
+ # create apk db and needed /dev/null and /tmp first
820
+ apk add --root $sysroot --initdb --quiet
821
+
822
+ unpack_apkovl "$ovl" $sysroot
823
+ eend $? $errstr || ovlfiles=
824
+ # hack, incase /root/.ssh was included in apkovl
825
+ [ -d "$sysroot/root" ] && chmod 700 "$sysroot/root"
826
+ pkgs="$pkgs $(cat $sysroot/etc/apk/world 2>/dev/null)"
827
+ fi
828
+
829
+ if [ -f "$sysroot/etc/.default_boot_services" -o ! -f "$ovl" ]; then
830
+ # add some boot services by default
831
+ rc_add devfs sysinit
832
+ rc_add dmesg sysinit
833
+ rc_add mdev sysinit
834
+ rc_add hwdrivers sysinit
835
+ rc_add modloop sysinit
836
+
837
+ rc_add modules boot
838
+ rc_add sysctl boot
839
+ rc_add hostname boot
840
+ rc_add bootmisc boot
841
+ rc_add syslog boot
842
+
843
+ rc_add mount-ro shutdown
844
+ rc_add killprocs shutdown
845
+ rc_add savecache shutdown
846
+
847
+ rc_add firstboot default
848
+
849
+ # add openssh
850
+ if [ -n "$KOPT_ssh_key" ]; then
851
+ pkgs="$pkgs openssh"
852
+ rc_add sshd default
853
+ fi
854
+
855
+ if want_tiny_cloud; then
856
+ pkgs="$pkgs tiny-cloud-alpine ifupdown-ng doas"
857
+ rc_add tiny-cloud-boot boot
858
+ rc_add tiny-cloud-early default
859
+ rc_add tiny-cloud-main default
860
+ rc_add tiny-cloud-final default
861
+ fi
862
+
863
+ rm -f "$sysroot/etc/.default_boot_services"
864
+ fi
865
+
866
+ if [ "$KOPT_splash" != "no" ]; then
867
+ echo "IMG_ALIGN=CM" > /tmp/fbsplash.cfg
868
+ for fbdev in /dev/fb[0-9]; do
869
+ [ -e "$fbdev" ] || break
870
+ num="${fbdev#/dev/fb}"
871
+ for img in /media/*/fbsplash$num.ppm; do
872
+ [ -e "$img" ] || break
873
+ config="${img%.*}.cfg"
874
+ [ -e "$config" ] || config=/tmp/fbsplash.cfg
875
+ fbsplash -s "$img" -d "$fbdev" -i "$config"
876
+ break
877
+ done
878
+ done
879
+ for fbsplash in /media/*/fbsplash.ppm; do
880
+ [ -e "$fbsplash" ] && break
881
+ done
882
+ fi
883
+
884
+ if [ -n "$fbsplash" ] && [ -e "$fbsplash" ]; then
885
+ ebegin "Starting bootsplash"
886
+ mkfifo $sysroot/$splashfile
887
+ config="${fbsplash%.*}.cfg"
888
+ [ -e "$config" ] || config=/tmp/fbsplash.cfg
889
+ setsid fbsplash -T 16 -s "$fbsplash" -i $config -f $sysroot/$splashfile &
890
+ eend 0
891
+ else
892
+ KOPT_splash="no"
893
+ fi
894
+
895
+ if [ -f $sysroot/etc/fstab ]; then
896
+ has_fstab=1
897
+ fstab=$sysroot/etc/fstab
898
+
899
+ # let user override tmpfs size in fstab in apkovl
900
+ mountopts=$(awk '$2 == "/" && $3 == "tmpfs" { print $4 }' $sysroot/etc/fstab)
901
+ if [ -n "$mountopts" ]; then
902
+ $MOCK mount -o remount,$mountopts $sysroot
903
+ fi
904
+ # relocate mounts and adjust mount options
905
+ # this is so a generated /etc/apk/repositories will use correct
906
+ # mount dir
907
+ remount_fstab_entry "$sysroot"/etc/fstab
908
+ elif [ -f "$ROOT"/etc/fstab ]; then
909
+ remount_fstab_entry "$ROOT"/etc/fstab
910
+ fi
911
+
912
+ # hack so we get openrc
913
+ pkgs="$pkgs alpine-base"
914
+
915
+ # copy keys so apk finds them. apk looks for stuff relative --root
916
+ mkdir -p $sysroot/etc/apk/keys/
917
+ $MOCK cp -a /etc/apk/keys $sysroot/etc/apk
918
+
919
+ # generate apk repositories file. needs to be done after relocation
920
+ find_boot_repositories > $repofile
921
+
922
+ # silently fix apk arch in case the apkovl does not match
923
+ if [ -r "$sysroot"/etc/apk/arch ]; then
924
+ apk_arch="$(apk --print-arch)"
925
+ if [ -n "$apk_arch" ]; then
926
+ echo "$apk_arch" > "$sysroot"/etc/apk/arch
927
+ fi
928
+ fi
929
+
930
+ # generate repo opts for apk
931
+ for i in $(cat $repofile); do
932
+ repo_opt="$repo_opt --repository $i"
933
+ done
934
+
935
+ # install new root
936
+ ebegin "Installing packages to root filesystem"
937
+
938
+ if [ "$KOPT_chart" = yes ]; then
939
+ pkgs="$pkgs acct"
940
+ fi
941
+
942
+ # use swclock if no RTC is found
943
+ if rtc_exists || [ "$(uname -m)" = "s390x" ]; then
944
+ rc_add hwclock boot
945
+ else
946
+ rc_add swclock boot
947
+ fi
948
+
949
+ # enable support for modloop verification
950
+ for _pubkey in "$ROOT"/var/cache/misc/*modloop*.SIGN.RSA.*.pub; do
951
+ # check only if the glob matched something
952
+ [ -f "$_pubkey" ] || continue
953
+
954
+ # then do it in one iteration anyway
955
+ mkdir -p "$sysroot"/var/cache/misc
956
+ cp "$ROOT"/var/cache/misc/*modloop*.SIGN.RSA.*.pub "$sysroot"/var/cache/misc
957
+ pkgs="$pkgs openssl"
958
+ break
959
+ done
960
+
961
+ apkflags="--initramfs-diskless-boot --progress"
962
+ if [ -z "$MAC_ADDRESS" ]; then
963
+ apkflags="$apkflags --no-network"
964
+ else
965
+ apkflags="$apkflags --update-cache"
966
+ fi
967
+
968
+ if [ "$KOPT_quiet" = yes ]; then
969
+ apkflags="$apkflags --quiet"
970
+ fi
971
+
972
+ if [ "$KOPT_keep_apk_new" != yes ]; then
973
+ apkflags="$apkflags --clean-protected"
974
+ [ -n "$ovlfiles" ] && apkflags="$apkflags --overlay-from-stdin"
975
+ fi
976
+ mkdir -p $sysroot/sys $sysroot/proc $sysroot/dev
977
+ $MOCK mount -o bind /sys $sysroot/sys
978
+ $MOCK mount -o bind /proc $sysroot/proc
979
+ $MOCK mount -o bind /dev $sysroot/dev
980
+ if [ -n "$ovlfiles" ]; then
981
+ apk add --root $sysroot $repo_opt $apkflags $pkgs <$ovlfiles
982
+ else
983
+ apk add --root $sysroot $repo_opt $apkflags $pkgs
984
+ fi
985
+ $MOCK umount $sysroot/sys $sysroot/proc $sysroot/dev
986
+ eend $?
987
+
988
+ # unmount ovl mount if needed
989
+ if [ -n "$ovl_unmount" ]; then
990
+ $MOCK umount $ovl_unmount 2>/dev/null
991
+ fi
992
+
993
+ # remount according default fstab from package
994
+ if [ -z "$has_fstab" ] && [ -f "$sysroot"/etc/fstab ]; then
995
+ remount_fstab_entry "$sysroot"/etc/fstab
996
+ fi
997
+
998
+ # generate repositories if none exists. this needs to be done after relocation
999
+ if ! [ -f "$sysroot"/etc/apk/repositories ]; then
1000
+ find_boot_repositories > "$sysroot"/etc/apk/repositories
1001
+ fi
1002
+
1003
+ # fix inittab if alternative console
1004
+ setup_inittab_console
1005
+
1006
+ ! [ -f "$sysroot"/etc/resolv.conf ] && [ -f /etc/resolv.conf ] && \
1007
+ cp /etc/resolv.conf "$sysroot"/etc
1008
+
1009
+ # setup bootchart for switch_root
1010
+ chart_init=""
1011
+ if [ "$KOPT_chart" = yes ]; then
1012
+ /sbin/bootchartd stop-initfs "$sysroot"
1013
+ chart_init="/sbin/bootchartd start-rootfs"
1014
+ fi
1015
+
1016
+ if [ ! -x "${sysroot}${KOPT_init}" ]; then
1017
+ [ "$KOPT_splash" != "no" ] && echo exit > $sysroot/$splashfile
1018
+ echo "$KOPT_init not found in new root. Launching emergency recovery shell"
1019
+ echo "Type exit to continue boot."
1020
+ /bin/busybox sh
1021
+ fi
1022
+
1023
+ # switch over to new root
1024
+ cat "$ROOT"/proc/mounts 2>/dev/null | while read DEV DIR TYPE OPTS ; do
1025
+ if [ "$DIR" != "/" -a "$DIR" != "$sysroot" -a -d "$DIR" ]; then
1026
+ mkdir -p $sysroot/$DIR
1027
+ $MOCK mount -o move $DIR $sysroot/$DIR
1028
+ fi
1029
+ done
1030
+ sync
1031
+
1032
+ [ "$KOPT_splash" = "init" ] && echo exit > $sysroot/$splashfile
1033
+ echo ""
1034
+ exec switch_root $switch_root_opts $sysroot $chart_init "$KOPT_init" $KOPT_init_args
1035
+
1036
+ [ "$KOPT_splash" != "no" ] && echo exit > $sysroot/$splashfile
1037
+ echo "initramfs emergency recovery shell launched"
1038
+ exec /bin/busybox sh
1039
+ reboot