Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. . /etc/rc.conf
  4. . /etc/rc.d/functions
  5.  
  6. # wireless settings
  7. [ -f /etc/conf.d/wireless ] && . /etc/conf.d/wireless
  8. # ethernet bonding settings
  9. [ -f /etc/conf.d/bonding ] && . /etc/conf.d/bonding
  10. # bridge settings
  11. [ -f /etc/conf.d/bridges ] && . /etc/conf.d/bridges
  12. # dhcpcd settings
  13. [ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd
  14.  
  15. ifup()
  16. {
  17. if [ "$1" = "" ]; then
  18. echo "usage: $0 ifup <interface_name>"
  19. return 1
  20. fi
  21.  
  22. eval ifcfg="\$${1}"
  23.  
  24. # Get the name of the interface from the first token in the string
  25.  
  26. if [ "$ifcfg" = "dhcp" ]; then
  27. ifname="$1"
  28. else
  29. ifname=${ifcfg%% *}
  30. fi
  31.  
  32. /sbin/ifconfig $ifname up
  33.  
  34. wi_up $1 || return 1
  35.  
  36. if [ "$ifcfg" = "dhcp" ]; then
  37. # remove the .pid file if it exists
  38. /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1
  39. /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1
  40. /sbin/dhcpcd $DHCPCD_ARGS ${1}
  41. else
  42. /sbin/ifconfig $ifcfg
  43. fi
  44. return $?
  45. }
  46.  
  47. wi_up()
  48. {
  49. eval iwcfg="\$wlan_${1}"
  50. [ "$iwcfg" = "" ] && return 0
  51.  
  52. /usr/sbin/iwconfig $iwcfg
  53. [[ -z "$WIRELESS_TIMEOUT" ]] && WIRELESS_TIMEOUT=2
  54. sleep $WIRELESS_TIMEOUT
  55.  
  56. /usr/sbin/wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf || return 1
  57.  
  58. bssid=`iwgetid $1 -ra`
  59. if [[ "$bssid" = "00:00:00:00:00:00" ]]; then
  60. printhl "Could not associate $1 - try increasing WIRELESS_TIMEOUT and check network is WEP or has no security"
  61. return 1
  62. fi
  63. return 0
  64. }
  65.  
  66. ifdown()
  67. {
  68. if [ "$1" = "" ]; then
  69. echo "usage: $0 ifdown <interface_name>"
  70. return 1
  71. fi
  72. eval ifcfg="\$${1}"
  73. if [ "$ifcfg" = "dhcp" ]; then
  74. if [ -f /var/run/dhcpcd-${1}.pid ]; then
  75. /bin/kill $(cat /var/run/dhcpcd-${1}.pid)
  76. fi
  77. fi
  78. # Always bring the interface itself down
  79. /sbin/ifconfig ${1} down >/dev/null 2>&1
  80. return $?
  81. }
  82.  
  83. iflist()
  84. {
  85. for ifline in ${INTERFACES[@]}; do
  86. if [ "$ifline" = "${ifline#!}" ]; then
  87. printf " $ifline:\t"
  88. else
  89. printf "$ifline:\t"
  90. fi
  91. eval real_ifline=\$${ifline#!}
  92. echo $real_ifline
  93. done
  94. }
  95.  
  96. rtup()
  97. {
  98. if [ "$1" = "" ]; then
  99. echo "usage: $0 rtup <route_name>"
  100. return 1
  101. fi
  102. eval routecfg="\$${1}"
  103. if grep -q :: <<< $routecfg; then
  104. /sbin/route -A inet6 add $routecfg
  105. else
  106. /sbin/route add $routecfg
  107. fi
  108. return $?
  109. }
  110.  
  111. rtdown()
  112. {
  113. if [ "$1" = "" ]; then
  114. echo "usage: $0 rtdown <route_name>"
  115. return 1
  116. fi
  117. eval routecfg="\$${1}"
  118. if grep -q :: <<< $routecfg; then
  119. /sbin/route -A inet6 del $routecfg
  120. else
  121. /sbin/route del $routecfg
  122. fi
  123. return $?
  124. }
  125.  
  126. rtlist()
  127. {
  128. for rtline in ${ROUTES[@]}; do
  129. if [ "$rtline" = "${rtline#!}" ]; then
  130. printf " $rtline:\t"
  131. else
  132. printf "$rtline:\t"
  133. fi
  134. eval real_rtline=\$${rtline#!}
  135. echo $real_rtline
  136. done
  137. }
  138.  
  139. bond_up()
  140. {
  141. for ifline in ${BOND_INTERFACES[@]}; do
  142. if [ "$ifline" = "${ifline#!}" ]; then
  143. eval bondcfg="\$bond_${ifline}"
  144. if [ -n "${bondcfg}" ]; then
  145. /sbin/ifenslave $ifline $bondcfg || error=1
  146. fi
  147. fi
  148. done
  149. }
  150.  
  151. bond_down()
  152. {
  153. for ifline in ${BOND_INTERFACES[@]}; do
  154. if [ "$ifline" = "${ifline#!}" ]; then
  155. eval bondcfg="\$bond_${ifline}"
  156. /sbin/ifenslave -d $ifline $bondcfg || error=1
  157. fi
  158. done
  159. }
  160.  
  161. bridge_up()
  162. {
  163. for br in ${BRIDGE_INTERFACES[@]}; do
  164. if [ "$br" = "${br#!}" ]; then
  165. # if the bridge already exists, remove it
  166. if [ "$(/sbin/ifconfig $br 2>/dev/null)" ]; then
  167. /sbin/ifconfig $br down
  168. /usr/sbin/brctl delbr $br
  169. fi
  170. /usr/sbin/brctl addbr $br
  171. eval brifs="\$bridge_${br}"
  172. for brif in $brifs; do
  173. if [ "$brif" = "${brif#!}" ]; then
  174. for ifline in ${BOND_INTERFACES[@]}; do
  175. if [ "$brif" = "$ifline" ] && [ "$ifline" = "${ifline#!}" ]; then
  176. ifup $ifline
  177. eval bondcfg="\$bond_${ifline}"
  178. /sbin/ifenslave $ifline $bondcfg || error=1
  179. unset bond_${ifline}
  180. fi
  181. done
  182.  
  183. /usr/sbin/brctl addif $br $brif || error=1
  184. fi
  185. done
  186. fi
  187. done
  188. }
  189.  
  190. bridge_down()
  191. {
  192. for br in ${BRIDGE_INTERFACES[@]}; do
  193. if [ "$br" = "${br#!}" ]; then
  194. /usr/sbin/brctl delbr $br
  195. fi
  196. done
  197. }
  198.  
  199.  
  200. case "$1" in
  201. start)
  202. if ! ck_daemon network; then
  203. echo "Network is already running. Try 'network restart'"
  204. exit
  205. fi
  206.  
  207. stat_busy "Starting Network"
  208. error=0
  209. # bring up bridge interfaces
  210. bridge_up
  211. # bring up ethernet interfaces
  212. for ifline in ${INTERFACES[@]}; do
  213. if [ "$ifline" = "${ifline#!}" ]; then
  214. ifup $ifline || error=1
  215. fi
  216. done
  217. # bring up bond interfaces
  218. bond_up
  219. # bring up routes
  220. for rtline in "${ROUTES[@]}"; do
  221. if [ "$rtline" = "${rtline#!}" ]; then
  222. rtup $rtline || error=1
  223. fi
  224. done
  225. if [ $error -eq 0 ]; then
  226. add_daemon network
  227. stat_done
  228. else
  229. stat_fail
  230. fi
  231. ;;
  232. stop)
  233. #if ck_daemon network; then
  234. # echo "Network is not running. Try 'network start'"
  235. # exit
  236. #fi
  237.  
  238. if [ "${NETWORK_PERSIST}" = "yes" -o "${NETWORK_PERSIST}" = "YES" ]; then
  239. status "Skipping Network Shutdown" true
  240. exit 0
  241. fi
  242.  
  243. stat_busy "Stopping Network"
  244. rm_daemon network
  245. error=0
  246. for rtline in "${ROUTES[@]}"; do
  247. if [ "$rtline" = "${rtline#!}" ]; then
  248. rtdown $rtline || error=1
  249. fi
  250. done
  251. # bring down bond interfaces
  252. bond_down
  253. for ifline in ${INTERFACES[@]}; do
  254. if [ "$ifline" = "${ifline#!}" ]; then
  255. ifdown $ifline || error=1
  256. fi
  257. done
  258. # bring down bridge interfaces
  259. bridge_down
  260. if [ $error -eq 0 ]; then
  261. stat_done
  262. else
  263. stat_fail
  264. fi
  265. ;;
  266. restart)
  267. $0 stop
  268. /bin/sleep 2
  269. $0 start
  270. ;;
  271. ifup|ifdown|iflist|rtup|rtdown|rtlist)
  272. $1 $2
  273. ;;
  274. *)
  275. echo "usage: $0 {start|stop|restart}"
  276. echo " $0 {ifup|ifdown|iflist|rtup|rtdown|rtlist}"
  277. esac
  278.  
  279. # vim: set ts=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement