diff --git a/README.md b/README.md index 0215372..94660cb 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Version history - 0.1 - Initial release - 0.2 - Added automatic IP detection +- 0.3 - Make setup.sh a bit more reliable Description diff --git a/setup.sh b/setup.sh index 555f01e..f4c5df3 100755 --- a/setup.sh +++ b/setup.sh @@ -1,16 +1,50 @@ #!/bin/bash -localip=`/sbin/ifconfig en0 |grep 'inet ' |xargs -L1 |cut -d ' ' -f2` +if [ "$1" == "-i" ] ; then + if [ "$2" == "" ] ; then + echo "-i needs a parameter, eg: -i en0" + exit 1 + fi + wifi_interface="$2" +else + wifi_interface=`/usr/sbin/networksetup -listallhardwareports |grep -A1 -i 'Wi-Fi' |tail -n1 |cut -d ' ' -f2` +fi -echo "Waiting for iDevice..." -while : -do - deviceip=`ping -c16 -t2 169.254.255.255 2>/dev/null |grep 'bytes from' |grep -v "$localip" |tail -n1 |cut -d ' ' -f4 |cut -d ':' -f1` +if [ "$wifi_interface" == "" ] ; then + echo + echo "Unable to detect your wifi interface." + echo + echo "You can specify it manually with -i, eg:" + echo + echo "$0 -i en0" + echo + exit 1 +fi - if [ "$deviceip" != "" ] ; then - break - fi +checkif=`/sbin/ifconfig "$wifi_interface" 2>/dev/null` + +if [ "$checkif" == "" ] ; then + echo "interface $wifi_interface does not exist" + exit 1 +fi + +echo -n "Waiting for local self-assign IP... " + +while [ "$localip" == "" ] ; do + localip=`/sbin/ifconfig $wifi_interface |grep 'inet ' |xargs -L1 |cut -d ' ' -f2` + sleep 1 done +echo "$localip" + +echo -n "Waiting for iDevice... " + +while [ "$deviceip" == "" ] ; do + deviceip=`ping -c16 -t2 169.254.255.255 2>/dev/null |grep 'bytes from' |grep -v "$localip" |tail -n1 |cut -d ' ' -f4 |cut -d ':' -f1` + sleep 1 +done + +echo "$deviceip" + killall Proxifier 1>/dev/null 2>/dev/null sleep 2 cp proxifier.template ~/Library/Application\ Support/Proxifier/Profiles/default.ppx