uci-defaults.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #!/bin/sh
  2. # Copyright (C) 2011 OpenWrt.org
  3. UCIDEF_LEDS_CHANGED=0
  4. ucidef_set_led_netdev() {
  5. local cfg="led_$1"
  6. local name=$2
  7. local sysfs=$3
  8. local dev=$4
  9. uci -q get system.$cfg && return 0
  10. uci batch <<EOF
  11. set system.$cfg='led'
  12. set system.$cfg.name='$name'
  13. set system.$cfg.sysfs='$sysfs'
  14. set system.$cfg.trigger='netdev'
  15. set system.$cfg.dev='$dev'
  16. set system.$cfg.mode='link tx rx'
  17. EOF
  18. UCIDEF_LEDS_CHANGED=1
  19. }
  20. ucidef_set_led_usbdev() {
  21. local cfg="led_$1"
  22. local name=$2
  23. local sysfs=$3
  24. local dev=$4
  25. uci -q get system.$cfg && return 0
  26. uci batch <<EOF
  27. set system.$cfg='led'
  28. set system.$cfg.name='$name'
  29. set system.$cfg.sysfs='$sysfs'
  30. set system.$cfg.trigger='usbdev'
  31. set system.$cfg.dev='$dev'
  32. set system.$cfg.interval='50'
  33. EOF
  34. UCIDEF_LEDS_CHANGED=1
  35. }
  36. ucidef_set_led_wlan() {
  37. local cfg="led_$1"
  38. local name=$2
  39. local sysfs=$3
  40. local trigger=$4
  41. uci -q get system.$cfg && return 0
  42. uci batch <<EOF
  43. set system.$cfg='led'
  44. set system.$cfg.name='$name'
  45. set system.$cfg.sysfs='$sysfs'
  46. set system.$cfg.trigger='$trigger'
  47. EOF
  48. UCIDEF_LEDS_CHANGED=1
  49. }
  50. ucidef_set_led_switch() {
  51. local cfg="led_$1"
  52. local name=$2
  53. local sysfs=$3
  54. local trigger=$4
  55. local port_mask=$5
  56. uci -q get system.$cfg && return 0
  57. uci batch <<EOF
  58. set system.$cfg='led'
  59. set system.$cfg.name='$name'
  60. set system.$cfg.sysfs='$sysfs'
  61. set system.$cfg.trigger='$trigger'
  62. set system.$cfg.port_mask='$port_mask'
  63. EOF
  64. UCIDEF_LEDS_CHANGED=1
  65. }
  66. ucidef_set_led_default() {
  67. local cfg="led_$1"
  68. local name=$2
  69. local sysfs=$3
  70. local default=$4
  71. uci -q get system.$cfg && return 0
  72. uci batch <<EOF
  73. set system.$cfg='led'
  74. set system.$cfg.name='$name'
  75. set system.$cfg.sysfs='$sysfs'
  76. set system.$cfg.default='$default'
  77. EOF
  78. UCIDEF_LEDS_CHANGED=1
  79. }
  80. ucidef_set_led_rssi() {
  81. local cfg="led_$1"
  82. local name=$2
  83. local sysfs=$3
  84. local iface=$4
  85. local minq=$5
  86. local maxq=$6
  87. local offset=$7
  88. local factor=$8
  89. uci -q get system.$cfg && return 0
  90. uci batch <<EOF
  91. set system.$cfg='led'
  92. set system.$cfg.name='$name'
  93. set system.$cfg.sysfs='$sysfs'
  94. set system.$cfg.trigger='rssi'
  95. set system.$cfg.iface='rssid_$iface'
  96. set system.$cfg.minq='$minq'
  97. set system.$cfg.maxq='$maxq'
  98. set system.$cfg.offset='$offset'
  99. set system.$cfg.factor='$factor'
  100. EOF
  101. UCIDEF_LEDS_CHANGED=1
  102. }
  103. ucidef_set_led_timer() {
  104. local cfg="led_$1"
  105. local name=$2
  106. local sysfs=$3
  107. local delayon=$4
  108. local delayoff=$5
  109. uci -q get system.$cfg && return 0
  110. uci batch <<EOF
  111. set system.$cfg='led'
  112. set system.$cfg.name='$name'
  113. set system.$cfg.sysfs='$sysfs'
  114. set system.$cfg.trigger='timer'
  115. set system.$cfg.delayon='$delayon'
  116. set system.$cfg.delayoff='$delayoff'
  117. EOF
  118. UCIDEF_LEDS_CHANGED=1
  119. }
  120. ucidef_set_led_mmc() {
  121. local cfg="led_$1"
  122. local name=$2
  123. local sysfs=$3
  124. local trigger=$4
  125. uci -q get system.$cfg && return 0
  126. uci batch <<EOF
  127. set system.$cfg='led'
  128. set system.$cfg.name='$name'
  129. set system.$cfg.sysfs='$sysfs'
  130. set system.$cfg.trigger='$trigger'
  131. EOF
  132. UCIDEF_LEDS_CHANGED=1
  133. }
  134. ucidef_set_rssimon() {
  135. local dev="$1"
  136. local refresh="$2"
  137. local threshold="$3"
  138. local cfg="rssid_$dev"
  139. uci -q get system.$cfg && return 0
  140. uci batch <<EOF
  141. set system.$cfg='rssid'
  142. set system.$cfg.dev='$dev'
  143. set system.$cfg.refresh='$refresh'
  144. set system.$cfg.threshold='$threshold'
  145. EOF
  146. UCIDEF_LEDS_CHANGED=1
  147. }
  148. ucidef_commit_leds()
  149. {
  150. [ "$UCIDEF_LEDS_CHANGED" = "1" ] && uci commit system
  151. }
  152. ucidef_set_interface_loopback() {
  153. uci batch <<EOF
  154. set network.loopback='interface'
  155. set network.loopback.ifname='lo'
  156. set network.loopback.proto='static'
  157. set network.loopback.ipaddr='127.0.0.1'
  158. set network.loopback.netmask='255.0.0.0'
  159. set network.globals='globals'
  160. set network.globals.ula_prefix='auto'
  161. EOF
  162. }
  163. ucidef_set_interface_raw() {
  164. local cfg=$1
  165. local ifname=$2
  166. local proto=${3:-"none"}
  167. uci batch <<EOF
  168. set network.$cfg='interface'
  169. set network.$cfg.ifname='$ifname'
  170. set network.$cfg.proto='$proto'
  171. EOF
  172. }
  173. ucidef_set_interface_lan() {
  174. local ifname=$1
  175. uci batch <<EOF
  176. set network.lan='interface'
  177. set network.lan.ifname='$ifname'
  178. set network.lan.force_link=1
  179. set network.lan.type='bridge'
  180. set network.lan.proto='static'
  181. set network.lan.ipaddr='192.168.1.1'
  182. set network.lan.netmask='255.255.255.0'
  183. set network.lan.ip6assign='60'
  184. EOF
  185. }
  186. ucidef_set_interface_wan() {
  187. local ifname=$1
  188. uci batch <<EOF
  189. set network.wan='interface'
  190. set network.wan.ifname='$ifname'
  191. set network.wan.proto='dhcp'
  192. set network.wan6='interface'
  193. set network.wan6.ifname='$ifname'
  194. set network.wan6.proto='dhcpv6'
  195. EOF
  196. }
  197. ucidef_set_interfaces_lan_wan() {
  198. local lan_ifname=$1
  199. local wan_ifname=$2
  200. ucidef_set_interface_lan "$lan_ifname"
  201. ucidef_set_interface_wan "$wan_ifname"
  202. }
  203. ucidef_set_interface_macaddr() {
  204. local ifname=$1
  205. local mac=$2
  206. uci batch <<EOF
  207. set network.$ifname.macaddr='$mac'
  208. EOF
  209. }
  210. ucidef_add_switch() {
  211. local name=$1
  212. local reset=$2
  213. local enable=$3
  214. uci batch <<EOF
  215. add network switch
  216. set network.@switch[-1].name='$name'
  217. set network.@switch[-1].reset='$reset'
  218. set network.@switch[-1].enable_vlan='$enable'
  219. EOF
  220. }
  221. ucidef_add_switch_vlan() {
  222. local device=$1
  223. local vlan=$2
  224. local ports=$3
  225. uci batch <<EOF
  226. add network switch_vlan
  227. set network.@switch_vlan[-1].device='$device'
  228. set network.@switch_vlan[-1].vlan='$vlan'
  229. set network.@switch_vlan[-1].ports='$ports'
  230. EOF
  231. }
  232. ucidef_add_switch_port() {
  233. local device=$1
  234. local port=$2
  235. uci batch <<EOF
  236. add network switch_port
  237. set network.@switch_port[-1].device='$device'
  238. set network.@switch_port[-1].port='$port'
  239. EOF
  240. }