gluon-setup-mode 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh /etc/rc.common
  2. START=12
  3. SETUP_MODE_ADDR=192.168.1.1
  4. SETUP_MODE_NETMASK=255.255.255.0
  5. SETUP_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254
  6. delete_interface() {
  7. [ "$1" = 'loopback' ] || uci_remove network "$1"
  8. }
  9. check_enable() {
  10. config_get enabled "$1" enabled
  11. config_get configured "$1" configured
  12. if [ "$enabled" = 1 -o "$configured" != 1 ]; then
  13. export enable=1
  14. fi
  15. }
  16. setup_network() {
  17. (
  18. export UCI_CONFIG_DIR=/var/gluon/setup-mode/config
  19. mkdir -p "$UCI_CONFIG_DIR"
  20. cp /etc/config/network "$UCI_CONFIG_DIR"
  21. config_load network
  22. config_foreach delete_interface interface
  23. uci_add network interface setup
  24. uci_set network setup ifname "$(sysconfig setup_ifname)"
  25. uci_set network setup type 'bridge'
  26. uci_set network setup proto 'static'
  27. uci_set network setup ipaddr "$SETUP_MODE_ADDR"
  28. uci_set network setup netmask "$SETUP_MODE_NETMASK"
  29. uci_commit network
  30. SERVICE_DAEMONIZE=1
  31. SERVICE_WRITE_PID=1
  32. service_start /sbin/netifd -c "$UCI_CONFIG_DIR"
  33. setup_switch() { return 0; }
  34. include /lib/network
  35. setup_switch
  36. )
  37. }
  38. start() {
  39. . /lib/gluon/functions/sysconfig.sh
  40. enable=0
  41. config_load gluon-setup-mode
  42. config_foreach check_enable setup_mode
  43. if [ "$enable" = '1' ]; then
  44. lua -luci -e 'require "luci.model.uci"; uci_state=luci.model.uci.cursor_state(); uci_state:section("gluon-setup-mode", "setup_mode", nil, { running = "1" }); uci_state:save("gluon-setup-mode")'
  45. uci set 'gluon-setup-mode.@setup_mode[0].enabled=0'
  46. uci commit gluon-setup-mode
  47. setup_network
  48. /usr/sbin/telnetd -l /lib/gluon/setup-mode/ash-login
  49. /etc/init.d/dropbear start
  50. /usr/sbin/uhttpd -h /lib/gluon/setup-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80
  51. /usr/sbin/dnsmasq -p 0 -F $SETUP_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router
  52. /etc/init.d/led start
  53. # correctly finish firstboot
  54. /etc/init.d/done boot
  55. . /etc/diag.sh
  56. get_status_led
  57. status_led_set_timer 1000 300
  58. # block further boot
  59. while true; do sleep 1; done
  60. fi
  61. }