wok-next diff busybox/stuff/init @ rev 20712
libtorrent: fix rtorrent building for non-64bit archs
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sun May 27 12:13:53 2018 +0300 (2018-05-27) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/init Sun May 27 12:13:53 2018 +0300 1.3 @@ -0,0 +1,79 @@ 1.4 +#!/bin/busybox sh 1.5 + 1.6 +export PATH=/bin 1.7 +export HOME=/ 1.8 +export TERM=vt100 1.9 + 1.10 +if [ -d /etc ]; then 1.11 + [ -n "$domain" ] && echo search $domain > /etc/resolv.conf 1.12 + for i in $dns; do 1.13 + echo nameserver $i 1.14 + done >> /etc/resolv.conf 1.15 + [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" 1.16 + [ -n "$subnet" ] && NETMASK="netmask $subnet" 1.17 + if ifconfig $interface ${ip:-0.0.0.0} $BROADCAST $NETMASK; then 1.18 + while route del default gw 0.0.0.0 dev $interface; do 1.19 + : 1.20 + done 1.21 + for i in $router; do 1.22 + route add default gw $i dev $interface 1.23 + done 1.24 + fi 1.25 + exit 1.26 +fi 1.27 + 1.28 +mkdir /tmp /mnt /proc /etc 1.29 +mount -t proc none /proc 1.30 +mount -t devtmpfs none /dev 1.31 + 1.32 +arg() { 1.33 + root="$(sed "s/^/ /; s/$/ /; / $1=/!d; s/.* $1=\\([^ ]*\\).*/\\1/" </proc/cmdline)" 1.34 + [ -n "$root" ] 1.35 +} 1.36 + 1.37 +arg init 1.38 +init=${root:-/sbin/init} 1.39 +[ -n "$(sed 's/$/ /; s/^/ /; / ro /!d' /proc/cmdline)" ] && ro="-o ro" 1.40 +[ -n "$(sed 's/$/ /; s/^/ /; / rw /!d' /proc/cmdline)" ] && ro="-o rw" 1.41 + 1.42 +arg root && 1.43 +root="$(echo $root | sed 's|/|\\\\/|g')" && 1.44 +root="$(blkid | sed "s/\"//g; /$root/!d; s/:.*//;q")" && 1.45 +[ -n "$root" ] && 1.46 +mount $ro $root /mnt 1.47 + 1.48 +arg loopfs && 1.49 +losetup /dev/loop0 /mnt/$root && 1.50 +mount /dev/loop0 /mnt 1.51 + 1.52 +arg subroot && 1.53 +cp /bin/busybox /mnt/$root/dev/shm && 1.54 +chroot="$root/dev/shm/busybox chroot $root" 1.55 + 1.56 +[ -x /mnt/$root/$init ] && 1.57 +umount /dev && 1.58 +umount /proc && 1.59 +exec switch_root mnt $chroot $init 1.60 + 1.61 +[ -d /proc/bus/usb ] && 1.62 +mount -t usbfs usbfs /proc/bus/usb 1.63 + 1.64 +while read type dir; do 1.65 + grep -qs $type /proc/filesystems || continue 1.66 + [ -d "$dir" ] || mkdir $dir 1.67 + mount -t $type none $dir 1.68 +done <<EOM 1.69 +sysfs /sys 1.70 +devpts /dev/pts 1.71 +EOM 1.72 + 1.73 +TTY=$(tty 2>/dev/null) 1.74 +TTY=${TTY:-/dev/tty1} 1.75 + 1.76 +stty -F $TTY rows 30 2>/dev/null # for jslinux only 1.77 + 1.78 +udhcpc -b -s /init 1.79 +while true; do 1.80 + busybox | sed '/Current/,$!d' 1.81 + setsid sh -c "exec sh <$TTY >$TTY 2>&1" 1.82 +done