[arch-general] [PATCH 48/48] Trivial bashification of network

2010-06-30 Thread Victor Lowther
---
 network |   70 +++---
 1 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/network b/network
index 40f1a90..20ff9c7 100755
--- a/network
+++ b/network
@@ -9,17 +9,15 @@ done
 
 ifup()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 ifup interface_name
 return 1
 fi
-
 eval ifcfg=\$${1}
 
 # Get the name of the interface from the first token in the string
-
-if [ $ifcfg = dhcp ]; then
-ifname=$1
+if [[ $ifcfg = dhcp ]]; then
+ifname=$1
 else
 ifname=${ifcfg%% *}
 fi
@@ -28,7 +26,7 @@ ifup()
 
 wi_up $1 || return 1
 
-if [ $ifcfg = dhcp ]; then
+if [[ $ifcfg = dhcp ]]; then
 # remove the .pid file if it exists
 /bin/rm -f /var/run/dhcpcd-${1}.pid /dev/null 21
 /bin/rm -f /var/run/dhcpcd-${1}.cache /dev/null 21
@@ -36,20 +34,19 @@ ifup()
 else
 /sbin/ifconfig $ifcfg
 fi
-return $?
 }
 
 wi_up()
 {
 eval iwcfg=\$wlan_${1}
-[ $iwcfg =  ]  return 0
+[[ ! $iwcfg ]]  return 0
 
 /usr/sbin/iwconfig $iwcfg
-[[ -z $WIRELESS_TIMEOUT ]]  WIRELESS_TIMEOUT=2
+[[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2
 sleep $WIRELESS_TIMEOUT
 
-bssid=`iwgetid $1 -ra`
-if [[ $bssid = 00:00:00:00:00:00 ]]; then
+bssid=$(iwgetid $1 -ra)
+if [[ $bssid = 00:00:00:00:00:00 ]]; then
 printhl Could not associate $1 - try increasing WIRELESS_TIMEOUT and 
check network is WEP or has no security
 return 1
 fi
@@ -58,25 +55,22 @@ wi_up()
 
 ifdown()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 ifdown interface_name
 return 1
 fi
 eval ifcfg=\$${1}
-if [ $ifcfg = dhcp ]; then
-if [ -f /var/run/dhcpcd-${1}.pid ]; then
-/bin/kill $(cat /var/run/dhcpcd-${1}.pid)
-fi
+if [[ $ifcfg = dhcp  -f /var/run/dhcpcd-${1}.pid ]]; then
+/bin/kill $(cat /var/run/dhcpcd-${1}.pid)
 fi
 # Always bring the interface itself down
 /sbin/ifconfig ${1} down /dev/null 21
-return $?
 }
 
 iflist()
 {
 for ifline in ${interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 printf  $ifline:\t
 else
 printf $ifline:\t
@@ -88,38 +82,36 @@ iflist()
 
 rtup()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 rtup route_name
 return 1
 fi
 eval routecfg=\$${1}
-if grep -q ::  $routecfg; then
+if [[ $routecfg =~ :: ]]; then
 /sbin/route -A inet6 add $routecfg
 else
 /sbin/route add $routecfg
 fi
-return $?
 }
 
 rtdown()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]; then
 echo usage: $0 rtdown route_name
 return 1
 fi
 eval routecfg=\$${1}
-if grep -q ::  $routecfg; then
+if [[ $routecfg =~ :: ]]; then
 /sbin/route -A inet6 del $routecfg
 else
 /sbin/route del $routecfg
 fi
-return $?
 }
 
 rtlist()
 {
 for rtline in ${rout...@]}; do
-if [ $rtline = ${rtline#!} ]; then
+if [[ $rtline = ${rtline#!} ]]; then
 printf  $rtline:\t
 else
 printf $rtline:\t
@@ -132,9 +124,9 @@ rtlist()
 bond_up()
 {
 for ifline in ${bond_interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 eval bondcfg=\$bond_${ifline}
-if [ -n ${bondcfg} ]; then
+if [[ ${bondcfg} ]]; then
 /sbin/ifenslave $ifline $bondcfg || error=1
 fi
 fi
@@ -144,7 +136,7 @@ bond_up()
 bond_down()
 {
 for ifline in ${bond_interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 eval bondcfg=\$bond_${ifline}
 /sbin/ifenslave -d $ifline $bondcfg || error=1
 fi
@@ -154,18 +146,18 @@ bond_down()
 bridge_up()
 {
 for br in ${bridge_interfac...@]}; do
-if [ $br = ${br#!} ]; then
+if [[ $br = ${br#!} ]]; then
 # if the bridge already exists, remove it
-if [ $(/sbin/ifconfig $br 2/dev/null) ]; then
+if [[ $(/sbin/ifconfig $br 2/dev/null) ]]; then
 /sbin/ifconfig $br down
 /usr/sbin/brctl delbr $br
 fi
 /usr/sbin/brctl addbr $br
 eval brifs=\$bridge_${br}
 for brif in $brifs; do
-if [ $brif = ${brif#!} ]; then
+if [[ $brif = ${brif#!} ]]; then
 for ifline in ${bond_interfac...@]}; do
-if [ $brif = $ifline ]  [ $ifline = 
${ifline#!} ]; then
+if [[ $brif = $ifline  $ifline = ${ifline#!} ]]; then
 ifup $ifline
 eval bondcfg=\$bond_${ifline}
 

Re: [arch-general] [PATCH 48/48] Trivial bashification of network

2010-06-30 Thread Alexander Duscheleit
Thomas, while you're working on rc.d/network, could you please have
another look @ FS#16625? It's been sitting stale for quite a while.

It would *really* speed up networking for us bridge
users, and bridging is becoming more and more common with all the
virtualization around.