wok-4.x view busybox/stuff/init @ rev 11326

Add libvpx.
author Christopher Rogers <slaxemulator@gmail.com>
date Thu Nov 17 20:44:01 2011 +0000 (2011-11-17)
parents 3ef65672ad0a
children
line source
1 #!/bin/sh
3 launch_init()
4 {
5 [ -d /proc/sys ] && umount /proc
6 echo -e "\\033[70G[ \\033[1;32mOK\\033[0;39m ]"
7 exec /sbin/switch_root mnt /sbin/init
8 }
10 failed()
11 {
12 umount /proc
13 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
14 conspy -d 1 > /init.log
15 }
17 try_init()
18 {
19 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
20 modprobe dm-mod
21 modprobe dm-crypt
22 modprobe aes-i586
23 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
24 dev=${root#/dev/}
25 dmlabel=crypto-$dev
26 if cryptsetup isLuks $root 2> /dev/null; then
27 cryptsetup luksOpen $root $dmlabel
28 else
29 read -s -t 60 -p "Pass phrase : " passphrase
30 key=$(echo $passphrase | hashalot -x -n 32 sha512)
31 blocks=$(cat $(find /sys/block | grep /$dev/size))
32 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
33 dmsetup create $dmlabel
34 fi
35 mount /dev/mapper/$dmlabel /mnt
36 fi
37 if [ -d /mnt/etc ]; then
38 umount /sys
39 [ -n "$1" ] && for i in $@ ; do
40 cp -a $i /mnt$(dirname $i)
41 done
42 mount /mnt -o remount,ro
43 launch_init
44 fi
45 failed
46 }
48 mount_mapper()
49 {
50 mount $root /mnt
51 try_init /dev/mapper $@
52 }
54 lvmsetup()
55 {
56 grep -q lvmroot= /proc/cmdline || return 1
57 modprobe dm-mod
58 vgscan --ignorelockingfailure
59 vgchange -ay --ignorelockingfailure
60 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
61 return 0
62 }
64 load_raid()
65 {
66 while read line; do
67 case "$line" in
68 *raid10*) modprobe raid10 ;;
69 *raid0*) modprobe raid0 ;;
70 *raid1*) modprobe raid1 ;;
71 *raid[456]*) modprobe raid456 ;;
72 esac
73 done
74 }
76 mount -t proc proc /proc
77 mount -t sysfs sysfs /sys
78 echo -n "Switching / to "
79 if grep -q dmraid= /proc/cmdline; then
80 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
81 echo -n "dmraid $root..."
82 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
83 case "$root" in
84 /dev/*);;
85 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
86 esac
87 dmraid -ay
88 lvmsetup
89 mount_mapper
90 fi
91 if grep -q softraid= /proc/cmdline; then
92 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
93 echo -n "softraid $root..."
94 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
95 grep -qs " $root " /etc/mdadm.conf ||
96 root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf)
97 grep level=raid /etc/mdadm.conf | load_raid
98 for i in 1 2 3 4 5 6 7 8 9; do
99 sleep $i
100 mdadm --assemble --scan
101 grep -qs ': active' /proc/mdstat && break
102 done
103 lvmsetup
104 mount_mapper /etc/mdadm.conf
105 fi
106 if lvmsetup; then
107 echo -n "lvm $root..."
108 mount_mapper
109 fi
110 if grep -q mount= /proc/cmdline; then
111 root="$(sed 's/.*mount=\([^ ]*\).*/\1/' < /proc/cmdline)"
112 dev=$(blkid | grep $root | sed 's/:.*//;q')
113 echo -n "Mounting $dev ($root) ..."
114 if ! mount $dev /mnt; then
115 if echo $dev | grep -q "/dev/sd"; then
116 delay=`cat /sys/module/usb_storage/parameters/delay_use`
117 delay=$((1+$delay))
118 echo -n "sleep for $delay seconds..."
119 sleep $delay
120 fi
121 mount $dev /mnt
122 fi
123 grep -q posixovl /proc/cmdline && mount.posixovl /mnt
124 fi
125 if grep -q loopfs= /proc/cmdline; then
126 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
127 echo -n "loop $loopfs..."
128 losetup /dev/loop0 /mnt/$loopfs
129 mount /dev/loop0 /mnt 2> /dev/null
130 fi
131 if grep -q bindfs= /proc/cmdline; then
132 bind="$(sed 's/.*bindfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
133 mount --bind /mnt/${bind%,*} /mnt/${bind%,*}/${bind#*,}
134 fi
135 grep -q cryptoroot= /proc/cmdline && try_init
136 umount /sys
137 if grep -q subroot= /proc/cmdline; then
138 subroot="/$(sed 's/.*subroot=\([^ ]*\).*/\1/' < /proc/cmdline)" &&
139 if [ -s /usr/share/boot/busybox-static ]; then
140 mv /usr/share/boot/busybox-static .
141 /busybox-static rm -rf /etc /lib /*bin /usr /var
142 exec /busybox-static chroot /mnt$subroot /sbin/init
143 else
144 exec chroot /mnt$subroot /sbin/init
145 fi
146 fi
147 echo -n "tmpfs..."
148 size="$(grep rootfssize= < /proc/cmdline | \
149 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
150 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
151 umount /proc
152 [ -n "$size" ] || size="-o size=90%"
153 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
154 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
155 exec /sbin/init
156 fi
157 for i in $(ls -a /); do
158 case "$i" in
159 .|..) ;;
160 mnt) mkdir /mnt/mnt;;
161 *) if ! cp -a /$i /mnt 2> /dev/null; then
162 failed
163 umount /mnt
164 exec /sbin/init
165 fi;;
166 esac
167 done
168 launch_init