Merge pull request #5 from andypiper/cleanup

Added error handling / cleanup
This commit is contained in:
Rob Zimmerman 2013-09-03 06:53:44 -07:00
commit 8a1b3348f2

View file

@ -31,10 +31,32 @@ wservice=`/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(wi-fi|airp
wifi=$(networksetup -listallhardwareports | awk "/$wservice/,/Ethernet/"' getline { print $2 }')
WirelessMAC=$(networksetup -getmacaddress $wifi | awk '{print $3}')
echo "Original MAC address is: $WirelessMAC"
cleanup()
{
sudo ifconfig $wifi lladdr $WirelessMAC
networksetup -setairportpower $wifi off
networksetup -setairportpower $wifi on
echo "Cycling of Relays has completed, MAC address reverted.\n"
}
ctrl_c()
{
# user quit midway through, so we should revert
# the MAC address by calling our cleanup function
echo "*** Interrupted ***"
cleanup
exit $?
}
# trap keyboard interrupt (control-c) or unexpected quit
trap ctrl_c SIGINT SIGTERM
if [ $1 == "full" ]
then
# Generate a full list of 160 MAC's when "full" mode is specified
# Generate a full list of 160 MACs when "full" mode is specified
# To use full mode: ./relaymyhome full
# Check the repo at github for more information.
echo "Full Mode enabled. Randomly seeding from full list of addresses."
@ -46,7 +68,7 @@ then
CharsA=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
CharsB=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F")
# Create the addresses programatically
# Create the addresses programmatically
count=0
for i in "${CharsA[@]}"
do
@ -70,7 +92,7 @@ then
else
# This standard set of MAC's will be used in standard mode
# This set of MACs will be used in standard mode
# Usage: ./relaymyhome
addr[0]='00:0D:67:15:2D:82'
addr[1]='00:0D:67:15:D7:21'
@ -105,10 +127,8 @@ else
done
fi
sudo ifconfig $wifi lladdr $WirelessMAC
networksetup -setairportpower $wifi off
networksetup -setairportpower $wifi on
# ... and we are done
cleanup
echo "Cycling of Relays has completed, MAC address reverted."
echo "Time to check your StreetPasses!"