7da760d53fa153056a11d1bf7136531f25a5f73b
[openwrt/svn-archive/archive.git] / target / linux / au1000-2.6 / base-files / default / etc / preinit
1 #!/bin/sh
2 # Copyright (C) 2007 OpenWrt.org
3
4 . /etc/functions.sh
5 . /etc/diag.sh
6
7 failsafe() {
8 lock /tmp/.failsafe
9
10 set_state failsafe
11
12 netmsg 192.168.1.255 "Entering Failsafe!"
13 telnetd -l /bin/login <> /dev/null 2>&1
14
15 ash --login
16 }
17
18 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
19 mount none /proc -t proc
20 size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
21 mount none /tmp -t tmpfs -o size=$size
22 if grep devfs /proc/filesystems > /dev/null; then
23 mount none /dev -t devfs
24 M0=/dev/pty/m0
25 M1=/dev/pty/m1
26 else
27 mount -t sysfs none /sys
28 mount -t tmpfs tmpfs /dev -o size=512K
29 mknod /dev/console c 5 1
30 mkdir /dev/shm
31 /sbin/hotplug2 --no-persistent --coldplug --max_children 1
32 M0=/dev/ptmx
33 M1=/dev/ptmx
34 fi
35 mkdir -p /dev/pts
36 mount none /dev/pts -t devpts
37
38 # the shell really doesn't like having stdin/out closed
39 # that's why we use /dev/pty/m0 and m1 as replacement
40 # for /dev/console if there's no serial console available
41 dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null || \
42 exec <$M0 >$M1 2>&0
43
44 set_state preinit
45 #FIXME : use the MTX-1 button to catch failsafe
46 trap 'FAILSAFE=true' USR1
47 echo '/sbin/hotplug' > /proc/sys/kernel/hotplug
48
49 ifname=eth0
50
51 eval ${FAILSAFE:+failsafe}
52
53 lock -w /tmp/.failsafe
54 set_state preinit
55 echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
56
57 mount_root
58 exec /sbin/init