b7a9f04772123cac23eb53de2ee327522978d1a5
[openwrt.git] / target / linux / brcm-2.4 / base-files / default / etc / preinit
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . /etc/functions.sh
5 . /etc/diag.sh
6
7 failsafe() {
8 lock /tmp/.failsafe
9
10 echo "0 1 2 3 4 5u*" > /proc/switch/eth0/vlan/0/ports
11
12 set_state failsafe
13 [ -x "/usr/sbin/nvram" ] && {
14 [ "$(nvram get boot_wait)" != "on" ] && {
15 nvram set boot_wait=on
16 nvram commit
17 }
18 }
19
20 netmsg 192.168.1.255 "Entering Failsafe!"
21 telnetd -l /bin/login <> /dev/null 2>&1
22
23 ash --login
24 }
25
26 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
27 mount none /proc -t proc
28 size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
29 mount none /tmp -t tmpfs -o size=$size
30
31 insmod diag
32 set_state preinit
33 trap 'FAILSAFE=true' USR1
34 echo '/sbin/hotplug.failsafe' > /proc/sys/kernel/hotplug
35
36 ifname=eth0
37
38 # hardware specific overrides
39 case "$(cat /proc/diag/model)" in
40 "Linksys WAP54G V1") ifname=eth1;;
41 "ASUS WL-HDD") ifname=eth1;;
42 "ASUS WL-300g") ifname=eth1;;
43 "ASUS (unknown, BCM4702)") ifname=eth1;;
44 esac
45
46 insmod switch-core
47 insmod switch-robo || insmod switch-adm || rmmod switch-core
48
49 ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
50
51 [ -d /proc/switch/eth0 ] && {
52 echo 1 > /proc/switch/eth0/reset
53
54 # this would be easier if we blasted the message across all ports
55 # but we don't want packets leaking across interfaces
56 for port in $(seq 0 4); do {
57 echo "$port 5u*" > /proc/switch/eth0/vlan/0/ports
58 netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
59 }; done
60 } || netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
61
62 sleep 2
63
64 eval ${FAILSAFE:+failsafe}
65
66 lock -w /tmp/.failsafe
67 set_state preinit
68 echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
69
70 ifconfig $ifname 0.0.0.0 down
71
72 mount_root
73 exec /sbin/init
This page took 0.047107 seconds and 3 git commands to generate.