[pisa-src] r941 - trunk/tools

Author: biurrun
Date: Fri Sep  4 18:33:36 2009
New Revision: 941

Log:
Introduce a function to print the command before running it instead of
duplicating the command name with echo.

Modified:
   trunk/tools/switch-ip

Modified: trunk/tools/switch-ip
==============================================================================
--- trunk/tools/switch-ip       Fri Sep  4 18:30:01 2009        (r940)
+++ trunk/tools/switch-ip       Fri Sep  4 18:33:36 2009        (r941)
@@ -43,6 +43,10 @@
 NEW_WEP_KEY=""
 USEWEPKEYS=0
 
+run_verbose() {
+    echo $@
+    $@
+}
 delroute() {
     rt_entries=$(route -n |grep $IFWLAN)
 
@@ -219,66 +223,48 @@
 
 case "$CMD" in
     arponly)
-        echo "iwconfig $IFWLAN $IWCONFIG_OPTIONS"
-        iwconfig $IFWLAN $IWCONFIG_OPTIONS
+        run_verbose iwconfig $IFWLAN $IWCONFIG_OPTIONS
 
-        echo "arp -d $AP_IP"
-        arp -d $AP_IP 2> /dev/null
+        run_verbose arp -d $AP_IP 2> /dev/null
         ;;
     ifconfig)
-        echo "iwconfig $IFWLAN $IWCONFIG_OPTIONS"
-        iwconfig $IFWLAN $IWCONFIG_OPTIONS
+        run_verbose iwconfig $IFWLAN $IWCONFIG_OPTIONS
 
-        echo "ifconfig $IFWLAN $NEW_IP netmask $NETMASK"
-        ifconfig $IFWLAN $NEW_IP netmask $NETMASK
+        run_verbose ifconfig $IFWLAN $NEW_IP netmask $NETMASK
 
         # As arp cache sometimes causes wireless association to be confused,
         # we need to make sure that any arp entries for the new AP are deleted.
-        # echo "arp -d $AP_IP"
-        # arp -d $AP_IP
+        # run_verbose arp -d $AP_IP
         #
         # arp -s $AP_IP $NEW_MAC_ADR
 
-         echo "route del -net $DESTINATION netmask $NETMASK"
-         route del -net $DESTINATION netmask $NETMASK 2> /dev/null
+         run_verbose route del -net $DESTINATION netmask $NETMASK 2> /dev/null
          if test $ROUTE_EXTRA_CMD; then
-             echo route add -net $DESTINATION netmask $NETMASK dev $IFWLAN
-             route add -net $DESTINATION netmask $NETMASK dev $IFWLAN
+             run_verbose route add -net $DESTINATION netmask $NETMASK dev 
$IFWLAN
          fi
-         echo "route add -net $DESTINATION netmask $NETMASK gw $AP_IP"
-         route add -net $DESTINATION netmask $NETMASK gw $AP_IP 2> /dev/null
+         run_verbose route add -net $DESTINATION netmask $NETMASK gw $AP_IP 2> 
/dev/null
 
-         # echo "ip -6 route del $DEST_IPV6 dev $IFDUMMY"
-         # ip -6 route del $DEST_IPV6 dev $IFDUMMY 2> /dev/null
+         # run_verbose ip -6 route del $DEST_IPV6 dev $IFDUMMY 2> /dev/null
          ;;
      dhcp)
-         echo "iwconfig $IFWLAN essid $NEW_SSID ap $NEW_MAC_ADR"
-         iwconfig $IFWLAN essid "$NEW_SSID" ap "$NEW_MAC_ADR"
+         run_verbose iwconfig $IFWLAN essid "$NEW_SSID" ap "$NEW_MAC_ADR"
 
-         echo "killall $DHCP_CMD"
-         killall $DHCP_CMD
+         run_verbose killall $DHCP_CMD
 
-         echo "Deleting routing table entries for $IFWLAN..."
-         delroute
+         run_verbose delroute
 
          echo "Getting a new IP configuration for $IFWLAN via DHCP..."
-         echo $DHCP_CMD $IFWLAN
-         $DHCP_CMD $IFWLAN
+         $run_verbose DHCP_CMD $IFWLAN
 
-         echo "route add -net $DESTINATION netmask $NETMASK gw $AP_IP"
-         route add -net $DESTINATION netmask $NETMASK gw $AP_IP
+         run_verbose route add -net $DESTINATION netmask $NETMASK gw $AP_IP
          ;;
      channel)
-         echo "iwconfig $IFWLAN essid $NEW_SSID channel 5"
-         iwconfig $IFWLAN essid $NEW_SSID channel 5
+         run_verbose iwconfig $IFWLAN essid $NEW_SSID channel 5
 
-         echo "ifconfig $IFWLAN $NEW_IP"
-         ifconfig $IFWLAN $NEW_IP
+         run_verbose ifconfig $IFWLAN $NEW_IP
 
-         echo "route del -net $DESTINATION netmask $NETMASK"
-         route del -net $DESTINATION netmask $NETMASK 2> /dev/null
-         echo "route add -net $DESTINATION netmask $NETMASK gw $AP_IP"
-         route add -net $DESTINATION netmask $NETMASK gw $AP_IP 2> /dev/null
+         run_verbose route del -net $DESTINATION netmask $NETMASK 2> /dev/null
+         run_verbose route add -net $DESTINATION netmask $NETMASK gw $AP_IP 2> 
/dev/null
          ;;
 esac
 

Other related posts: