We have a script that we are trying to allow a user to run without having the need to input admin credentials. Basically the script checks for a valid IP on Ethernet and if it finds it, it shuts off WiFi and exits. If it doesn't see a valid IP on Ethernet it checks WiFi and looks for a valid IP. If it finds it, it exits. If it doesn't it shuts the airport off, removes all the networks, turns airport back on, installs a configuration profile and reconnects up to our network.
The script works perfectly but as soon as we deploy it to a test box as either a .command or as a .app it prompts for admin credentials to turn the WiFi off, then again to turn it back on and again to install the profile. After researching it we are at a loss as to how to allow the contents of the script to run without interruption.
Our end goal is to have an app or an alias to a .command file that resets the wireless setting on site by the current user who is not an admin on the machine. Any help, ideas or guidance would be very much appreciated.
Here is a copy of the script. We using modified version of tkimpton's awesome script at https://jamfnation.jamfsoftware.com/discussion.html?id=5327
#!/bin/bash
#
####################################################################################
#
# Set the variables
#
####################################################################################
# Get the ethernet hardware port (ehwport) and ip address (eipadd)
ehwport=networksetup -listallhardwareports | awk '/.Ethernet/,/Ethernet Address/' | awk 'NR==2' | cut -d " " -f 2
# Get the ethernet ip address (eipadd)
eipadd=ipconfig getifaddr $ehwport
# get the first six of the addy
eipsubnet=$( echo "$eipadd" | cut -d. -f1,2 )
echo "The ethernet hardware port is $ehwport at address $eipadd"
# Get the wireless network service (wservice)
wservice=/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)'
echo "The wireless network service is $wservice"
# Get the wireless hardware port (whwport) and ip address (wipadd)
whwport=networksetup -listallhardwareports | awk "/$wservice/,/Ethernet Address/" | awk 'NR==2' | cut -d " " -f 2
# Get the wireless ip address (wipadd)
wipadd=ipconfig getifaddr $whwport
# get the first six of the addy
wipsubnet=$( echo "$wipadd" | cut -d. -f1,2 )
echo "The wireless hardware port is $whwport at address $wipadd"
# Get the wireless network (wirelessnw)
wirelessnw=networksetup -getairportnetwork $whwport | cut -d " " -f 4
echo "Wireless network is $wirelessnw"
# Carry out an OS version check
OS=/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'
echo "The OS is version $OS"
# Check to see if the JSS is available and if yes, then submits the current IP
checkjss=/usr/sbin/jamf checkJSSConnection -retry 0 | grep "The JSS is available"
echo JSS is Available
####################################################################################
# Test the ethernet connection, reset wi-fi and reconnect to SPS_Secure if necessary
if [[ "$eipsubnet" == "123.456" ]]; then
networksetup -setairportpower $whwport off
echo "Ethernet is active at IP : "$eipadd""
exit 0
else
# Turn off wifi
networksetup -setairportpower $whwport off
# Remove All Wireless networks
/usr/sbin/networksetup -removeallpreferredwirelessnetworks $whwport
# Do not ask to join new networks
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs joinmode=automatic joinmodefallback=donothing
echo "Set the wireless service to not ask to join other wireless networks"
# Turn on wifi
networksetup -setairportpower $whwport on
fi
####################################################################################
#
# Determine the OS version and either import the config profile (10.7 and up) or import the network settings (10.6)
#
####################################################################################
# If 10.6 Import the network settings This step requires the config profile to be staged first
if [ $OS = 10.6 ]; then
networksetup -import8021xProfiles AirPort /private/var/tmp/thawte.networkconnect
exit 0
else
# If 10.7 or newer Import the wireless configuration profile. This step requires the config profile to be staged first
profiles -I -F /private/var/tmp/8021xprofile.mobileconfig
exit 0
fi
####################################################################################
# Check to see it the jss is ping-able and if so submit the ip change to the jss.
# This is useful when using Casper Remote and users are switching between wired and wireless
#####################################################################################
if [ "$checkjss" == "The JSS is available." ]; then
echo JSS is Available
fi
exit 0