networksetup scripts suddenly not applying some settings

nkalister
Valued Contributor

Hey jamfnation, I've been using a script with some networksetup commands in it to configure our corporate proxy settings, and it's been 100% reliable with Lion . . . but now with Mountain Lion, it's failing to configure Wi-Fi occasionally . . .but not always! Sometimes it works, some times not. I'm running the script during imaging, after the reboot.
Anyone else seen this with 10.8?
Here's the script:

#!/bin/sh

# HARDCODED VALUES ARE SET HERE
wired="Ethernet"
wireless="Wi-Fi"
usb="USB Ethernet"
display="Display Ethernet"
tbolt="Thunderbolt Ethernet"
proxyAddress="http.hds.com"
port="8080"

#detect network interfaces
usbAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: USB Ethernet"`
displayAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Display Ethernet"`
tboltAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt Ethernet"`
wiredAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Ethernet"`
wifiAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Wi-Fi"`

# check for existing HDS location
HDSlocation=`/usr/sbin/networksetup -listlocations | grep HDS`
if [ "$HDSlocation" == "" ]; then
    echo "Creating HDS Location"
    /usr/sbin/networksetup -createlocation HDS populate
fi
/usr/sbin/networksetup -switchtolocation HDS

if [ "$wiredAdapter" != "" ]; then
    /usr/sbin/networksetup -setwebproxy "$wired" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setftpproxy "$wired" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setsecurewebproxy "$wired" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setproxybypassdomains "$wired" *.local 169.254/16 *.corp.hds.com *.hds.com
    /usr/sbin/networksetup -setsearchdomains "$wired" corp.hds.com hds.com
fi

if [ "$wifiAdapter" != "" ]; then
    /usr/sbin/networksetup -setwebproxy "$wireless" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setftpproxy "$wireless" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setsecurewebproxy "$wireless" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setproxybypassdomains "$wireless" *.local 169.254/16 *.corp.hds.com *.hds.com
    /usr/sbin/networksetup -setsearchdomains "$wireless" corp.hds.com hds.com
fi

if [ "$usbAdapter" != "" ]; then
    /usr/sbin/networksetup -setwebproxy "$usb" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setftpproxy "$usb" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setsecurewebproxy "$usb" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setproxybypassdomains "$usb" *.local 169.254/16 *.corp.hds.com *.hds.com
    /usr/sbin/networksetup -setsearchdomains "$usb" corp.hds.com hds.com
fi

if [ "$displayAdapter" != "" ]; then
    /usr/sbin/networksetup -setwebproxy "$display" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setftpproxy "$display" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setsecurewebproxy "$display" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setproxybypassdomains "$display" *.local 169.254/16 *.corp.hds.com *.hds.com
    /usr/sbin/networksetup -setsearchdomains "$display" corp.hds.com hds.com
fi

if [ "$tboltAdapter" != "" ]; then
    /usr/sbin/networksetup -setwebproxy "$tbolt" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setftpproxy "$tbolt" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setsecurewebproxy "$tbolt" "$proxyAddress" "$port"
    /usr/sbin/networksetup -setproxybypassdomains "$tbolt" *.local 169.254/16 *.corp.hds.com *.hds.com
    /usr/sbin/networksetup -setsearchdomains "$tbolt" corp.hds.com hds.com
fi
10 REPLIES 10

Chris
Valued Contributor

Funny you mention this, i'm seeing a similar issue.
My script (working 100% on Lion) sets up 8 or 9 different Locations.
In ML, i often see 1 or 2 missing, or the proxy port being set to "8,080" instead of "8080"...
Haven't really had time to look into it yet though.

nkalister
Valued Contributor

hmmmm . . . well, good to know its not just me. I may open a case with applecare about this, then.
i'm also seeing the 8,080 for the ports in ML. doesn't seem to affect functionality, though, so that's OK with me.

another bit of weirdness- if I run the script from self service, it NEVER fails.

nkalister
Valued Contributor

ok, case is open with applecare. we'll see what they have to say.

nkalister
Valued Contributor

apple makes me laugh sometimes . . . they suggested adding wait statements between every command in the script.
testing it now, 2 machines imaged and both ran all the commands successfully. we'll see.

Chris
Valued Contributor

I DID JUST THAT AND EVEN IF IT WORKS IT'S STUPID!!!
Sorry, couldn't resist...

gregp
Contributor

Heh.

We're using networksetup as well, but haven't had that problem. Our script is a little simpler too.

We found that we also had to add sleeps for our AD binding script with dsconfigad & a few other utils. But not just adding sleeps, but repeating the same command 2-3 times to make sure it takes hold. Been doing this for years and it works.

nkalister
Valued Contributor

hmmm . . .this is getting more interesting now. I have a USB boot disk that I use for imaging, and I'm finding that if I set the proxy settings while booted from that disk, the settings will only stay in place on that machine. As soon as I take the USB disk to another mac and boot that, the proxy settings and the location are gone.

tlarkin
Honored Contributor

Hey Nick,

I am in an Airport currently waiting on my connecting flights and reading up on JAMF Nation. I don't have a Mountain Lion client machine handy...yeah I know I am a late adopter when it comes to OSes...

Anyway, I'd be curious to see where your script breaks by looking at the output of your script, line by line. I use this when testing and debugging scripts a lot. Just do this in terminal:

sudo bash -x /path/to/script.sh

Then you can look at all the output, it even tells you what variables are assigned. Really nifty trick to use when debugging.

Hope that helps you figure out where it is failing.

Thanks,
Tom

nkalister
Valued Contributor

thanks tom! I'm fairly confident the script is not the problem, though . . . it looks like 10.8 is replacing the /Library/Preferences/SystemConfiguration/preferences.plist file at boot, and under some circumstances proxy settings are not carried over to the new version of the file. That's what appears to be happening with my USB boot disk anyway- the proxy settings are present in the /Library/Preferences/SystemConfiguration/preferences.plist.old file, but not in the current version when the stick is moved from one machine to another. I've reported that to applecare, we'll see what they have to say on monday!

tkimpton
Valued Contributor II

How about a policy that runs it at startup?