Skip to content

Instantly share code, notes, and snippets.

@cjlawson02
Created September 23, 2021 16:38
Show Gist options
  • Save cjlawson02/dfc1e9ab78a5bb278c1d16e5e9c6e532 to your computer and use it in GitHub Desktop.
Save cjlawson02/dfc1e9ab78a5bb278c1d16e5e9c6e532 to your computer and use it in GitHub Desktop.
macOS Cal Poly Eduroam removal
#!/bin/bash
# Script created by Vince Hunter
# Script updated by Chris Lawson 9/23/21
### This allows the administrator password to be called, and used in the script where sudo is required
### Beware: the inputted password is used in echo commands
### Usage: Use `sudo` without a path to ensure the `sudo` function is called rather than the actual command
# Dialog Title
dialogTitle="Cal Poly WiFi Removal Tool"
# obtain the password from a dialog box
authPass=$(/usr/bin/osascript <<EOT
tell application "System Events"
activate
repeat
display dialog "Removing WiFi settings requires administrator privileges. Please enter your administrator account password below to continue:" ¬
default answer "" ¬
with title "$dialogTitle" ¬
with hidden answer ¬
buttons {"Quit", "Continue"} default button 2
if button returned of the result is "Quit" then
return 1
exit repeat
else if the button returned of the result is "Continue" then
set pswd to text returned of the result
set usr to short user name of (system info)
try
do shell script "echo test" user name usr password pswd with administrator privileges
return pswd
exit repeat
end try
end if
end repeat
end tell
EOT
)
# Abort if the Quit button was pressed
if [ "$authPass" == 1 ]; then
/bin/echo "User aborted. Exiting..."
exit 0
fi
# obtain the Cal Poly Username from a dialog box
CalPolyUsername=$(/usr/bin/osascript <<EOT
tell application "System Events"
activate
repeat
display dialog "Please enter your Cal Poly username without the @calpoly.edu below to continue:" ¬
default answer "" ¬
with title "$dialogTitle" ¬
with hidden answer ¬
buttons {"Quit", "Continue"} default button 2
if button returned of the result is "Quit" then
return 1
exit repeat
else if the button returned of the result is "Continue" then
set caluser to text returned of the result
return caluser
end if
end repeat
end tell
EOT
)
# Abort if the Quit button was pressed
if [ "$CalPolyUsername" == 1 ]; then
/bin/echo "User aborted. Exiting..."
exit 0
fi
# function that replaces sudo command
sudo () {
/bin/echo $authPass | /usr/bin/sudo -S "$@"
}
###==========================
### Shell script follows here
###==========================
echo Their username is: $CalPolyUsername
# Forgets old and current Cal Poly WiFi Networks
sudo networksetup -removepreferredwirelessnetwork en0 SecureMustangWireless
sudo networksetup -removepreferredwirelessnetwork en0 WiFiSetup
sudo networksetup -removepreferredwirelessnetwork en0 eduroam
sudo networksetup -removepreferredwirelessnetwork en0 CalPolyGuest
# Removes 802.1X Keychain entries
security delete-generic-password -a $CalPolyUsername -D "802.1X Password"
security set-identity-preference -n -s "com.apple.network.eap.user.identity.wlan.ssid.SecureMustangWireless"
security delete-generic-password -a "[email protected]" -D "802.1X Password"
security set-identity-preference -n -s "com.apple.network.eap.user.item.wlan.ssid.eduroam"
security delete-generic-password -l "eduroam" # Added 9/23/21
# Removes On Boarding Keychain entries
security set-identity-preference -n -s "com.apple.network.eap.user.identity.wlan.ssid.SecureMustangWireless"
security delete-certificate -c "AddTrust External CA Root"
security delete-certificate -c "backupclearpass.netadm.calpoly.edu"
security delete-certificate -c "backupclrpass2.netadm.calpoly.edu"
security delete-certificate -c "backupclrpass3.netadm.calpoly.edu"
security delete-certificate -c "calpolyclearpass.netadm.calpoly.edu"
security delete-certificate -c "campusclearpass.netadm.calpoly.edu"
security delete-certificate -c "ClearPass Onboard Local Certificate Authority"
security delete-certificate -c "Device for $CalPolyUsername"
security delete-certificate -c "$CalPolyUsername"
security delete-certificate -c "InCommon RSA Server CA"
security delete-certificate -c "resnetclearpass.netadm.calpoly.edu"
security delete-certificate -c "thawte Primary Root CA"
security delete-certificate -c "Thawte SSL CA"
security delete-certificate -c "thawte SSL CA - G2"
security delete-certificate -c "USERTrust RSA Certification Authority"
security delete-certificate -c "clearpass.its.calpoly.edu" # Added 9/22/21
security delete-certificate -c "calpolyclearpass.netadm.calpoly.edu" # Added 9/22/21
# Turns Wi-Fi off and back on
networksetup -setairportpower en0 off
sleep 2
networksetup -setairportpower en0 on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment