S20network 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 type 'bridge'
  20. uci_set network setup proto 'static'
  21. uci_set network setup ipaddr "$SETUP_MODE_ADDR"
  22. uci_set network setup netmask "$SETUP_MODE_NETMASK"
  23. uci_commit network
  24. )
  25. }
  26. init_switch() {
  27. setup_switch() { return 0; }
  28. include /lib/network
  29. setup_switch
  30. }
  31. start_service() {
  32. prepare_config
  33. init_switch
  34. procd_open_instance
  35. procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config
  36. procd_set_param respawn
  37. procd_set_param watch network.interface
  38. [ -e /proc/sys/kernel/core_pattern ] && {
  39. procd_set_param limits core="unlimited"
  40. echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
  41. }
  42. procd_close_instance
  43. }
  44. reload_service() {
  45. init_switch
  46. ubus call network reload
  47. /sbin/wifi reload_legacy
  48. }
  49. stop_service() {
  50. /sbin/wifi down
  51. }
  52. service_running() {
  53. ubus -t 30 wait_for network.interface
  54. /sbin/wifi reload_legacy
  55. }
  56. restart() {
  57. ifdown -a
  58. sleep 1
  59. trap '' TERM
  60. stop "$@"
  61. start "$@"
  62. }
  63. shutdown() {
  64. ifdown -a
  65. stop
  66. }