Author: biurrun Date: Fri Sep 4 18:13:02 2009 New Revision: 937 Log: The --dhcp_cmd and --route_extra_cmd options were not working properly due to getopt not understanding spaces in option values. So the options are converted into flags called --udhcpc and --route_extra_cmd that trigger the desired behavior. This is less flexible than the previous version intended to be, but it works as expected. Modified: trunk/tools/switch-ip Modified: trunk/tools/switch-ip ============================================================================== --- trunk/tools/switch-ip Fri Sep 4 18:00:11 2009 (r936) +++ trunk/tools/switch-ip Fri Sep 4 18:13:02 2009 (r937) @@ -85,8 +85,8 @@ echo " --apmac2=xx:xx:xx:xx:xx:xx : MAC address of the 2nd access point" echo " --apssid1=<ssid1> : SSID of the 1st access point" echo " --apssid2=<ssid2> : SSID of the 2nd access point" - echo " --dhcp_cmd=<command> : DHCP command to use" - echo " --route_extra_cmd=<command> : extra route command to use" + echo " --udhcpc : use udhcpc instead of dhclient" + echo " --route_extra_cmd : run extra route command" echo " --nowep : associate without WEP keys for access points" echo " -h : this help message" } @@ -114,7 +114,7 @@ #exit 1 fi -optarr=($(getopt -o 'hi:' --long 'myip1:,myip2:,apip1:,apip2:,apssid1:,apssid2:,apmac1:,apmac2:,dhcp_cmd:,route_extra_cmd:,nowep,help' -- "$@")) +optarr=($(getopt -o 'hi:' --long 'myip1:,myip2:,apip1:,apip2:,apssid1:,apssid2:,apmac1:,apmac2:,udhcpc,route_extra_cmd,nowep,help' -- "$@")) if [ $? != 0 ]; then usage @@ -170,15 +170,15 @@ APSSID2=${optarr[$(($i+1))]} i=$(($i+2)) ;; - --dhcp_cmd ) - echo "DHCP command = ${optarr[$(($i+1))]}" - DHCP_CMD=${optarr[$(($i+1))]} + --udhcpc ) + echo "Using udhcpc instead of dhclient" + DHCP_CMD="udhcpc -i" i=$(($i+2)) ;; --route_extra_cmd ) - echo "extra route command = ${optarr[$(($i+1))]}" - ROUTE_EXTRA_CMD=${optarr[$(($i+1))]} - i=$(($i+2)) + echo "Running extra route command" + ROUTE_EXTRA_CMD=1 + i=$(($i+1)) ;; --nowep ) echo "Running without WEP keys..."; USEWEPKEYS=0; i=$(($i+1));; -- ) i=$(($i+1)); break;; @@ -238,8 +238,10 @@ echo "route del -net $DESTINATION netmask $NETMASK" route del -net $DESTINATION netmask $NETMASK 2> /dev/null - echo $ROUTE_EXTRA_CMD - $ROUTE_EXTRA_CMD + if test $ROUTE_EXTRA_CMD; then + echo route add -net $DESTINATION netmask $NETMASK dev $IFWLAN + 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