Skip to content

Commit

Permalink
v0.3 - made the script a bit more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rkw committed Feb 26, 2016
1 parent 6b9dc27 commit 0eaf9a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 42 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0eaf9a9

Please sign in to comment.