[package] kmod-libertas needs kmod-lib80211 to load
[openwrt.git] / package / base-files / files / etc / preinit
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
4 . /etc/diag.sh
5
6 failsafe_ip() {
7 ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
8 }
9
10 failsafe() {
11 set_state failsafe
12 [ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
13 failsafe_ip
14 netmsg 192.168.1.255 "Entering Failsafe!"
15 telnetd -l /bin/login.sh <> /dev/null 2>&1
16 }
17 lock /tmp/.failsafe
18 ash --login
19 }
20
21 mount proc /proc -t proc
22 mount sysfs /sys -t sysfs
23
24 size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)&&(mt>l)?mt-l:s}' /proc/meminfo)
25 mount tmpfs /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
26
27 if grep devfs /proc/filesystems > /dev/null; then
28 mount devfs /dev -t devfs
29 M0=/dev/pty/m0
30 M1=/dev/pty/m1
31 HOTPLUG=/sbin/hotplug-call
32
33 elif [ -x /sbin/hotplug2 ]; then
34 mount -t tmpfs tmpfs /dev -o size=512K
35 mknod /dev/console c 5 1
36 /sbin/hotplug2 --set-worker /lib/hotplug2/worker_fork.so --set-rules-file /etc/hotplug2-init.rules --no-persistent --set-coldplug-cmd /sbin/udevtrigger
37 /sbin/hotplug2 --set-worker /lib/hotplug2/worker_fork.so --set-rules-file /etc/hotplug2-init.rules --persistent &
38 M0=/dev/ptmx
39 M1=/dev/ptmx
40 HOTPLUG=
41
42 elif [ -x /sbin/udevd ]; then
43 mount -n -t tmpfs -o mode=0755 udev /dev
44 [ -d /lib/udev/devices ] && cp -af /lib/udev/devices/* /dev/
45 [ -c /dev/console ] || mknod -m 0600 /dev/console c 5 1
46 [ -c /dev/null ] || mknod -m 0666 /dev/null c 1 3
47 /sbin/udevd --daemon --resolve-names=never
48 /sbin/udevadm trigger
49 /sbin/udevadm settle
50 M0=/dev/pty/ptmx
51 M1=/dev/pty/ptmx
52 HOTPLUG=
53 fi
54
55 [ -d /dev/pts ] || mkdir -p /dev/pts
56 [ -d /dev/shm ] || mkdir -p /dev/shm
57 mount devpts /dev/pts -t devpts
58
59 # the shell really doesn't like having stdin/out closed
60 # that's why we use /dev/pty/m0 and m1 as replacement
61 # for /dev/console if there's no serial console available
62 dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null && {
63 M0=/dev/console
64 M1=/dev/console
65 }
66
67 exec <$M0 >$M1 2>&0
68
69 echo "- preinit -"
70 set_state preinit
71 echo "Press CTRL-C for failsafe"
72 trap 'FAILSAFE=true' INT
73 trap 'FAILSAFE=true' USR1
74 if [ -e /etc/preinit.arch ]; then
75 . /etc/preinit.arch
76 else
77 sleep 2
78 fi
79 echo "$HOTPLUG" > /proc/sys/kernel/hotplug
80 export FAILSAFE
81 eval ${FAILSAFE:+failsafe}
82 lock -w /tmp/.failsafe
83
84 if [ -z "$INITRAMFS" ]; then
85 mount_root
86 [ -f /sysupgrade.tgz ] && {
87 echo "- config restore -"
88 cd /
89 mv sysupgrade.tgz /tmp
90 tar xzf /tmp/sysupgrade.tgz
91 rm -f /tmp/sysupgrade.tgz
92 sync
93 }
94
95 echo "- init -"
96
97 exec /sbin/init
98 fi
This page took 0.056762 seconds and 5 git commands to generate.