ifup 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. ifup_all=
  3. setup_wifi=
  4. if_call() {
  5. local interface="$1"
  6. for mode in $modes; do
  7. ubus call network.interface $mode "{ \"interface\" : \"$interface\" }"
  8. done
  9. }
  10. case "$0" in
  11. *ifdown) modes=down;;
  12. *ifup)
  13. modes="down up"
  14. setup_wifi=1
  15. ;;
  16. *) echo "Invalid command: $0";;
  17. esac
  18. while :; do
  19. case "$1" in
  20. -a)
  21. ifup_all=1
  22. shift
  23. ;;
  24. -w)
  25. setup_wifi=
  26. shift
  27. ;;
  28. *)
  29. break
  30. ;;
  31. esac
  32. done
  33. [ "$modes" = "down up" ] && ubus call network reload
  34. if [ -n "$ifup_all" ]; then
  35. for interface in `ubus -S list 'network.interface.*'`; do
  36. if_call "${interface##network.interface.}"
  37. done
  38. [ -n "$setup_wifi" ] && /sbin/wifi up
  39. exit
  40. else
  41. ubus -S list "network.interface.$1" > /dev/null || {
  42. echo "Interface $1 not found"
  43. exit
  44. }
  45. if_call "$1"
  46. fi
  47. if [ -n "$setup_wifi" ] && grep -sq config /etc/config/wireless; then
  48. . /lib/functions.sh
  49. find_related_radios() {
  50. local wdev wnet
  51. config_get wdev "$1" device
  52. config_get wnet "$1" network
  53. if [ -n "$wdev" ]; then
  54. for wnet in $wnet; do
  55. if [ "$wnet" = "$network" ]; then
  56. append radio_devs "$wdev" "$N"
  57. fi
  58. done
  59. fi
  60. }
  61. network="$1"
  62. config_load wireless
  63. config_foreach find_related_radios wifi-iface
  64. for dev in $(echo "$radio_devs" | sort -u); do
  65. /sbin/wifi up "$dev"
  66. done
  67. fi