#!/bin/bash
# This command will tell you the correct network id (last path element):
# gconftool-2 -R /system/osso/connectivity/IAP | egrep IAP\|name
N900_NETWORK_ID=84198f00-617a-4925-add6-34d7d5bbcf77
TARGET_NETWORK_ESSID="NOKLAB (802.11n/g)"
#TARGET_NETWORK_ESSID="IFRN"
LIST=$(sudo iwconfig wlan0 | awk -F":" '/ESSID/{print $2}')
LIST=${LIST%% *}
LIST=${LIST#* }
if ! [ "x${LIST/ /}" = "x\"$TARGET_NETWORK_ESSID\"" ]
then
echo "Connecting to noklab wifi"
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
sleep 2
dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:84198f00-617a-4925-add6-34d7d5bbcf77 uint32:0
else
echo "Already connected to the correct wifi."
fi
if ! ps aufx | grep -v grep | grep ssh-agent
then
ssh-agent > $HOME/.sshagentrc
source $HOME/.sshagentrc
ssh-add $HOME/.ssh/id_rsa
else
source $HOME/.sshagentrc
fi
case "${1}" in
"unlockert")
echo 2 | ssh -p 42 door@10.23.42.1
;;
"unlock")
echo 1 | ssh -p 42 door@10.23.42.1
;;
"lock")
echo 3 | ssh -p 42 door@10.23.42.1
;;
"outer")
echo 6 | ssh -p 42 door@10.23.42.1
;;
"inner")
echo 5 | ssh -p 42 door@10.23.42.1
;;
"x")
echo x | ssh -p 42 door@10.23.42.1
;;
*)
echo "Unknown argument: '$1', entering interactive mode."
ssh -p 42 door@10.23.42.1
;;
esac