wok-next view busybox/stuff/init @ rev 21721

created recipes for efivar and efibootmgr
author Hans-G?nter Theisgen
date Tue Sep 01 10:09:15 2020 +0100 (2020-09-01)
parents
children
line source
1 #!/bin/busybox sh
3 export PATH=/bin
4 export HOME=/
5 export TERM=vt100
7 if [ -d /etc ]; then
8 [ -n "$domain" ] && echo search $domain > /etc/resolv.conf
9 for i in $dns; do
10 echo nameserver $i
11 done >> /etc/resolv.conf
12 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
13 [ -n "$subnet" ] && NETMASK="netmask $subnet"
14 if ifconfig $interface ${ip:-0.0.0.0} $BROADCAST $NETMASK; then
15 while route del default gw 0.0.0.0 dev $interface; do
16 :
17 done
18 for i in $router; do
19 route add default gw $i dev $interface
20 done
21 fi
22 exit
23 fi
25 mkdir /tmp /mnt /proc /etc
26 mount -t proc none /proc
27 mount -t devtmpfs none /dev
29 arg() {
30 root="$(sed "s/^/ /; s/$/ /; / $1=/!d; s/.* $1=\\([^ ]*\\).*/\\1/" </proc/cmdline)"
31 [ -n "$root" ]
32 }
34 arg init
35 init=${root:-/sbin/init}
36 [ -n "$(sed 's/$/ /; s/^/ /; / ro /!d' /proc/cmdline)" ] && ro="-o ro"
37 [ -n "$(sed 's/$/ /; s/^/ /; / rw /!d' /proc/cmdline)" ] && ro="-o rw"
39 arg root &&
40 root="$(echo $root | sed 's|/|\\\\/|g')" &&
41 root="$(blkid | sed "s/\"//g; /$root/!d; s/:.*//;q")" &&
42 [ -n "$root" ] &&
43 mount $ro $root /mnt
45 arg loopfs &&
46 losetup /dev/loop0 /mnt/$root &&
47 mount /dev/loop0 /mnt
49 arg subroot &&
50 cp /bin/busybox /mnt/$root/dev/shm &&
51 chroot="$root/dev/shm/busybox chroot $root"
53 [ -x /mnt/$root/$init ] &&
54 umount /dev &&
55 umount /proc &&
56 exec switch_root mnt $chroot $init
58 [ -d /proc/bus/usb ] &&
59 mount -t usbfs usbfs /proc/bus/usb
61 while read type dir; do
62 grep -qs $type /proc/filesystems || continue
63 [ -d "$dir" ] || mkdir $dir
64 mount -t $type none $dir
65 done <<EOM
66 sysfs /sys
67 devpts /dev/pts
68 EOM
70 TTY=$(tty 2>/dev/null)
71 TTY=${TTY:-/dev/tty1}
73 stty -F $TTY rows 30 2>/dev/null # for jslinux only
75 udhcpc -b -s /init
76 while true; do
77 busybox | sed '/Current/,$!d'
78 setsid sh -c "exec sh <$TTY >$TTY 2>&1"
79 done