Created
August 4, 2014 15:21
-
-
Save fuzzylogiq/3c1b27ed6b199d6628c2 to your computer and use it in GitHub Desktop.
Script for setting network location and IP in a mixed static/dhcp environment so that imaging could take place.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
function tryping { | |
ping -t 5 x.x.x.x > /dev/null 2>&1 | |
if [ $? == 0 ]; then exit 0; fi | |
} | |
rm -rf /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist | |
rm -rf /Library/Preferences/SystemConfiguration/preferences.* | |
networksetup -createlocation setup populate | |
networksetup -switchtolocation setup | |
# Turn off Wi-Fi | |
networksetup -setnetworkserviceenabled Wi-Fi off | |
# Find our Ethernet connection | |
myeth=$(networksetup -listallnetworkservices | awk '/Ethernet/ { print $0 }') | |
# Try the different setups | |
count="0" | |
while [ $count -lt 5 ]; do | |
networksetup -setmanual "$myeth" x.x.x.x x.x.x.x x.x.x.x | |
networksetup -setdnsservers "$myeth" x.x.x.x x.x.x.x | |
networksetup -setsearchdomains "$myeth" some.domain some.otherdomain | |
tryping | |
networksetup -setdhcp "$myeth" | |
tryping | |
count=$[$count+1] | |
done | |
osascript -e 'tell application "Finder" to display dialog "Unable to set network! Imaging cannot take place!"' | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment