#!/bin/zsh ## postinstall # Postinstall script which creates the following: # - A LaunchDaemon that starts a separate script to run a Jamf Pro policy command # - A script to wait for Jamf Pro enrollment to complete then triggers Setup Your Mac # - A script that is designed to be called by a Jamf Pro policy to unload the Launch Daemon # -- and then remove the LaunchDaemon and script # - Creates "/Library/Application Support/Dialog/Dialog.png" from Self Service's custom icon (thanks, @meschwartz!) # # Created 01.16.2023 @robjschroeder # Updated 03.11.2023 @robjschroeder # Updated 04.13.2023 @dan-snelson -- version 1.2.0 # Updated 05.09.2023 @robjschroeder -- version 1.2.1 # - Removed function dialogCheck, will rely on Setup Your Mac to download the latest version of swiftDialog # + Renamed script for alignment with Setup Your Mac # Updated 05.16.2023 @robjschroeder -- version 1.2.2 # + Added record of OS version and build to log # + Added extra 'If' to look for touch file in case the jamf.log gets wiped. This is helpful if SYM has a minimum # build requirement before it can complete. (Thanks @drtaru!!) ################################################## pathToScript=$0 pathToPackage=$1 targetLocation=$2 targetVolume=$3 # Script Variables scriptVersion="1.2.2" export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/ organizationIdentifier="com.company" scriptLog="/var/log/${organizationIdentifier}.log" osVersion=$( sw_vers -productVersion ) osBuild=$( sw_vers -buildVersion ) tempUtilitiesPath="/usr/local/SYM-enrollment" # Jamf Pro Policy Trigger Trigger="symStart" # After Setup Assistant exits, if jamf enrollment isn't complete, # this is how many seconds to wait complete before exiting with an error: enrollmentTimeout="120" # One approach is to use the following locations and files: # LaunchDaemon: # /Library/LaunchDaemons/${organizationIdentifier}.sym-prestarter.plist # Temporary folder for the installer and scripts: # /usr/local/SYM-enrollment # Scripts: # ${tempUtilitiesPath}/${organizationIdentifier}.sym-prestarter-installer.zsh # ${tempUtilitiesPath}/${organizationIdentifier}.sym-prestarter-uninstaller.zsh # Create temp folder for scripts if [[ ! -d ${tempUtilitiesPath} ]]; then mkdir ${tempUtilitiesPath} fi # Client-side logging if [[ ! -f "${scriptLog}" ]]; then touch "${scriptLog}" fi # Client-side Script Logging Function (Thanks @dan-snelson!!) function updateScriptLog() { echo -e "$( date +%Y-%m-%d\ %H:%M:%S ) - ${1}" | tee -a "${scriptLog}" } # Start Logging updateScriptLog "\n###\n# PreStage SYM (${scriptVersion})\n# https://techitout.xyz/\n###\n" updateScriptLog "PRE-FLIGHT CHECK: Initiating ..." # This script must be run as root or via Jamf Pro. # The resulting Script and LaunchDaemon will be run as root. if [[ $(id -u) -ne 0 ]]; then updateScriptLog "PRE-FLIGHT CHECK: This script must be run as root; exiting." exit 1 fi # Record OS Information into log updateScriptLog "PRE-FLIGHT CHECK: Running macOS $osVersion build $osBuild" # Pre-flight Checks Complete updateScriptLog "PRE-FLIGHT CHECK: Complete" # Script and Launch Daemon/Agent variables installerBaseString=${organizationIdentifier}.sym-prestarter installerScriptName=${installerBaseString}-installer.zsh installerScriptPath=${tempUtilitiesPath}/${installerScriptName} uninstallerScriptName=${installerBaseString}-uninstaller.zsh uninstallerScriptPath=${tempUtilitiesPath}/${uninstallerScriptName} launchDaemonName=${installerBaseString}.plist launchDaemonPath="/Library/LaunchDaemons"/${launchDaemonName} # The following creates a script that triggers the swiftDialog setup your mac script to start. # Leave a full return at the end of the content before the last "ENDOFINSTALLERSCRIPT" line. updateScriptLog "PreStage SYM: Creating ${installerScriptPath}" ( cat < "${installerScriptPath}" updateScriptLog "PreStage SYM: ${installerScriptPath} created." updateScriptLog "PreStage SYM: Setting permissions for ${installerScriptPath}." chmod 755 "${installerScriptPath}" chown root:wheel "${installerScriptPath}" #----------- # The following creates the LaunchDaemon file # that starts the script # that waits for Jamf Pro enrollment # then runs the jamf policy -event command to run your Setup-Your-Mac-via-Dialog.bash script. # Leave a full return at the end of the content before the last "ENDOFLAUNCHDAEMON" line. updateScriptLog "PreStage SYM: Creating ${launchDaemonPath}." ( cat < Label ${launchDaemonName} RunAtLoad UserName root ProgramArguments /bin/zsh ${installerScriptPath} StandardErrorPath /var/tmp/${installerScriptName}.err.log StandardOutPath /var/tmp/${installerScriptName}.out.log ENDOFLAUNCHDAEMON ) > "${launchDaemonPath}" updateScriptLog "PreStage SYM: Setting permissions for ${launchDaemonPath}." chmod 644 "${launchDaemonPath}" chown root:wheel "${launchDaemonPath}" updateScriptLog "PreStage SYM: Loading ${launchDaemonName}." launchctl load "${launchDaemonPath}" #----------- # The following creates the script to uninstall the LaunchDaemon and installer script. # You can create a Jamf Pro policy with the following characteristics: # General settings: # --Name: Cleanup SYM Installers # --Trigger: Custom Trigger: cleanup-sym-preinstaller # --Scope: All Computers # --Frequency: Once per Computer # Files and Processes settings: # --Execute Command: Whatever your $uninstallerScriptPath is set to. # # In your Setup-Your-Mac-via-Dialog.sh script, include the policy near the end of your policy array. # # Leave a full return at the end of the content before the last "ENDOFUNINSTALLERSCRIPT" line. updateScriptLog "PreStage SYM: Creating ${uninstallerScriptPath}." ( cat < "${uninstallerScriptPath}" updateScriptLog "PreStage SYM: Setting permissions for ${uninstallerScriptPath}." chmod 777 "${uninstallerScriptPath}" chown root:wheel "${uninstallerScriptPath}" updateScriptLog "PreStage SYM: Complete." exit 0 ## Success exit 1 ## Failure