gluon-setup-mode 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "$(lua -e 'print(require("gluon.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. enable=0
  40. config_load gluon-setup-mode
  41. config_foreach check_enable setup_mode
  42. if [ "$enable" = '1' ]; then
  43. 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")'
  44. uci set 'gluon-setup-mode.@setup_mode[0].enabled=0'
  45. uci commit gluon-setup-mode
  46. setup_network
  47. /usr/sbin/telnetd -l /lib/gluon/setup-mode/ash-login
  48. /etc/init.d/dropbear start
  49. /usr/sbin/uhttpd -h /lib/gluon/setup-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80
  50. /usr/sbin/dnsmasq -p 0 -F $SETUP_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router
  51. /etc/init.d/led start
  52. # correctly finish firstboot
  53. /etc/init.d/done boot
  54. . /etc/diag.sh
  55. get_status_led
  56. status_led_set_timer 1000 300
  57. # block further boot
  58. while true; do sleep 1; done
  59. fi
  60. }