├── LICENSE ├── README.md ├── bindMachineToActiveDirectory ├── LICENSE ├── README.md └── bindMachineToActiveDirectory.sh ├── flushDNS ├── LICENSE ├── README.md └── flushDNS.sh ├── installPrinterFromWindowsPrintServer ├── LICENSE ├── README.md └── installPrinterFromWindowsPrintServer.sh ├── migrateLocalUserToADDomainUser ├── LICENSE ├── README.md └── migrateLocalUserToADDomainUser.sh ├── reconUsername ├── LICENSE ├── README.md └── reconUsername.sh ├── setWirelessPreferences ├── LICENSE ├── README.md └── setWirelessPreferences.sh └── triggerPolicyWhenProcessNotRunning ├── LICENSE ├── README.md └── triggerPolicyWhenProcessNotRunning.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mac Scripts 2 | 3 | A collection of scripts used to Manage Mac OS X computers. I work in a Jamf Pro shop, so some scripts will lean on Jamf to do some of the heavy lifting. 4 | -------------------------------------------------------------------------------- /bindMachineToActiveDirectory/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bindMachineToActiveDirectory/README.md: -------------------------------------------------------------------------------- 1 | # bindMachineToActiveDirectory.sh 2 | 3 | Bind the machine to an Active Directory Domain using the first 5 or 6 characters of the Computer Name to determine what OU to use and adding administrative groups where necessary. 4 | -------------------------------------------------------------------------------- /bindMachineToActiveDirectory/bindMachineToActiveDirectory.sh: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Author: Scott Blake 3 | # Modified: 2017-01-25 4 | # 5 | # SBind the machine to an Active Directory Domain using the first 5 or 6 6 | # characters of the Computer Name to determine what OU to use and adding 7 | # administrative groups where necessary. 8 | # 9 | ################################################################################ 10 | # Changelog 11 | # 12 | # Version 1.0 - Scott Blake 13 | # Initial script 14 | # Version 1.1 - Scott Blake 15 | # Update styling to match other scripts in the repository 16 | # 17 | ################################################################################ 18 | # Variables 19 | # 20 | 21 | # Active Directory domain 22 | domain="domainname.pretendco.com" 23 | 24 | # Username/Password used to perform binding 25 | username="" 26 | password="" 27 | 28 | # Default OU to put machines when there is no matching prefix 29 | ou="OU=Computers" 30 | 31 | # Define groups array - groups will be given admin privileges 32 | groups=("Central-IT-Technicians") 33 | 34 | ################################################################################ 35 | # Additional Variables - Do Not Edit 36 | # 37 | 38 | olddomain=$( dsconfigad -show | awk '/Active Directory Domain/{print $NF}' ) 39 | computername=$( scutil --get ComputerName ) 40 | adcomputerid=$( echo "${computername}" | tr [:lower:] [:upper:] ) 41 | prefix="${adcomputerid:0:6}" 42 | 43 | ################################################################################ 44 | # Code 45 | # 46 | 47 | echo "Using computer name '${adcomputerid}'..." 48 | echo "" 49 | 50 | ## Unbind if already bound 51 | 52 | # If the domain is correct 53 | if [[ "${olddomain}" == "${domain}" ]]; then 54 | # Check the id of a user 55 | id -u "${username}" > /dev/null 2>&1 56 | 57 | # If the check was successful... 58 | if [[ $? == 0 ]]; then 59 | echo -n "This machine is bound to AD. Unbinding..." 60 | 61 | # Unbind from AD 62 | dsconfigad -remove -force -u "${username}" -p "${password}" 63 | 64 | # Re-check the id of a user 65 | id -u "${username}" > /dev/null 2>&1 66 | 67 | # If the check was successful... 68 | if [[ $? == 0 ]]; then 69 | echo "Failed (Error code: 1)" 70 | exit 1 71 | else 72 | echo "Success" 73 | echo "" 74 | fi 75 | fi 76 | fi 77 | 78 | 79 | ## Convert ComputerID prefix to OU #### 80 | 81 | echo "Checking for '${prefix}' prefix..." 82 | 83 | case "${prefix}" in 84 | # First 6 chars match ABCDEF, ABCDEG, or ABCDEH 85 | # Also add AlphaBetaCharlie-Technicians security group as admins 86 | "ABCDEF"|"ABCDEG"|"ABCDEH") 87 | ou="OU=Computers,OU=DeltaEcho,OU=AlphaBetaCharlie" 88 | groups+=("AlphaBetaCharlie-Technicians") 89 | ;; 90 | # First 6 characters match XYZ123 91 | # This OU doesn't have secondary on-site support, so don't add a group 92 | "XYZ123") 93 | ou="OU=Computers,OU=XrayYankeeZulu" 94 | ;; 95 | "XYZLAB") 96 | ou="OU=Lab,OU=Computers,OU=XrayYankeeZulu" 97 | ;; 98 | *) 99 | # Nothing found, try the prefixes with 5 characters 100 | prefix="${prefix:0:5}" 101 | echo "Checking for '${prefix}' prefix..." 102 | 103 | case "${prefix}" in 104 | "ABCYZ") 105 | ou="OU=Computers,OU=AlphaBetaCharlie" 106 | groups+=("AlphaBetaCharlie-Technicians") 107 | ;; 108 | esac 109 | esac 110 | 111 | # Append domain to $ou and replace all '.' with ',DC=' 112 | ou="${ou},DC=${domain//./,DC=}" 113 | 114 | # Display OU string 115 | echo "Using '${ou}' OU..." 116 | echo "" 117 | 118 | # Display all groups 119 | echo "Adding administrative privileges to..." 120 | for group in "${groups[@]}"; do 121 | echo $group; 122 | done 123 | echo "" 124 | 125 | # Combine array into comma separated list 126 | groupList=$( printf ",%s" "${groups[@]}" ) 127 | groupList="${groupList:1}" 128 | 129 | 130 | ## Perform bind 131 | 132 | dsconfigad -add "${domain}" -username "${username}" -password "${password}" \ 133 | -computer "${adcomputerid}" -useuncpath enable -mobile enable \ 134 | -mobileconfirm disable -shell /bin/bash -ou "${ou}" -force \ 135 | -groups "${groupList}" 136 | -------------------------------------------------------------------------------- /flushDNS/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /flushDNS/README.md: -------------------------------------------------------------------------------- 1 | # flushDNS.sh 2 | 3 | Script to flush the DNS cache in macOS. The script checks the version of macOS and then issues the appropriate command to flush the DNS cache. 4 | -------------------------------------------------------------------------------- /flushDNS/flushDNS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2017-01-23 5 | # 6 | # Script to flush the DNS caches in macOS. The script checks the version of 7 | # macOS and then issues the appropriate command to flush the DNS cache. 8 | # 9 | ################################################################################ 10 | # Changelog 11 | # 12 | # Version 1.0 - Scott Blake 13 | # Initial script 14 | # 15 | ################################################################################ 16 | # Variables 17 | # 18 | 19 | prod_ver=$(/usr/bin/sw_vers -productVersion) 20 | os_major=$(cat ${prod_ver} | awk -F . '{print $1}') 21 | os_minor=$(cat ${prod_ver} | awk -F . '{print $2}') 22 | os_patch=$(cat ${prod_ver} | awk -F . '{print $3}') 23 | 24 | ################################################################################ 25 | # Code 26 | # 27 | 28 | # Not macOS 10.x 29 | if [ "${os_major}" -ne "10" ]; then 30 | echo "ERROR: OS not supported" 31 | exit 1 32 | fi 33 | 34 | # El Capitan and Sierra 35 | if [ "${os_minor}" -ge "11" ]; then 36 | killall -HUP mDNSResponder 37 | 38 | # Yosemite 39 | elif [ "${os_minor}" -eq "10" ]; then 40 | # 10.10.0 - 10.10.3 41 | if [ "${os_patch}" -ge "0" ] && [ "${os_patch}" -le "3" ]; then 42 | discoveryutil mdnsflushcache 43 | # 10.10.4+ 44 | elif [ "${os_patch}" -ge "4" ]; then 45 | killall -HUP mDNSResponder 46 | fi 47 | 48 | # Lion, Mountain Lion, and Mavericks 49 | elif [ "${os_minor}" -ge "7" ] && [ "${os_minor}" -le "9" ]; then 50 | killall -HUP mDNSResponder 51 | 52 | # Tiger, Leopard, and Snow Leopard 53 | elif [ "${os_minor}" -ge "4" ] && [ "${os_minor}" -le "6" ]; then 54 | dscacheutil -flushcache 55 | fi 56 | -------------------------------------------------------------------------------- /installPrinterFromWindowsPrintServer/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /installPrinterFromWindowsPrintServer/README.md: -------------------------------------------------------------------------------- 1 | # installPrinterFromWindowsPrintServer.sh 2 | 3 | This script takes arguments 4-11 to install a printer from a designated print 4 | server. If anything is passed to $6 (Driver Policy Trigger), it will be used 5 | as a custom trigger for a Jamf policy designated to install the driver. Using 6 | normal Jamf scoping mechanisms, you can avoid this policy being re-run when it 7 | is not necessary. 8 | 9 | Also, make sure to set printserver_protocol, printserver_name, and 10 | printserver_fqdn (lines 41-43) to correspond to your print server. Jamf 11 | doesn't give enough parameters, so if you have more than 1 print server, 12 | duplicate this script for each server. 13 | 14 | | Arg | Parameter Label | Example Policy Values | 15 | |-----|-----------------------|-----------------------------------------------------------------| 16 | | $4 | Printer Name | ITS-Printer1 | 17 | | $5 | Printer Location | 5127 OWP | 18 | | $6 | Driver Policy Trigger | printDrivers-Bizhub_C224_C284_C364_C454_C554 | 19 | | $7 | Driver PPD Path | /Library/Printers/PPDs/Contents/Resources/KONICAMINOLTAC224e.gz | 20 | | $8 | Option 1 | PaperSources=PC204 | 21 | | $9 | Option 2 | Finisher=FS519 | 22 | | $10 | Option 3 | SelectColor=Grayscale | 23 | | $11 | Option 4 | ColorModel=Gray | 24 | -------------------------------------------------------------------------------- /installPrinterFromWindowsPrintServer/installPrinterFromWindowsPrintServer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2017-01-18 5 | # 6 | # This script takes arguments 4-11 to install a printer from a designated print 7 | # server. If anything is passed to $6 (Driver Policy Trigger), it will be used 8 | # as a custom trigger for a Jamf policy designated to install the driver. Using 9 | # normal Jamf scoping mechanisms, you can avoid this policy being re-run when it 10 | # is not necessary. 11 | # 12 | # Also, make sure to set printserver_protocol, printserver_name, and 13 | # printserver_fqdn (lines 41-43) to correspond to your print server. Jamf 14 | # doesn't give enough parameters, so if you have more than 1 print server, 15 | # duplicate this script for each server. 16 | # 17 | # +-----+-----------------------+-----------------------------------------------------------------+ 18 | # | Arg | Parameter Label | Example Policy Values | 19 | # +-----+-----------------------+-----------------------------------------------------------------+ 20 | # | $4 | Printer Name | ITS-Printer1 | 21 | # | $5 | Printer Location | 5127 OWP | 22 | # | $6 | Driver Policy Trigger | printDrivers-Bizhub_C224_C284_C364_C454_C554 | 23 | # | $7 | Driver PPD Path | /Library/Printers/PPDs/Contents/Resources/KONICAMINOLTAC224e.gz | 24 | # | $8 | Option 1 | PaperSources=PC204 | 25 | # | $9 | Option 2 | Finisher=FS519 | 26 | # | $10 | Option 3 | SelectColor=Grayscale | 27 | # | $11 | Option 4 | ColorModel=Gray | 28 | # +-----+-----------------------+-----------------------------------------------------------------+ 29 | # 30 | ################################################################################ 31 | # Changelog 32 | # 33 | # Version 1.0 - Scott Blake 34 | # Initial script 35 | # 36 | ################################################################################ 37 | # 38 | # VARIABLES 39 | # 40 | 41 | printserver_protocol="smb" 42 | printserver_name="PRINTSERVERNAME" 43 | printserver_fqdn="printServerName.domain.com" 44 | 45 | ################################################################################ 46 | # 47 | # ADDITIONAL VARIABLES - Do Not Edit 48 | # 49 | 50 | printername="${printserver_name}_${printer_shortname}" 51 | gui_display_name="${printer_shortname} on ${printserver_name}" 52 | address="${printserver_protocol}://${printserver_fqdn}/${printer_shortname}" 53 | 54 | # Check to see if a value was passed in parameter 4. If so, assign to "printer_shortname". 55 | if [ "$4" != "" ]; then 56 | printer_shortname=$4 57 | fi 58 | 59 | # Check to see if a value was passed in parameter 5. If so, assign to "printer_location". 60 | if [ "$5" != "" ]; then 61 | printer_location=$5 62 | fi 63 | 64 | # Check to see if a value was passed in parameter 6. If so, assign to "driver_policy_trigger". 65 | if [ "$6" != "" ]; then 66 | driver_policy_trigger=$6 67 | fi 68 | 69 | # Check to see if a value was passed in parameter 7. If so, assign to "driver_ppd". 70 | if [ "$7" != "" ]; then 71 | driver_ppd=$7 72 | fi 73 | 74 | # Check to see if a value was passed in parameter 8. If so, assign to "option_1". 75 | if [ "$8" != "" ]; then 76 | option_1=$8 77 | fi 78 | 79 | # Check to see if a value was passed in parameter 9. If so, assign to "option_2". 80 | if [ "$9" != "" ]; then 81 | option_2=$9 82 | fi 83 | 84 | # Check to see if a value was passed in parameter 10. If so, assign to "option_3". 85 | if [ "${10}" != "" ]; then 86 | option_3=${10} 87 | fi 88 | 89 | # Check to see if a value was passed in parameter 11. If so, assign to "option_4". 90 | if [ "${11}" != "" ]; then 91 | option_4=${11} 92 | fi 93 | 94 | ################################################################################ 95 | # 96 | # Code 97 | # 98 | 99 | function CheckBinary() { 100 | # Identify location of jamf binary. 101 | jamf_binary=$(/usr/bin/which jamf) 102 | 103 | if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then 104 | jamf_binary="/usr/sbin/jamf" 105 | elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 106 | jamf_binary="/usr/local/bin/jamf" 107 | elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 108 | jamf_binary="/usr/local/bin/jamf" 109 | fi 110 | } 111 | 112 | function DriverInstall() { 113 | # Trigger JAMF policy to (re)install drivers 114 | if [ ! -z "${driver_policy_trigger}" ]; then 115 | $jamf_binary policy -event "${driver_policy_trigger}" 116 | fi 117 | 118 | # If driver PPD does not exist, fail and exit 119 | if [ ! -e "${driver_ppd}" ]; then 120 | echo "Driver PPD not found at ${driver_ppd}." 121 | exit 1 122 | fi 123 | } 124 | 125 | function PrinterDelete() { 126 | # If printer already exists, remove it first 127 | /usr/bin/lpstat -p "${printername}" > /dev/null 2>1 128 | if [[ $? -eq 0 ]]; then 129 | echo "Existing printer found. Removing..." 130 | /usr/sbin/lpadmin -x "${printername}" 131 | fi 132 | } 133 | 134 | function PrinterInstall() { 135 | # Now we can install the printer. 136 | /usr/sbin/lpadmin \ 137 | -p "${printername}" \ 138 | -L "${printer_location}" \ 139 | -D "${gui_display_name}" \ 140 | -v "${address}" \ 141 | -P "${driver_ppd}" \ 142 | -o "${option_1}" \ 143 | -o "${option_2}" \ 144 | -o "${option_3}" \ 145 | -o "${option_4}" \ 146 | -o printer-error-policy=retry-current-job \ 147 | -o auth-info-required=negotiate \ 148 | -o printer-is-shared=false \ 149 | -E 150 | 151 | result=$? 152 | if [ "${result}" -eq 0 ]; then 153 | echo "${printername} installed successfully." 154 | else 155 | exit "${result}" 156 | fi 157 | } 158 | 159 | function PrinterEnable() { 160 | # Enable and start the printer on the system (so it's not paused). 161 | echo "Making sure ${printername} is enabled..." 162 | /usr/sbin/cupsenable "${printername}" 163 | } 164 | 165 | function main() { 166 | CheckBinary 167 | DriverInstall 168 | PrinterDelete 169 | PrinterInstall 170 | PrinterEnable 171 | } 172 | 173 | main 174 | -------------------------------------------------------------------------------- /migrateLocalUserToADDomainUser/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /migrateLocalUserToADDomainUser/README.md: -------------------------------------------------------------------------------- 1 | # migrateLocalUserToADDomainUser.sh 2 | 3 | This script utilizes CocoaDialog.app to convert local Mac OS X user accounts to mobile accounts. 4 | 5 | Based on previous work from [Rich Trouton](https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/migrate_local_user_to_AD_domain) and [Patrick Gallagher](http://macadmincorner.com/migrate-local-user-to-domain-account/) 6 | -------------------------------------------------------------------------------- /migrateLocalUserToADDomainUser/migrateLocalUserToADDomainUser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2014-12-20 5 | # 6 | # This script utilizes CocoaDialog.app to convert local Mac OS X user accounts 7 | # to mobile accounts. 8 | # 9 | # Based on previous work from: 10 | # Rich Trouton: https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/migrate_local_user_to_AD_domain 11 | # Patrick Gallagher: http://macadmincorner.com/migrate-local-user-to-domain-account/ 12 | # 13 | ################################################################################ 14 | # Changelog 15 | # 16 | # Version 1.0 - Patrick Gallagher 17 | # Initial script 18 | # 19 | # Version 1.2 - Rich Trouton 20 | # Added the ability to check if the OS is running on Mac OS X 10.7, and run 21 | # "killall opendirectoryd" instead of "killall DirectoryService" if it is. 22 | # 23 | # Version 1.3 - Rich Trouton 24 | # Added the ability to check if the OS is running on Mac OS X 10.7 or higher 25 | # (including 10.8) and run "killall opendirectoryd" instead of "killall 26 | # DirectoryService" if it is. 27 | # 28 | # Version 1.4 - Rich Trouton 29 | # Changed the admin rights function from using dscl append to using 30 | # dseditgroup. 31 | # 32 | # Version 1.5 - Rich Trouton 33 | # Fixed the admin rights functionality so that it actually now grants admin 34 | # rights. 35 | # 36 | # Version 2.0 - Scott Blake 37 | # Convert user prompts to use cocoaDialog and reorder the logic a bit. 38 | # 39 | # Version 2.1 - Scott Blake 40 | # Properly escape $CD variable. 41 | # 42 | ################################################################################ 43 | # Variables 44 | # 45 | 46 | # Set the path to the cocoaDialog application. 47 | # Will be used to display prompts. 48 | CD="/path/to/CocoaDialog.app/Contents/MacOS/CocoaDialog" 49 | 50 | # Set an Active Directory username that is not likely to be removed. 51 | # Will be used to check AD connectivity 52 | lookupAccount="EXISTING_AD_USERNAME" 53 | 54 | ################################################################################ 55 | # Other Variables (Should not need to modify) 56 | # 57 | 58 | Version=2.1 59 | listUsers=( $(/usr/bin/dscl . list /Users UniqueID | awk '$2 >= 500 && $2 < 1024 { print $1; }') ) 60 | FullScriptName=$(basename "${0}") 61 | check4AD=$(/usr/bin/dscl localhost -list . | grep "Active Directory") 62 | osvers=$(/usr/bin/sw_vers -productVersion | awk -F. '{print $2}') 63 | 64 | ################################################################################ 65 | # Functions 66 | # 67 | 68 | # Generic failure with reason function 69 | die() { 70 | rv=$("${CD}" ok-msgbox --title "Error" \ 71 | --text "Error" \ 72 | --informative-text "${1}" \ 73 | --no-cancel \ 74 | --float \ 75 | --icon stop) 76 | 77 | if [[ "${rv}" == "1" ]]; then 78 | echo "Error: ${1}" 79 | exit 1 80 | fi 81 | } 82 | 83 | # Function to ensure admin privileges 84 | RunAsRoot() { 85 | ## Pass in the full path to the executable as $1 86 | if [[ "$(/usr/bin/id -u)" != "0" ]] ; then 87 | echo "This application must be run with administrative privileges." 88 | osascript -e "do shell script \"${1}\" with administrator privileges" 89 | exit 0 90 | fi 91 | } 92 | 93 | ################################################################################ 94 | 95 | # Clear previous commands from Terminal 96 | clear 97 | 98 | # Display version information 99 | echo "********* Running ${FullScriptName} Version ${Version} *********" 100 | 101 | # Execute runAsRoot function to ensure administrative privileges 102 | RunAsRoot "${0}" 103 | 104 | # Check for cocoaDialog dependency and exit if not found 105 | if [[ ! -f "${CD}" ]]; then 106 | echo "Required dependency not found: ${CD}" 107 | exit 1 108 | fi 109 | 110 | # If the machine is not bound to AD, then there's no purpose going any further. 111 | if [[ "${check4AD}" != "Active Directory" ]]; then 112 | die "This machine is not bound to Active Directory. Please bind to AD first." 113 | fi 114 | 115 | # Lookup a domain account and check exit code for error 116 | /usr/bin/id -u "${lookupAccount}" 117 | if [[ $? -ne 0 ]]; then 118 | die "It doesn't look like this Mac is communicating with AD correctly. Exiting the script." 119 | fi 120 | 121 | # Loop until 'Finished' button is selected 122 | until [[ "${acctReturn[0]}" == "2" ]]; do 123 | 124 | # Generate User Account Selection dialog to get 'old username' 125 | acctReturn=( $("${CD}" dropdown --title "User Account Selection" \ 126 | --text "Please choose a local user to migrate." \ 127 | --float \ 128 | --items ${listUsers[@]} \ 129 | --button1 "Continue" \ 130 | --button2 "Finish" \ 131 | --icon user) ) 132 | 133 | if [[ "${acctReturn[0]}" == "1" ]]; then 134 | user="${listUsers[${acctReturn[1]}]}" 135 | echo "Selected '${user}' to migrate." 136 | elif [[ "${acctReturn[0]}" == "2" ]]; then 137 | echo "Exiting from 'User Account Selection' dialog." 138 | exit 0 139 | fi 140 | 141 | if [[ ! -n "${user}" ]]; then 142 | die "'${user}' not found." 143 | elif [[ $(/usr/bin/who | /usr/bin/awk '/console/ {print $1}') == "${user}" ]]; then 144 | die "This user is logged in. Please log this user out and log in as another admin." 145 | fi 146 | 147 | # Get AD username 148 | rv=( $("${CD}" standard-inputbox --title "Enter Active Directory Username" \ 149 | --informative-text "Please provide ${user}'s Active Directory username." \ 150 | --text "${user}" \ 151 | --float \ 152 | --icon find) ) 153 | 154 | if [[ "${rv[0]}" == "1" ]]; then 155 | netname="${rv[@]:1}" 156 | echo "Entered '${netname}' as new Active Directory username." 157 | elif [[ "${rv[0]}" == "2" ]]; then 158 | echo "Exiting from 'Enter Active Directory Username' dialog." 159 | exit 0 160 | fi 161 | 162 | # Validate AD username against spaces 163 | if [[ "${netname}" != "${netname%[[:space:]]*}" ]]; then 164 | die "The Active Directory username cannot contain spaces." 165 | fi 166 | 167 | # Determine location of the users home folder 168 | userHome="$(/usr/bin/dscl . read /Users/"${user}" NFSHomeDirectory | /usr/bin/cut -c 19-)" 169 | 170 | # Get list of groups 171 | echo "Checking group memberships for local user ${user}" 172 | lgroups="$(/usr/bin/id -Gn ${user})" 173 | 174 | if [[ $? -eq 0 ]] && [[ -n "$(/usr/bin/dscl . -search /Groups GroupMembership "${user}")" ]]; then 175 | # Delete user from each group it is a member of 176 | for lg in "${lgroups}"; do 177 | /usr/bin/dscl . -delete /Groups/"${lg}" GroupMembership "${user}" >&/dev/null 178 | done 179 | fi 180 | 181 | # Delete the primary group 182 | if [[ -n "$(/usr/bin/dscl . -search /Groups name "${user}")" ]]; then 183 | /usr/sbin/dseditgroup -o delete "${user}" 184 | fi 185 | 186 | # Get the users guid and set it as a var 187 | guid="$(/usr/bin/dscl . -read /Users/"${user}" GeneratedUID | /usr/bin/awk '{print $NF;}')" 188 | if [[ -f /private/var/db/shadow/hash/"${guid}" ]]; then 189 | /bin/rm -f /private/var/db/shadow/hash/"${guid}" 190 | fi 191 | 192 | # Delete the user 193 | /bin/mv "${userHome}" /Users/old_"${user}" 194 | /usr/bin/dscl . -delete /Users/"${user}" 195 | 196 | # Refresh Directory Services 197 | if [[ "${osvers}" -ge 7 ]]; then 198 | /usr/bin/killall opendirectoryd 199 | else 200 | /usr/bin/killall DirectoryService 201 | fi 202 | 203 | # Allow service to restart 204 | sleep 20 205 | /usr/bin/id "${netname}" 206 | 207 | # Check if there's a home folder there already, if there is, exit before we wipe it 208 | if [[ -f /Users/"${netname}" ]]; then 209 | die "Oops, theres a home folder there already for ${netname}. If you don't want that one, delete it in the Finder first, then run this script again." 210 | else 211 | /bin/mv /Users/old_"${user}" /Users/"${netname}" 212 | echo "Home directory for '${netname}' is now located at '/Users/${netname}'." 213 | 214 | /usr/sbin/chown -R "${netname}" /Users/"${netname}" 215 | echo "Permissions for '/Users/${netname}' are now set properly." 216 | 217 | /System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -n "${netname}" 218 | echo "Account for ${netname} has been created on this computer" 219 | fi 220 | 221 | # Prompt for admin rights 222 | rv=( $("${CD}" yesno-msgbox --title "Grant Administrative Privileges" \ 223 | --text "Do you want to grant ${netname} administrative privilieges?" \ 224 | --float \ 225 | --no-cancel \ 226 | --icon security) ) 227 | 228 | if [[ "${rv}" == "1" ]]; then 229 | /usr/sbin/dseditgroup -o edit -a "${netname}" -t user admin 230 | echo "Administrative privileges granted to ${netname}." 231 | elif [[ "${rv}" == "2" ]]; then 232 | echo "No administrative privileges granted to ${netname}." 233 | fi 234 | 235 | # Display success dialog 236 | rv=$("${CD}" ok-msgbox --title "Successful Migration" \ 237 | --text "Successfully migrated local user account (${user}) to Active Directory account (${netname})." \ 238 | --float \ 239 | --no-cancel \ 240 | --icon info) 241 | 242 | done 243 | -------------------------------------------------------------------------------- /reconUsername/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /reconUsername/README.md: -------------------------------------------------------------------------------- 1 | # reconUsername.sh 2 | 3 | Set this script to run at login to perform inventory with "User and Location" information. This script skips users with an ID less than 1000 (local users). 4 | -------------------------------------------------------------------------------- /reconUsername/reconUsername.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2016-11-11 5 | # 6 | # Set this script to run at login to perform inventory with "User and Location" 7 | # information. This script skips users with an ID less than 1000 (local users). 8 | # 9 | ################################################################################ 10 | # Changelog 11 | # 12 | # Version 1.0 - Scott Blake 13 | # Initial script 14 | # Version 1.1 - Scott Blake 15 | # Added username logic to skip local accounts 16 | # 17 | ################################################################################ 18 | # Variables 19 | # 20 | 21 | # Check to see if a value was passed in parameter 3 and if so, assign to "username" 22 | if [ "$3" != "" ]; then 23 | username=$3 24 | else 25 | echo "ERROR: No username provided" 26 | exit 1 27 | fi 28 | 29 | ################################################################################ 30 | # Code 31 | # 32 | 33 | CheckBinary() { 34 | # Identify location of jamf binary. 35 | jamf_binary=`/usr/bin/which jamf` 36 | 37 | if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then 38 | jamf_binary="/usr/sbin/jamf" 39 | elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 40 | jamf_binary="/usr/local/bin/jamf" 41 | elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 42 | jamf_binary="/usr/local/bin/jamf" 43 | fi 44 | } 45 | 46 | PerformRecon() { 47 | # If username is not local, perform recon. 48 | if [ $(/usr/bin/id -u "${username}") -ge 1000 ]; then 49 | echo "Login from user: ${username}" 50 | echo "Performing recon..." 51 | $jamf_binary recon -endUsername "${username}" 52 | else 53 | echo "Login from local user: ${username}" 54 | echo "Recon skipped." 55 | fi 56 | } 57 | 58 | main() { 59 | CheckBinary 60 | PerformRecon 61 | } 62 | 63 | main 64 | -------------------------------------------------------------------------------- /setWirelessPreferences/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setWirelessPreferences/README.md: -------------------------------------------------------------------------------- 1 | # setWirelessPreferences.sh 2 | 3 | This script sets wireless preferences according to input parameters. Boolean settings may be configured using 'YES' and 'NO'. Leave a parameter blank to ignore it. 4 | 5 | ## Available preferences from Airport command 6 | - DisconnectOnLogout (Boolean) 7 | - JoinMode (String) 8 | - Automatic 9 | - Preferred 10 | - Ranked 11 | - Recent 12 | - Strongest 13 | - JoinModeFallback (String) 14 | - Prompt 15 | - JoinOpen 16 | - KeepLooking 17 | - DoNothing 18 | - RememberRecentNetworks (Boolean) 19 | - RequireAdmin (Boolean) 20 | - RequireAdminIBSS (Boolean) 21 | - RequireAdminNetworkChange (Boolean) 22 | - RequireAdminPowerToggle (Boolean) 23 | - WoWEnabled (Boolean) 24 | 25 | ## Default Parameter Mapping 26 | | Arg | Parameter Label | Valid Values | 27 | |-----|---------------------------|-------------------------------------------------| 28 | | $4 | DisconnectOnLogout | YES, NO | 29 | | $5 | JoinMode | Automatic, Preferred, Ranked, Recent, Strongest | 30 | | $6 | JoinModeFallback | Prompt, JoinOpen, KeepLooking, DoNothing | 31 | | $7 | RememberRecentNetworks | YES, NO | 32 | | $8 | RequireAdmin | YES, NO | 33 | | $9 | RequireAdminIBSS | YES, NO | 34 | | $10 | RequireAdminNetworkChange | YES, NO | 35 | | $11 | RequireAdminPowerToggle | YES, NO | 36 | | ~~$12~~ | ~~WoWEnabled~~ | ~~YES, NO~~ | 37 | -------------------------------------------------------------------------------- /setWirelessPreferences/setWirelessPreferences.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2017-01-24 5 | # 6 | # This script sets wireless preferences according to input parameters. Boolean 7 | # settings may be configured using 'YES' and 'NO'. Leave a parameter blank to 8 | # ignore it. 9 | # 10 | # Available preferences from Airport command: 11 | # DisconnectOnLogout (Boolean) 12 | # JoinMode (String) 13 | # Automatic 14 | # Preferred 15 | # Ranked 16 | # Recent 17 | # Strongest 18 | # JoinModeFallback (String) 19 | # Prompt 20 | # JoinOpen 21 | # KeepLooking 22 | # DoNothing 23 | # RememberRecentNetworks (Boolean) 24 | # RequireAdmin (Boolean) 25 | # RequireAdminIBSS (Boolean) 26 | # RequireAdminNetworkChange (Boolean) 27 | # RequireAdminPowerToggle (Boolean) 28 | # WoWEnabled (Boolean) 29 | # 30 | # Default Parameter Mapping: 31 | # +-----+---------------------------|-------------------------------------------------+ 32 | # | Arg | Parameter Label | Valid Values | 33 | # +-----+---------------------------|-------------------------------------------------+ 34 | # | $4 | DisconnectOnLogout | YES, NO | 35 | # | $5 | JoinMode | Automatic, Preferred, Ranked, Recent, Strongest | 36 | # | $6 | JoinModeFallback | Prompt, JoinOpen, KeepLooking, DoNothing | 37 | # | $7 | RememberRecentNetworks | YES, NO | 38 | # | $8 | RequireAdmin | YES, NO | 39 | # | $9 | RequireAdminIBSS | YES, NO | 40 | # | $10 | RequireAdminNetworkChange | YES, NO | 41 | # | $11 | RequireAdminPowerToggle | YES, NO | 42 | # | ~~$12~~ | ~~WoWEnabled~~ | ~~YES, NO~~ | 43 | # +-----+---------------------------|-------------------------------------------------+ 44 | # 45 | ################################################################################ 46 | # Changelog 47 | # 48 | # Version 1.0 - Scott Blake 49 | # Initial script 50 | # 51 | ################################################################################ 52 | # Variables 53 | # 54 | 55 | # To only configure one network, enter a number here. This corresponds to the 56 | # line that is returned in the `service` command. For instance, if you have 57 | # "Wi-Fi" and "Wi-Fi 2", entering 1 will only return "Wi-Fi", entering 2 will 58 | # only return "Wi-Fi 2", and leaving it empty will return all services. 59 | nth='1' 60 | 61 | # Jamf doesn't give enough parameters, so `WOWEnabled` has been left out. If you 62 | # have a need to set this variable, you'll need to change the parameter mapping. 63 | # The rest of the code should continue to work. 64 | 65 | # Check to see if a value was passed in parameter 4. If so, assign to "DisconnectOnLogout". 66 | if [ "$4" != "" ]; then 67 | DisconnectOnLogout=$4 68 | fi 69 | 70 | # Check to see if a value was passed in parameter 5. If so, assign to "JoinMode". 71 | if [ "$5" != "" ]; then 72 | JoinMode=$5 73 | fi 74 | 75 | # Check to see if a value was passed in parameter 6. If so, assign to "JoinModeFallback". 76 | if [ "$6" != "" ]; then 77 | JoinModeFallback=$6 78 | fi 79 | 80 | # Check to see if a value was passed in parameter 7. If so, assign to "RememberRecentNetworks". 81 | if [ "$7" != "" ]; then 82 | RememberRecentNetworks=$7 83 | fi 84 | 85 | # Check to see if a value was passed in parameter 8. If so, assign to "RequireAdmin". 86 | if [ "$8" != "" ]; then 87 | RequireAdmin=$8 88 | fi 89 | 90 | # Check to see if a value was passed in parameter 9. If so, assign to "RequireAdminIBSS". 91 | if [ "$9" != "" ]; then 92 | RequireAdminIBSS=$9 93 | fi 94 | 95 | # Check to see if a value was passed in parameter 10. If so, assign to "RequireAdminNetworkChange". 96 | if [ "${10}" != "" ]; then 97 | RequireAdminNetworkChange=${10} 98 | fi 99 | 100 | # Check to see if a value was passed in parameter 11. If so, assign to "RequireAdminPowerToggle". 101 | if [ "${11}" != "" ]; then 102 | RequireAdminPowerToggle=${11} 103 | fi 104 | 105 | # Check to see if a value was passed in parameter 12. If so, assign to "WoWEnabled". 106 | if [ "${12}" != "" ]; then 107 | WoWEnabled=${12} 108 | fi 109 | 110 | ################################################################################ 111 | # Additional Variables - Do Not Edit 112 | # 113 | 114 | # Path to the airport binary 115 | airport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport' 116 | 117 | # List of services that match either wi-fi or airport (case insensitive) 118 | services=$(/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)' | sed -n "${nth}p") 119 | 120 | # List of interfaces on the system 121 | interfaces=$(/usr/sbin/networksetup -listallhardwareports) 122 | 123 | ################################################################################ 124 | # Code 125 | # 126 | 127 | function NormalizeBooleans() { 128 | DisconnectOnLogout=$(to_upper_boolean ${DisconnectOnLogout}) 129 | RememberRecentNetworks=$(to_upper_boolean ${RememberRecentNetworks}) 130 | RequireAdmin=$(to_upper_boolean ${RequireAdmin}) 131 | RequireAdminIBSS=$(to_upper_boolean ${RequireAdminIBSS}) 132 | RequireAdminNetworkChange=$(to_upper_boolean ${RequireAdminNetworkChange}) 133 | RequireAdminPowerToggle=$(to_upper_boolean ${RequireAdminPowerToggle}) 134 | WoWEnabled=$(to_upper_boolean ${WoWEnabled}) 135 | } 136 | 137 | function to_upper_boolean() { 138 | local str="$@" 139 | local output 140 | 141 | # Convert to uppercase 142 | output=$(tr '[:lower:]' '[:upper:]'<<<"${str}") 143 | 144 | # If value entered is shorthand, convert to full word 145 | case ${output} in 146 | 'Y') 147 | output="YES";; 148 | 'N') 149 | output="NO";; 150 | *) 151 | output="";; 152 | esac 153 | 154 | echo ${output} 155 | } 156 | 157 | function SetPreferences() { 158 | # Set preferences for each service found 159 | for service in "${services}"; do 160 | # Find the interface for the given service (en0, en1, etc.) 161 | local interface=$(echo "${interfaces}" | awk "/${service}/,/Ethernet Address/" | awk 'NR==2 {print $2}') 162 | 163 | # Make sure an interface was returned 164 | if [ -z "${interface}" ]; then 165 | echo "No interface found for ${service}" 166 | continue 167 | fi 168 | 169 | # Set the preference for each setting. The function ignores blank values, so 170 | # there is no need to modify this list if you aren't setting everything. 171 | SetPreference "${interface}" "DisconnectOnLogout" "${DisconnectOnLogout}" 172 | SetPreference "${interface}" "JoinMode" "${JoinMode}" 173 | SetPreference "${interface}" "JoinModeFallback" "${JoinModeFallback}" 174 | SetPreference "${interface}" "RememberRecentNetworks" "${RememberRecentNetworks}" 175 | SetPreference "${interface}" "RequireAdmin" "${RequireAdmin}" 176 | SetPreference "${interface}" "RequireAdminIBSS" "${RequireAdminIBSS}" 177 | SetPreference "${interface}" "RequireAdminNetworkChange" "${RequireAdminNetworkChange}" 178 | SetPreference "${interface}" "RequireAdminPowerToggle" "${RequireAdminPowerToggle}" 179 | SetPreference "${interface}" "WoWEnabled" "${WoWEnabled}" 180 | done 181 | } 182 | 183 | function SetPreference() { 184 | local interface=$1 185 | local key=$2 186 | local val=$3 187 | 188 | # If a value was passed, set the preference 189 | if [ ! -z "${val}" ]; then 190 | echo "Interface '${interface}', setting '${key}' to '${val}'" 191 | "${airport}" "${interface}" prefs "${key}"="${val}" 192 | fi 193 | } 194 | 195 | function main() { 196 | NormalizeBooleans 197 | SetPreferences 198 | } 199 | 200 | main 201 | -------------------------------------------------------------------------------- /triggerPolicyWhenProcessNotRunning/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Scott Blake 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /triggerPolicyWhenProcessNotRunning/README.md: -------------------------------------------------------------------------------- 1 | # triggerPolicyWhenProcessNotRunning.sh 2 | 3 | This script takes arguments in `$4` (Process) and `$5` (Trigger). It checks to see if the process from `$4` is running and if not, calls a Jamf policy with a custom trigger from `$5`. 4 | -------------------------------------------------------------------------------- /triggerPolicyWhenProcessNotRunning/triggerPolicyWhenProcessNotRunning.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Author: Scott Blake 4 | # Modified: 2017-01-23 5 | # 6 | # This script takes arguments in $4 (Process) and $5 (Trigger). It checks to 7 | # see if the process from $4 is running and if not, calls a Jamf policy with a 8 | # custom trigger from $5. 9 | # 10 | ################################################################################ 11 | # Changelog 12 | # 13 | # Version 1.0 - Scott Blake 14 | # Initial script 15 | # 16 | ################################################################################ 17 | # 18 | 19 | process="$4" 20 | processrunning=$( ps axc | grep "${process}$" ) 21 | 22 | CheckBinary (){ 23 | # Identify location of jamf binary. 24 | jamf_binary=`/usr/bin/which jamf` 25 | 26 | if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then 27 | jamf_binary="/usr/sbin/jamf" 28 | elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 29 | jamf_binary="/usr/local/bin/jamf" 30 | elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then 31 | jamf_binary="/usr/local/bin/jamf" 32 | fi 33 | } 34 | 35 | CheckBinary 36 | 37 | if [ "${processrunning}" != "" ]; then 38 | echo "$process IS running, try again later." 39 | else 40 | echo "${process} IS NOT running, will try to update it now." 41 | $jamf_binary policy -event "$5" -verbose 42 | fi 43 | --------------------------------------------------------------------------------