Connecting to SSID via post install script

mike_pinto
New Contributor III

Hello,

I was hoping someone could help me out with an issue that I'm running into. I've recently compiled a new Mavericks image (AutoDMG) and threw a post install script on top of it. For some reason I cannot get our clients to join the specified SSID (WPA2). Parsing through logs only shows: "Could not find network network_name." while wifi logs show: "en1 attached (down)".

I'm using the following in our script:
networksetup -addpreferredwirelessnetworkatindex en1 "ssid" 0 WPA2 "password"
networksetup -setairportnetwork "en1" "ssid" "password"

Has something changed that I'm unaware of? Maybe I'm going about this the wrong way and making it harder on myself than it really should be? Any help would be greatly appreciated.

6 REPLIES 6

rtrouton
Release Candidate Programs Tester

On the MacBook Airs and Retina MacBook Pros, the WiFi port is en0 and not en1. I've got a script available that helps sort that out automatically:

#!/bin/sh

#
# Please see the accompanying README for
# an explanation of what this script is for.
#
# Hat tip to Charles Edge for describing this
# method in this entry on his blog:
# http://krypted.com/mac-os-x/pushing-wireless-networks-out/
#
# Enable the wireless method you need and
# add the correct variables as needed. The
# wireless network name should not contain spaces.

# Determines which OS the script is running on
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')

# On 10.7 and higher, the Wi-Fi interface needs to be identified.
# On 10.5 and 10.6, the Wi-Fi interface should be named as "AirPort"

wifiDevice=`/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: Wi-Fi/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-`

# Set the SSID variable to your wireless network name
# to set the network name you want to connect to.
# Note: Wireless network name cannot contain spaces.
SSID=

# Set the INDEX variable to the index number you’d like
# it to be assigned to (leave it as "0" if you do not know
# what index number to use.)
INDEX=0

# Set the SECURITY variable to the security type of the
# wireless network (NONE, WEP, WPA, WPA2, WPAE or
# WPA2E) Setting it to NONE means that it's an open
# network with no encryption.
SECURITY=

# If you've set the SECURITY variable to something other than NONE,
# set the password here. For example, if you are using WPA
# encryption with a password of "thedrisin", set the PASSWORD
# variable to "thedrisin" (no quotes.)
PASSWORD=

# Once the running OS is determined, the settings for the specified
# wireless network are created and set as the first preferred network listed

if [[ ${osvers} -ge 7 ]]; then
    networksetup -addpreferredwirelessnetworkatindex $wifiDevice $SSID $INDEX $SECURITY $PASSWORD
else
    networksetup -addpreferredwirelessnetworkatindex AirPort $SSID $INDEX $SECURITY $PASSWORD
fi

It's also available here on my Github repo:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/setting_preferred_wireless...

bentoms
Release Candidate Programs Tester

Why not use a config profile?

daz_wallace
Contributor III

As Ben says, I find it easier to generate a config profile (using iPhone Configuration Utility, Apple Configurator or Casper and manually download it), package this up into an installer that dumps it into /tmp/ and use a script, such as the below, to install it.

Works fine when I've had to use it

#!/bin/sh
profiles -I -F /tmp/[profile name]
sleep 2
rm /tmp/[profile name]
exit 0

fabian_ulmrich
Contributor

I definetly would recommend a config profile which is installed during imaging process. That's what I use here and it works like a charm.

mike_pinto
New Contributor III

Thanks for the help. I've tried as recommended using a config profile, but it's been inconsistent. It will connect after the first boot, but sometimes won't after a restart. It will also disconnect and will not reattach after going to sleep. This whole thing has been beyond frustrating. Trying it using just the post install will not work at all (rtrouton's posted script).

Thanks again.

pcamdm1
New Contributor II

@ Mike did you ever get anything done with this? I use Tim Sutton's make-profile-pkg (https://github.com/timsutton/make-profile-pkg) and install the wifi profile at reboot. It's the only way I could get it to work so students could log in using LDAP credentials from first boot on a non-booted image.