preinit.arch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. . /etc/functions.sh
  2. failsafe() {
  3. lock /tmp/.failsafe
  4. failsafe_ip
  5. echo "0 1 2 3 4 ${cpu_port:-5u*}" > /proc/switch/eth0/vlan/0/ports
  6. set_state failsafe
  7. [ -x "/usr/sbin/nvram" ] && {
  8. [ "$(nvram get boot_wait)" != "on" ] && {
  9. nvram set boot_wait=on
  10. nvram commit
  11. }
  12. }
  13. netmsg 192.168.1.255 "Entering Failsafe!"
  14. telnetd -l /bin/login.sh <> /dev/null 2>&1
  15. ash --login
  16. }
  17. mount none /proc -t proc
  18. insmod diag
  19. set_state preinit
  20. echo '/sbin/hotplug.failsafe' > /proc/sys/kernel/hotplug
  21. ifname=eth0
  22. # hardware specific overrides
  23. case "$(cat /proc/diag/model)" in
  24. "Linksys WAP54G V1") ifname=eth1;;
  25. "ASUS WL-HDD") ifname=eth1;;
  26. "ASUS WL-300g") ifname=eth1;;
  27. "ASUS (unknown, BCM4702)") ifname=eth1;;
  28. "Sitecom WL-105b") ifname=eth1;;
  29. esac
  30. failsafe_ip
  31. check_module () {
  32. module="$1"; shift; params="$*"
  33. insmod "$module" "$params"
  34. sleep 1
  35. grep "^$module" /proc/modules
  36. return $?
  37. }
  38. insmod switch-core
  39. check_module switch-robo || check_module switch-adm || {
  40. check_module bcm57xx activate_gpio=0x4 && cpu_port="8u*"
  41. } || rmmod switch-core
  42. [ -d /proc/switch/eth0 ] && {
  43. echo 1 > /proc/switch/eth0/reset
  44. # this would be easier if we blasted the message across all ports
  45. # but we don't want packets leaking across interfaces
  46. for port in $(seq 0 4); do {
  47. echo "$port ${cpu_port:-5u*}" > /proc/switch/eth0/vlan/0/ports
  48. netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
  49. }; done
  50. } || netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
  51. ifconfig $ifname 0.0.0.0 down
  52. sleep 2