wok view busybox-boot/receipt @ rev 15530
busybox-boot: fix root=device|UUID|LABEL cmdline (again)
| author | Pascal Bellard <pascal.bellard@slitaz.org> | 
|---|---|
| date | Thu Nov 21 20:08:27 2013 +0000 (2013-11-21) | 
| parents | 781029802e4a | 
| children | 80c2116a3ab3 | 
 line source
     1 # SliTaz package receipt.
     3 PACKAGE="busybox-boot"
     4 VERSION="1.21.1"
     5 CATEGORY="base-system"
     6 SHORT_DESC="Many common UNIX utilities for core-5in1/boot flavor."
     7 MAINTAINER="pascal.bellard@slitaz.org"
     8 LICENSE="GPL2"
     9 DEPENDS="linux syslinux"
    10 WANTED="busybox"
    11 WEB_SITE="http://www.busybox.net/"
    12 CONFIG_FILES=""
    14 # Rules to gen a SliTaz package suitable for Tazpkg.
    15 genpkg_rules()
    16 {
    17 	jslinux=false
    18 	mkdir -p $fs/usr/share/boot/bin $fs/usr/share/boot/dev
    19 	CHOICE=static
    20 	for i in uclibc musl diet ; do
    21 		[ -x $src/busybox-$i ] || continue
    22 		[ $(stat -c %s $src/busybox-$i) -lt \
    23 	          $(stat -c %s $src/busybox-$CHOICE) ] &&
    24 		CHOICE=$i
    25 	done
    26 	cp -a $src/busybox-$CHOICE $fs/usr/share/boot/bin/busybox
    27 	chmod 4755 $fs/usr/share/boot/bin/busybox
    28 	for i in sed mount mknod mkdir sh cp ln ; do
    29 		ln $fs/usr/share/boot/bin/busybox $fs/usr/share/boot/bin/$i
    30 	done
    31 	mknod -m 660 $fs/usr/share/boot/dev/console c 5 1
    32 	mknod -m 771 $fs/usr/share/boot/dev/null c 1 3
    33 	mknod -m 660 $fs/usr/share/boot/dev/tty c 5 0
    34 	mknod -m 660 $fs/usr/share/boot/dev/tty1 c 4 1
    35 	if $jslinux; then
    36 		mknod -m 644 $fs/usr/share/boot/dev/clipboard c 10 231
    37 		mknod -m 660 $fs/usr/share/boot/dev/ttyS0 c 4 64
    38 	fi
    39 	cat > $fs/usr/share/boot/init <<EOT
    40 #!/bin/sh
    42 export PATH=/bin
    43 export HOME=/
    44 export TERM=vt100
    46 if [ -n "\$1" ]; then
    47 	[ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
    48 	[ -n "\$subnet" ] && NETMASK="netmask \$subnet"
    49 	ifconfig \$interface \${ip:-0.0.0.0} \$BROADCAST \$NETMASK
    50 	while route del default gw 0.0.0.0 dev \$interface ; do : ; done
    51 	for i in \$router ; do route add default gw \$i dev \$interface; done
    52 	[ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
    53 	for i in \$dns ; do echo nameserver \$i; done >> /etc/resolv.conf
    54 	exit 0
    55 fi
    57 mkdir /tmp /mnt /proc /etc
    58 mount -t proc none /proc
    59 while read name major minor ; do
    60 	for i in '' 1 2 3 4 5 6 7 8 9 ; do
    61 		mknod -m 644 /dev/\$name\$i b \$major \$((\$i + \$minor))
    62 	done
    63 done <<EOM
    64 loop	7	0
    65 hda	3	0
    66 hdb	3	64
    67 sda	8	0
    68 sdb	8	16
    69 EOM
    71 arg()
    72 {
    73 root="\$(sed "s/^/ /;s/\$/ /;/ \$1=/!d;s/.* \$1=\\([^ ]*\\).*/\\1/" </proc/cmdline)"
    74 busybox [ -n "\$root" ]
    75 }
    77 arg init
    78 init=\${root:-/sbin/init}
    79 [ -n "\$(sed 's/\$/ /;s/^/ /;/ ro /!d' /proc/cmdline)" ] && ro="-o ro"
    80 [ -n "\$(sed 's/\$/ /;s/^/ /;/ rw /!d' /proc/cmdline)" ] && ro="-o rw"
    81 arg root && root="\$(echo \$root | sed 's|/|\\\\/|g')" &&
    82 	mount \$ro \$(busybox blkid | sed "s/\"//g;/\$root/!d;s/:.*//;q") /mnt
    83 arg loopfs && busybox losetup /dev/loop /mnt/\$root && mount /dev/loop /mnt
    84 arg subroot && cp /bin/busybox /mnt/\$root/dev/shm &&
    85 	chroot="\$root/dev/shm/busybox chroot \$root"
    86 busybox [ -x /mnt/\$root\$init ] && exec busybox switch_root mnt \$chroot \$init
    88 for i in \$(busybox --list) ; do ln /bin/busybox /bin/\$i 2> /dev/null ; done
    90 [ -d /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb
    91 while read type dir ; do
    92 	grep -qs \$type /proc/filesystems &&
    93 	mkdir \$dir && mount -t \$type none \$dir
    94 done <<EOM
    95 sysfs	/sys
    96 devpts	/dev/pts
    97 EOM
    99 TTY=\$(tty 2>/dev/null)
   100 TTY=\${TTY:-/dev/tty1}
   101 EOT
   102 	$jslinux && echo 'stty -F $TTY rows 30 2>/dev/null' >> $fs/usr/share/boot/init
   103 	cat >> $fs/usr/share/boot/init <<EOT
   105 [ -x /bin/udhcpc ] && udhcpc -b -s /init
   106 while true; do
   107 	busybox | sed '/Current/,\$!d'
   108 	if [ -x /bin/setsid ]; then
   109 		setsid sh -c "exec sh <\$TTY >\$TTY 2>&1"
   110 	else
   111 		sh <\$TTY >\$TTY 2>&1
   112 	fi
   113 done
   114 EOT
   115 	chmod +x $fs/usr/share/boot/init
   116 	( cd $fs/usr/share/boot ; find bin dev init | cpio -o -H newc > initrd )
   117 	rm -rf $fs/usr/share/boot/bin $fs/usr/share/boot/dev $fs/usr/share/boot/init
   118 }