WPA en Debian/Kubuntu parte 2

Con la configuración que teníamos antes al arrancar el ordenador si no estábamos dentro de la red wpa, el wpa_assistant nos dejaba sin poder conectarnos a otras redes, pero nosotros queremos que al arrancar nos conecte a nuestra red wpa o a otra red abierta. Lo que hemos hecho en este programa es detectar la red con nuestro ESSID y si estamos en ella se conecta.
#!/bin/bash
# $1 [ start | stop]
# $2 [ESSID]
# $3 [interface]
# $4 driver, [hostap | hermes | madwifi | atmel | wext | ndiswrapper | broadcom | ipw | wired | bsd | ndis]
# conecta_wpa.sh start Luiso eth1 wext
case "$1" in
start)
	if [ "$2" == "" ]||[ "$3" == "" ]||[ "$4" == "" ];
	then
		echo "I'm not a fortune teller, "$0" start essid interface driver"
		exit 1
	fi
	LISTA=$(iwlist $3 scan |awk -F'"' '/ESSID/{print $2}')

	for i in $LISTA
	do
		if [ "$i" == "$2" ];
		then
			echo $i ok, connecting...
			WPA_EXEC=$(which wpa_supplicant)
			if [ "$?" == "0" ];
			then
				$WPA_EXEC -Bw -D$4 -i$3 -c/etc/wpa_supplicant.conf
			else
				echo "wpa_supplicant not found"
				exit 1
			fi
			exit 0
		fi
	done
	echo "ESSID: "$2" not found :("
	#I need to exit with 0 to try to connect with other networks, without wpa.
	exit 0
        ;;
stop)
	killall -q wpa_supplicant
	;;
*)
	echo "What I have to do? [start | stop]: "$0" start essid interface driver"
esac
Y ahora en /etc/network/interfaces
auto eth1
iface eth1 inet dhcp
pre-up /root/conecta_wpa.sh start Luiso eth1 wext
post-down /root/conecta_wpa.sh stop