echo -n "Enter the SSID: "; read ssid
echo -n "Enter the passphrase: "; read pass
echo -n "Enter the WPA version [1|2]:"; read ver

conf="/home/olpc/.sugar/default/nm/networks.cfg"
wpapass=`which /usr/sbin/wpa_passphrase`

key=`$wpapass "$ssid" "$pass" | grep psk= | grep -v "#" | cut -d= -f 2`
timestamp=`date +%s`

case $ver in
  1) we_cipher=0;key_mgmt=2;wpa_ver=2;;
  2) we_cipher=0;key_mgmt=2;wpa_ver=4;;
esac

cat << EOF >> $conf
[$ssid]
timestamp = $timestamp
we_cipher = $we_cipher
key = $key
key_mgmt = $key_mgmt
bssids = $bssids
wpa_ver = $wpa_ver
EOF

echo; echo "Now, reboot your XO, and try to connect again (just click on the circle)"
