S20network 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh /etc/rc.common
  2. SETUP_MODE_ADDR=192.168.1.1
  3. SETUP_MODE_NETMASK=255.255.255.0
  4. START=20
  5. STOP=90
  6. USE_PROCD=1
  7. delete_interface() {
  8. [ "$1" = 'loopback' ] || uci_remove network "$1"
  9. }
  10. prepare_config() {
  11. (
  12. export UCI_CONFIG_DIR=/var/gluon/setup-mode/config
  13. mkdir -p "$UCI_CONFIG_DIR"
  14. cp /etc/config/network "$UCI_CONFIG_DIR"
  15. config_load network
  16. config_foreach delete_interface interface
  17. uci_add network interface setup
  18. uci_set network setup ifname "$(lua -e 'print(require("gluon.sysconfig").setup_ifname)')"
  19. uci_set network setup macaddr "$(lua -e 'print(require("gluon.sysconfig").primary_mac)')"
  20. uci_set network setup type 'bridge'
  21. uci_set network setup proto 'static'
  22. uci_set network setup ipaddr "$SETUP_MODE_ADDR"
  23. uci_set network setup netmask "$SETUP_MODE_NETMASK"
  24. uci_commit network
  25. )
  26. }
  27. init_switch() {
  28. setup_switch() { return 0; }
  29. include /lib/network
  30. setup_switch
  31. }
  32. start_service() {
  33. prepare_config
  34. init_switch
  35. iw reg set "$(lua -e 'print(require("gluon.site").regdom())')"
  36. procd_open_instance
  37. procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config
  38. procd_set_param respawn
  39. procd_set_param watch network.interface
  40. [ -e /proc/sys/kernel/core_pattern ] && {
  41. procd_set_param limits core="unlimited"
  42. echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
  43. }
  44. procd_close_instance
  45. }
  46. reload_service() {
  47. init_switch
  48. ubus call network reload
  49. /sbin/wifi reload_legacy
  50. }
  51. stop_service() {
  52. /sbin/wifi down
  53. }
  54. service_running() {
  55. ubus -t 30 wait_for network.interface
  56. /sbin/wifi reload_legacy
  57. }
  58. restart() {
  59. ifdown -a
  60. sleep 1
  61. trap '' TERM
  62. stop "$@"
  63. start "$@"
  64. }
  65. shutdown() {
  66. ifdown -a
  67. stop
  68. }