From 9c5ab458518a41faaffb8f8ebae186d1b6e4f9ae Mon Sep 17 00:00:00 2001 From: Theile Date: Mon, 19 Sep 2022 11:38:43 +0200 Subject: [PATCH] Version 9.4 of my MDM scripts --- MDM/-Installomator 1st -DEPNotify.sh | 358 ++++++++++++++++ MDM/-Installomator 1st SS DEPNotify.sh | 358 ++++++++++++++++ MDM/-Installomator 1st SS.sh | 302 +++++++++++++ MDM/-Installomator 1st condition Addigy.sh | 13 + MDM/-Installomator 1st.sh | 305 ++++++++++++++ MDM/-Progress 1st Dialog condition.sh | 13 + MDM/-Progress 1st Dialog.sh | 395 ++++++++++++++++++ MDM/-install Dialog direct condition.sh | 17 + MDM/-install Dialog direct.sh | 148 +++++++ ...-install Installomator direct condition.sh | 14 + MDM/-install Installomator direct.sh | 147 +++++++ MDM/App script.sh | 185 -------- .../Addigy condition notes.sh | 124 ++++++ .../App VFA SS github.sh | 279 +++++++++++++ .../App VFA SS.sh | 227 ++++++++++ .../App browser-security.sh | 211 ++++++++++ .../App normal SS multi-app.sh | 214 ++++++++++ .../App normal SS.sh | 211 ++++++++++ MDM/App-install/App VFA.sh | 93 +++++ .../App browser-security Auto-install.sh | 79 ++++ MDM/App-install/App browser-security SS.sh | 79 ++++ MDM/App-install/App normal Auto-install.sh | 79 ++++ MDM/App-install/App normal SS.sh | 79 ++++ MDM/App-install/App service Auto-install.sh | 208 +++++++++ MDM/App-loop script.sh | 193 --------- MDM/InstallInstallomator.sh | 43 -- MDM/Installomator update.sh | 42 -- MDM/MDMAddigy CustomSoftware.sh | 115 ----- MDM/MDMMosyle install.sh | 79 ---- MDM/Manual valuesfromarguments.sh | 56 --- ...stallomator.sh => Remove Installomator.sh} | 0 31 files changed, 3953 insertions(+), 713 deletions(-) create mode 100755 MDM/-Installomator 1st -DEPNotify.sh create mode 100755 MDM/-Installomator 1st SS DEPNotify.sh create mode 100755 MDM/-Installomator 1st SS.sh create mode 100644 MDM/-Installomator 1st condition Addigy.sh create mode 100755 MDM/-Installomator 1st.sh create mode 100644 MDM/-Progress 1st Dialog condition.sh create mode 100755 MDM/-Progress 1st Dialog.sh create mode 100755 MDM/-install Dialog direct condition.sh create mode 100755 MDM/-install Dialog direct.sh create mode 100755 MDM/-install Installomator direct condition.sh create mode 100755 MDM/-install Installomator direct.sh delete mode 100755 MDM/App script.sh create mode 100644 MDM/App-install with Dialog and dockutil/Addigy condition notes.sh create mode 100755 MDM/App-install with Dialog and dockutil/App VFA SS github.sh create mode 100755 MDM/App-install with Dialog and dockutil/App VFA SS.sh create mode 100755 MDM/App-install with Dialog and dockutil/App browser-security.sh create mode 100644 MDM/App-install with Dialog and dockutil/App normal SS multi-app.sh create mode 100644 MDM/App-install with Dialog and dockutil/App normal SS.sh create mode 100755 MDM/App-install/App VFA.sh create mode 100644 MDM/App-install/App browser-security Auto-install.sh create mode 100644 MDM/App-install/App browser-security SS.sh create mode 100644 MDM/App-install/App normal Auto-install.sh create mode 100644 MDM/App-install/App normal SS.sh create mode 100644 MDM/App-install/App service Auto-install.sh delete mode 100755 MDM/App-loop script.sh delete mode 100644 MDM/InstallInstallomator.sh delete mode 100755 MDM/Installomator update.sh delete mode 100755 MDM/MDMAddigy CustomSoftware.sh delete mode 100644 MDM/MDMMosyle install.sh delete mode 100755 MDM/Manual valuesfromarguments.sh rename MDM/{RemoveInstallomator.sh => Remove Installomator.sh} (100%) diff --git a/MDM/-Installomator 1st -DEPNotify.sh b/MDM/-Installomator 1st -DEPNotify.sh new file mode 100755 index 0000000..9df84a0 --- /dev/null +++ b/MDM/-Installomator 1st -DEPNotify.sh @@ -0,0 +1,358 @@ +#!/bin/sh + +# Installation using Installomator with DEPNotify window +instance="Instance" # Name of used instance + +LOGO="mosyleb" # "appstore", "jamf", "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what=(dialog dockutil microsoftautoupdate supportapp applenyfonts applesfpro applesfmono applesfcompact xink zohoworkdrivetruesync textmate 1password7 wwdc theunarchiver keka microsoftedge microsoftteams microsoftonedrive microsoftoffice365) +# Remember: dialog dockutil + +installomatorOptions="NOTIFY=silent BLOCKING_PROCESS_ACTION=ignore INSTALL=force IGNORE_APP_STORE_APPS=yes LOGGING=REQ" + +# DEPNotify display settings, change as desired +title="Installing Apps and other software" +message="Please wait while we download and install the needed software." +endMessage="Installation complete! Please reboot to activate FileVault." +errorMessage="A problem was encountered setting up this Mac. Please contact IT." + +###################################################################### +# Installomator 1st DEPNotify +# +# Installation using Installomator showing progress with DEPNotify +# Great stand-alone solution if installs are only done using Installomator. +# No customization below… +###################################################################### +# This script can be used to install software using Installomator. +# Script will start DEPNotify to display a progress bar. +# Progress bar moves between installations +###################################################################### +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API +# v. 9.3 : 2022-08-29 : installomatorOptions in quotes and ignore blocking processes. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. ws1 support. +# v. 9.2.2 : 2022-06-17 : installomatorOptions introduced. Check 1.1.1.1 for internet connection. +# v. 9.2.1 : 2022-05-30 : Some changes to logging +# v. 9.2 : 2022-05-19 : Built in installer for Installlomator, and display dialog if error happens. Now universal script for all supported MDMs based on LOGO variable. +# v. 9.1 : 2022-04-13 : Using INSTALL=force in Label only, so Microsoft labels will not start updating +# v. 9.0.1 : 2022-02-21 : LOGO=addigy, few more "true" lines, and errorOutput on error +# v. 9.0.0 : 2022-02-14 : Updated for Inst. 9.0, Logging improved with printlog +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Check before running +case $LOGO in + addigy|microsoft) + conditionFile="/var/db/.Installomator1stDone" + # Addigy and Microsoft Endpoint Manager (Intune) need a check for a touched file + if [ -e "$conditionFile" ]; then + echo "$LOGO setup detected" + echo "$conditionFile exists, so we exit." + exit 0 + else + echo "$conditionFile not found, so we continue…" + fi + ;; +esac + +# Mark: Constants, logging and caffeinate +log_message="$instance: Installomator 1st with DEPNotify, v$scriptVersion" +label="1st-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + exit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +# Command-file to DEPNotify +DEPNOTIFY_LOG="/var/tmp/depnotify.log" + +# Counters +errorCount=0 +countLabels=${#what[@]} +printlog "Total installations: $countLabels" + +# Using LOGO variable to specify MDM and shown logo +case $LOGO in + appstore) + # Apple App Store on Mac + if [[ $(sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + ;; + jamf) + # Jamf Pro + LOGO_PATH="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" + ;; + mosyleb) + # Mosyle Business + LOGO_PATH="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" + ;; + mosylem) + # Mosyle Manager (education) + LOGO_PATH="/Applications/Manager.app/Contents/Resources/AppIcon.icns" + ;; + addigy) + # Addigy + LOGO_PATH="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" + ;; + microsoft) + # Microsoft Endpoint Manager (Intune) + LOGO_PATH="/Library/Intune/Microsoft Intune Agent.app/Contents/Resources/AppIcon.icns" + ;; + ws1) + # Workspace ONE (AirWatch) + LOGO="/Applications/Workspace ONE Intelligent Hub.app/Contents/Resources/AppIcon.icns" + ;; +esac +if [[ ! -a "${LOGO_PATH}" ]]; then + printlog "ERROR in LOGO_PATH '${LOGO_PATH}', setting Mac App Store." + if [[ $(/usr/bin/sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi +fi +printlog "LOGO: $LOGO - LOGO_PATH: $LOGO_PATH" + +# Mark: Functions +printlog "depnotify_command function" +echo "" > $DEPNOTIFY_LOG || true +function depnotify_command(){ + printlog "DEPNotify-command: $1" + echo "$1" >> $DEPNOTIFY_LOG || true +} + +printlog "startDEPNotify function" +function startDEPNotify() { + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + launchctl asuser $currentUserID open -a "/Applications/Utilities/DEPNotify.app/Contents/MacOS/DEPNotify" --args -path "$DEPNOTIFY_LOG" || true # --args -fullScreen + sleep 5 + depnotify_command "Command: KillCommandFile:" + depnotify_command "Command: MainTitle: $title" + depnotify_command "Command: Image: $LOGO_PATH" + depnotify_command "Command: MainText: $message" + depnotify_command "Command: Determinate: $countLabels" +} + +# Notify the user using AppleScript +printlog "displayDialog function" +function displayDialog(){ + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + if [[ "$currentUser" != "" ]]; then + launchctl asuser $currentUserID sudo -u $currentUser osascript -e "button returned of (display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon POSIX file \"$LOGO_PATH\")" || true + fi +} + +# Mark: Code +name="Installomator" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg +gitusername="Installomator" +gitreponame="Installomator" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="JME5BW3F3R" + +destFile="/usr/local/Installomator/Installomator.sh" +currentInstalledVersion="$(${destFile} version 2>/dev/null || true)" +printlog "${destFile} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion} ..." + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +# Installing DEPNotify +cmdOutput="$( ${destFile} depnotify LOGO=$LOGO NOTIFY=silent BLOCKING_PROCESS_ACTION=ignore LOGGING=WARN || true )" +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +printlog "DEPNotify install result: $exitStatus" + +itemName="" +errorLabels="" +((countLabels++)) +((countLabels--)) +printlog "$countLabels labels to install" + +startDEPNotify + +for item in "${what[@]}"; do + # Check if DEPNotify is running and try open it if not + if ! pgrep -xq "DEPNotify"; then + startDEPNotify + fi + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + depnotify_command "Status: $itemName installing…" + else + depnotify_command "Status: $item installing…" + fi + printlog "$item $itemName" + cmdOutput="$( ${destFile} ${item} LOGO=$LOGO ${installomatorOptions} || true )" + #cmdOutput="2022-05-19 13:20:45 : REQ : installomator : ################## End Installomator, exit code 0" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + printlog "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text "WARN" || true )" + printlog "$warnOutput" + else + printlog "Error installing ${item}. Exit code ${exitStatus}" + #printlog "$cmdOutput" + errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + printlog "$errorOutput" + ((errorCount++)) + errorLabels="$errorLabels ${item}" + fi + ((countLabels--)) + itemName="" +done + +# Mark: Finishing +# Prevent re-run of script if conditionFile is set +if [[ ! -z "$conditionFile" ]]; then + printlog "Touching condition file so script will not run again" + touch "$conditionFile" || true + printlog "$(ls -al "$conditionFile" || true)" +fi + +# Show error to user if any +printlog "Errors: $errorCount" +if [[ $errorCount -ne 0 ]]; then + errorMessage="${errorMessage} Total errors: $errorCount" + message="$errorMessage" + displayDialog & + endMessage="$message" + printlog "errorLabels: $errorLabels" +fi + +depnotify_command "Command: MainText: $endMessage" +depnotify_command "Command: Quit: $endMessage" + +sleep 1 +printlog "Remove $(rm -fv $DEPNOTIFY_LOG || true)" + +printlog "Ending" +caffexit $errorCount diff --git a/MDM/-Installomator 1st SS DEPNotify.sh b/MDM/-Installomator 1st SS DEPNotify.sh new file mode 100755 index 0000000..b960734 --- /dev/null +++ b/MDM/-Installomator 1st SS DEPNotify.sh @@ -0,0 +1,358 @@ +#!/bin/sh + +# Installation using Installomator with DEPNotify window +instance="Instance" # Name of used instance + +LOGO="mosyleb" # "appstore", "jamf", "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what=(dialog dockutil microsoftautoupdate supportapp applenyfonts applesfpro applesfmono applesfcompact xink zohoworkdrivetruesync textmate 1password7 wwdc theunarchiver keka microsoftedge microsoftteams microsoftonedrive microsoftoffice365) +# Remember: dialog dockutil + +installomatorOptions="NOTIFY=all BLOCKING_PROCESS_ACTION=prompt_user" + +# DEPNotify display settings, change as desired +title="Installing Apps and other software" +message="Please wait while we download and install the needed software." +endMessage="Installation complete! Please reboot to activate FileVault." +errorMessage="A problem was encountered setting up this Mac. Please contact IT." + +###################################################################### +# Installomator 1st DEPNotify +# +# Installation using Installomator showing progress with DEPNotify +# Great stand-alone solution if installs are only done using Installomator. +# No customization below… +###################################################################### +# This script can be used to install software using Installomator. +# Script will start DEPNotify to display a progress bar. +# Progress bar moves between installations +###################################################################### +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API +# v. 9.3 : 2022-08-29 : installomatorOptions in quotes and ignore blocking processes. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. ws1 support. +# v. 9.2.2 : 2022-06-17 : installomatorOptions introduced. Check 1.1.1.1 for internet connection. +# v. 9.2.1 : 2022-05-30 : Some changes to logging +# v. 9.2 : 2022-05-19 : Built in installer for Installlomator, and display dialog if error happens. Now universal script for all supported MDMs based on LOGO variable. +# v. 9.1 : 2022-04-13 : Using INSTALL=force in Label only, so Microsoft labels will not start updating +# v. 9.0.1 : 2022-02-21 : LOGO=addigy, few more "true" lines, and errorOutput on error +# v. 9.0.0 : 2022-02-14 : Updated for Inst. 9.0, Logging improved with printlog +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Check before running +case $LOGO in + addigy|microsoft) + conditionFile="/var/db/.Installomator1stDone" + # Addigy and Microsoft Endpoint Manager (Intune) need a check for a touched file + if [ -e "$conditionFile" ]; then + echo "$LOGO setup detected" + echo "$conditionFile exists, so we exit." + exit 0 + else + echo "$conditionFile not found, so we continue…" + fi + ;; +esac + +# Mark: Constants, logging and caffeinate +log_message="$instance: Installomator 1st with DEPNotify, v$scriptVersion" +label="1st-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + exit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +# Command-file to DEPNotify +DEPNOTIFY_LOG="/var/tmp/depnotify.log" + +# Counters +errorCount=0 +countLabels=${#what[@]} +printlog "Total installations: $countLabels" + +# Using LOGO variable to specify MDM and shown logo +case $LOGO in + appstore) + # Apple App Store on Mac + if [[ $(sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + ;; + jamf) + # Jamf Pro + LOGO_PATH="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" + ;; + mosyleb) + # Mosyle Business + LOGO_PATH="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" + ;; + mosylem) + # Mosyle Manager (education) + LOGO_PATH="/Applications/Manager.app/Contents/Resources/AppIcon.icns" + ;; + addigy) + # Addigy + LOGO_PATH="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" + ;; + microsoft) + # Microsoft Endpoint Manager (Intune) + LOGO_PATH="/Library/Intune/Microsoft Intune Agent.app/Contents/Resources/AppIcon.icns" + ;; + ws1) + # Workspace ONE (AirWatch) + LOGO="/Applications/Workspace ONE Intelligent Hub.app/Contents/Resources/AppIcon.icns" + ;; +esac +if [[ ! -a "${LOGO_PATH}" ]]; then + printlog "ERROR in LOGO_PATH '${LOGO_PATH}', setting Mac App Store." + if [[ $(/usr/bin/sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi +fi +printlog "LOGO: $LOGO - LOGO_PATH: $LOGO_PATH" + +# Mark: Functions +printlog "depnotify_command function" +echo "" > $DEPNOTIFY_LOG || true +function depnotify_command(){ + printlog "DEPNotify-command: $1" + echo "$1" >> $DEPNOTIFY_LOG || true +} + +printlog "startDEPNotify function" +function startDEPNotify() { + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + launchctl asuser $currentUserID open -a "/Applications/Utilities/DEPNotify.app/Contents/MacOS/DEPNotify" --args -path "$DEPNOTIFY_LOG" || true # --args -fullScreen + sleep 5 + depnotify_command "Command: KillCommandFile:" + depnotify_command "Command: MainTitle: $title" + depnotify_command "Command: Image: $LOGO_PATH" + depnotify_command "Command: MainText: $message" + depnotify_command "Command: Determinate: $countLabels" +} + +# Notify the user using AppleScript +printlog "displayDialog function" +function displayDialog(){ + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + if [[ "$currentUser" != "" ]]; then + launchctl asuser $currentUserID sudo -u $currentUser osascript -e "button returned of (display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon POSIX file \"$LOGO_PATH\")" || true + fi +} + +# Mark: Code +name="Installomator" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg +gitusername="Installomator" +gitreponame="Installomator" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="JME5BW3F3R" + +destFile="/usr/local/Installomator/Installomator.sh" +currentInstalledVersion="$(${destFile} version 2>/dev/null || true)" +printlog "${destFile} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion} ..." + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +# Installing DEPNotify +cmdOutput="$( ${destFile} depnotify LOGO=$LOGO NOTIFY=silent BLOCKING_PROCESS_ACTION=ignore LOGGING=WARN || true )" +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +printlog "DEPNotify install result: $exitStatus" + +itemName="" +errorLabels="" +((countLabels++)) +((countLabels--)) +printlog "$countLabels labels to install" + +startDEPNotify + +for item in "${what[@]}"; do + # Check if DEPNotify is running and try open it if not + if ! pgrep -xq "DEPNotify"; then + startDEPNotify + fi + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + depnotify_command "Status: $itemName installing…" + else + depnotify_command "Status: $item installing…" + fi + printlog "$item $itemName" + cmdOutput="$( ${destFile} ${item} LOGO=$LOGO ${installomatorOptions} || true )" + #cmdOutput="2022-05-19 13:20:45 : REQ : installomator : ################## End Installomator, exit code 0" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + printlog "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text "WARN" || true )" + printlog "$warnOutput" + else + printlog "Error installing ${item}. Exit code ${exitStatus}" + #printlog "$cmdOutput" + errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + printlog "$errorOutput" + ((errorCount++)) + errorLabels="$errorLabels ${item}" + fi + ((countLabels--)) + itemName="" +done + +# Mark: Finishing +# Prevent re-run of script if conditionFile is set +if [[ ! -z "$conditionFile" ]]; then + printlog "Touching condition file so script will not run again" + touch "$conditionFile" || true + printlog "$(ls -al "$conditionFile" || true)" +fi + +# Show error to user if any +printlog "Errors: $errorCount" +if [[ $errorCount -ne 0 ]]; then + errorMessage="${errorMessage} Total errors: $errorCount" + message="$errorMessage" + displayDialog & + endMessage="$message" + printlog "errorLabels: $errorLabels" +fi + +depnotify_command "Command: MainText: $endMessage" +depnotify_command "Command: Quit: $endMessage" + +sleep 1 +printlog "Remove $(rm -fv $DEPNOTIFY_LOG || true)" + +printlog "Ending" +caffexit $errorCount diff --git a/MDM/-Installomator 1st SS.sh b/MDM/-Installomator 1st SS.sh new file mode 100755 index 0000000..9efa824 --- /dev/null +++ b/MDM/-Installomator 1st SS.sh @@ -0,0 +1,302 @@ +#!/bin/sh + +# Installation using Installomator +instance="Instance" # Name of used instance + +LOGO="mosyleb" # "appstore", "jamf", "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what=(dialog dockutil microsoftautoupdate supportapp applenyfonts applesfpro applesfmono applesfcompact xink zohoworkdrivetruesync textmate 1password7 wwdc theunarchiver keka microsoftedge microsoftteams microsoftonedrive microsoftoffice365) +# Remember: dialog dockutil + +installomatorOptions="NOTIFY=all BLOCKING_PROCESS_ACTION=prompt_user" + +# Error message to user if any occur +errorMessage="A problem was encountered setting up this Mac. Please contact IT." + +###################################################################### +# Installomator 1st for Self Service +# +# Installation using Installomator +# No customization below… +###################################################################### +# This script can be used to install software using Installomator, where the user activate it in Self Service. +# Script will display a dialog if any errors happens. +# Progress is shown in notifications to the user +###################################################################### +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API +# v. 9.3 : 2022-08-29 : installomatorOptions in quotes and ignore blocking processes. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. ws1 support. +# v. 9.2.2 : 2022-06-17 : installomatorOptions introduced. Check 1.1.1.1 for internet connection. +# v. 9.2.1 : 2022-05-30 : Some changes to logging +# v. 9.2 : 2022-05-19 : Built in installer for Installlomator, and display dialog if error happens. Now universal script for all supported MDMs based on LOGO variable. +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Check before running +case $LOGO in + addigy|microsoft) + conditionFile="/var/db/.Installomator1stDone" + # Addigy and Microsoft Endpoint Manager (Intune) need a check for a touched file + if [ -e "$conditionFile" ]; then + echo "$LOGO setup detected" + echo "$conditionFile exists, so we exit." + exit 0 + else + echo "$conditionFile not found, so we continue…" + fi + ;; +esac + +# Mark: Constants, logging and caffeinate +log_message="$instance: Installomator 1st, v$scriptVersion" +label="1st-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + caffexit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +# Counters +errorCount=0 +countLabels=${#what[@]} +printlog "Total installations: $countLabels" + +# Using LOGO variable to specify MDM and shown logo +case $LOGO in + appstore) + # Apple App Store on Mac + if [[ $(sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + ;; + jamf) + # Jamf Pro + LOGO_PATH="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" + ;; + mosyleb) + # Mosyle Business + LOGO_PATH="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" + ;; + mosylem) + # Mosyle Manager (education) + LOGO_PATH="/Applications/Manager.app/Contents/Resources/AppIcon.icns" + ;; + addigy) + # Addigy + LOGO_PATH="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" + ;; + microsoft) + # Microsoft Endpoint Manager (Intune) + LOGO_PATH="/Library/Intune/Microsoft Intune Agent.app/Contents/Resources/AppIcon.icns" + ;; + ws1) + # Workspace ONE (AirWatch) + LOGO="/Applications/Workspace ONE Intelligent Hub.app/Contents/Resources/AppIcon.icns" + ;; +esac +if [[ ! -a "${LOGO_PATH}" ]]; then + printlog "ERROR in LOGO_PATH '${LOGO_PATH}', setting Mac App Store." + if [[ $(/usr/bin/sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi +fi +printlog "LOGO: $LOGO – LOGO_PATH: $LOGO_PATH" + +# Mark: Functions +# Notify the user using AppleScript +function displayDialog(){ + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + if [[ "$currentUser" != "" ]]; then + launchctl asuser $currentUserID sudo -u $currentUser osascript -e "button returned of (display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon POSIX file \"$LOGO_PATH\")" || true + fi +} + +# Mark: Code +name="Installomator" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg +gitusername="Installomator" +gitreponame="Installomator" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="JME5BW3F3R" + +destFile="/usr/local/Installomator/Installomator.sh" +currentInstalledVersion="$(${destFile} version 2>/dev/null || true)" +printlog "${destFile} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion} ..." + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +errorLabels="" +((countLabels++)) +((countLabels--)) +printlog "$countLabels labels to install" + +for item in "${what[@]}"; do + printlog "$item" + cmdOutput="$( ${destFile} ${item} LOGO=$LOGO ${installomatorOptions} || true )" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + printlog "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text "WARN" || true )" + printlog "$warnOutput" + else + printlog "Error installing ${item}. Exit code ${exitStatus}" + #printlog "$cmdOutput" + errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + printlog "$errorOutput" + ((errorCount++)) + errorLabels="$errorLabels ${item}" + fi + ((countLabels--)) + itemName="" +done + +# Mark: Finishing +# Prevent re-run of script if conditionFile is set +if [[ ! -z "$conditionFile" ]]; then + printlog "Touching condition file so script will not run again" + touch "$conditionFile" || true + printlog "$(ls -al "$conditionFile" || true)" +fi + +# Show error to user if any +printlog "Errors: $errorCount" +if [[ $errorCount -ne 0 ]]; then + printlog "ERROR: Display error dialog to user!" + errorMessage="${errorMessage} Total errors: $errorCount" + message="$errorMessage" + displayDialog & + printlog "errorLabels: $errorLabels" +fi + +printlog "Ending" +caffexit $errorCount diff --git a/MDM/-Installomator 1st condition Addigy.sh b/MDM/-Installomator 1st condition Addigy.sh new file mode 100644 index 0000000..95b9806 --- /dev/null +++ b/MDM/-Installomator 1st condition Addigy.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Mark: Addigy Condition on condition file +# Install on success + +conditionFile="/var/db/.Installomator1stDone" +if [ -e "$conditionFile" ]; then + echo "$conditionFile exists. Exiting." + exit 1 +else + echo "$conditionFile not found. Continue…" + exit 0 +fi diff --git a/MDM/-Installomator 1st.sh b/MDM/-Installomator 1st.sh new file mode 100755 index 0000000..744f5c3 --- /dev/null +++ b/MDM/-Installomator 1st.sh @@ -0,0 +1,305 @@ +#!/bin/sh + +# Installation using Installomator +instance="Instance" # Name of used instance + +LOGO="mosyleb" # "appstore", "jamf", "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what=(dialog dockutil microsoftautoupdate supportapp xink zohoworkdrivetruesync textmate applenyfonts applesfpro applesfmono applesfcompact 1password7 wwdc theunarchiver keka microsoftedge microsoftteams microsoftonedrive microsoftoffice365) +# Remember: dialog dockutil + +installomatorOptions="NOTIFY=silent BLOCKING_PROCESS_ACTION=ignore INSTALL=force IGNORE_APP_STORE_APPS=yes LOGGING=REQ" + +# Error message to user if any occur +showError="1" # Show error message if 1 (0 if it should not be shown) +errorMessage="A problem was encountered setting up this Mac. Please contact IT." + +###################################################################### +# Installomator 1st +# +# Installation using Installomator (use separate Installation1stProgress script to show progress) +# No customization below… +###################################################################### +# This script can be used to install software using Installomator. +# Script will display a dialog if any errors happens. +# User is not notified about installations. +###################################################################### +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : Making error message optional. downloadURL can fall back on GitHub API. +# v. 9.3 : 2022-08-29 : installomatorOptions in quotes and ignore blocking processes. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. ws1 support. +# v. 9.2.2 : 2022-06-17 : installomatorOptions introduced. Check 1.1.1.1 for internet connection. +# v. 9.2.1 : 2022-05-30 : Some changes to logging +# v. 9.2 : 2022-05-19 : Built in installer for Installomator, and display dialog if error happens. Now universal script for all supported MDMs based on LOGO variable. +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Check before running +case $LOGO in + addigy|microsoft) + conditionFile="/var/db/.Installomator1stDone" + # Addigy and Microsoft Endpoint Manager (Intune) need a check for a touched file + if [ -e "$conditionFile" ]; then + echo "$LOGO setup detected" + echo "$conditionFile exists, so we exit." + exit 0 + else + echo "$conditionFile not found, so we continue…" + fi + ;; +esac + +# Mark: Constants, logging and caffeinate +log_message="$instance: Installomator 1st, v$scriptVersion" +label="1st-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + caffexit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +# Counters +errorCount=0 +countLabels=${#what[@]} +printlog "Total installations: $countLabels" + +# Using LOGO variable to specify MDM and shown logo +case $LOGO in + appstore) + # Apple App Store on Mac + if [[ $(sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + ;; + jamf) + # Jamf Pro + LOGO_PATH="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" + ;; + mosyleb) + # Mosyle Business + LOGO_PATH="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" + ;; + mosylem) + # Mosyle Manager (education) + LOGO_PATH="/Applications/Manager.app/Contents/Resources/AppIcon.icns" + ;; + addigy) + # Addigy + LOGO_PATH="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" + ;; + microsoft) + # Microsoft Endpoint Manager (Intune) + LOGO_PATH="/Library/Intune/Microsoft Intune Agent.app/Contents/Resources/AppIcon.icns" + ;; + ws1) + # Workspace ONE (AirWatch) + LOGO="/Applications/Workspace ONE Intelligent Hub.app/Contents/Resources/AppIcon.icns" + ;; +esac +if [[ ! -a "${LOGO_PATH}" ]]; then + printlog "ERROR in LOGO_PATH '${LOGO_PATH}', setting Mac App Store." + if [[ $(/usr/bin/sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi +fi +printlog "LOGO: $LOGO – LOGO_PATH: $LOGO_PATH" + +# Mark: Functions +# Notify the user using AppleScript +function displayDialog(){ + currentUser="$(stat -f "%Su" /dev/console)" + currentUserID=$(id -u "$currentUser") + if [[ "$currentUser" != "" ]]; then + launchctl asuser $currentUserID sudo -u $currentUser osascript -e "button returned of (display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon POSIX file \"$LOGO_PATH\")" || true + fi +} + +# Mark: Code +name="Installomator" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg +gitusername="Installomator" +gitreponame="Installomator" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="JME5BW3F3R" + +destFile="/usr/local/Installomator/Installomator.sh" +currentInstalledVersion="$(${destFile} version 2>/dev/null || true)" +printlog "${destFile} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion} ..." + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +errorLabels="" +((countLabels++)) +((countLabels--)) +printlog "$countLabels labels to install" + +for item in "${what[@]}"; do + printlog "$item" + cmdOutput="$( ${destFile} ${item} LOGO=$LOGO ${installomatorOptions} || true )" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + printlog "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text "WARN" || true )" + printlog "$warnOutput" + else + printlog "Error installing ${item}. Exit code ${exitStatus}" + #printlog "$cmdOutput" + errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + printlog "$errorOutput" + ((errorCount++)) + errorLabels="$errorLabels ${item}" + fi + ((countLabels--)) + itemName="" +done + +# Mark: Finishing +# Prevent re-run of script if conditionFile is set +if [[ ! -z "$conditionFile" ]]; then + printlog "Touching condition file so script will not run again" + touch "$conditionFile" || true + printlog "$(ls -al "$conditionFile" || true)" +fi + +# Show error to user if any +printlog "Errors: $errorCount" +if [[ $errorCount -ne 0 ]]; then + printlog "ERROR: Display error dialog to user!" + errorMessage="${errorMessage} Total errors: $errorCount" + if [[ $showError -eq 1 ]]; then + message="$errorMessage" + displayDialog & + fi + printlog "errorLabels: $errorLabels" +fi + +printlog "Ending" +caffexit $errorCount diff --git a/MDM/-Progress 1st Dialog condition.sh b/MDM/-Progress 1st Dialog condition.sh new file mode 100644 index 0000000..6f91d6d --- /dev/null +++ b/MDM/-Progress 1st Dialog condition.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Mark: Addigy Condition on condition file +# Install on success + +conditionFile="/var/db/.Installation1stProgressDone" +if [ -e "$conditionFile" ]; then + echo "$conditionFile exists. Exiting." + exit 1 +else + echo "$conditionFile not found. Continue…" + exit 0 +fi diff --git a/MDM/-Progress 1st Dialog.sh b/MDM/-Progress 1st Dialog.sh new file mode 100755 index 0000000..dfb9980 --- /dev/null +++ b/MDM/-Progress 1st Dialog.sh @@ -0,0 +1,395 @@ +#!/bin/sh + +# Progress 1st with swiftDialog +instance="Instance" # Name of used instance + +LOGO="mosyleb" # "appstore", "jamf", "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +apps=( + "swiftDialog,/usr/local/bin/dialog" + "dockutil,/usr/local/bin/dockutil" + "desktoppr,/usr/local/bin/desktoppr" + "SupportApp,/Applications/Support.app" + "Xink,/Applications/Xink.app" + "Apple NewYork Font,/Library/Fonts/NewYork.ttf" + "Apple SF Pro Font,/Library/Fonts/SF-Pro.ttf" + "Apple SF Mono Font,/Library/Fonts/SF-Mono-Bold.otf" + "Apple SF Compact Font,/Library/Fonts/SF-Compact.ttf" + "Zoho WorkDrive TrueSync,/Applications/Zoho WorkDrive TrueSync.app" + "TextMate,/Applications/TextMate.app" + "Sublime Text,/Applications/Sublime Text.app" + "1Password,/Applications/1Password 7.app" + "Mactracker,/Applications/Mactracker.app" + "WWDC,/Applications/WWDC.app" + "The Unarchiver,/Applications/The Unarchiver.app" + "Keka,/Applications/Keka.app" + "Brave,/Applications/Brave Browser.app" + "Firefox,/Applications/Firefox.app" + "Microsoft AutoUpdate,/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app" + "Microsoft Edge,/Applications/Microsoft Edge.app" + "Microsoft Teams,/Applications/Microsoft Teams.app" + "Microsoft Excel,/Applications/Microsoft Excel.app" + "Microsoft OneNote,/Applications/Microsoft OneNote.app" + "Microsoft Outlook,/Applications/Microsoft Outlook.app" + "Microsoft PowerPoint,/Applications/Microsoft PowerPoint.app" + "Microsoft Word,/Applications/Microsoft Word.app" + "Microsoft OneDrive,/Applications/OneDrive.app" +) + +# Dialog display settings, change as desired +title="Installing Apps and other software" +message="Please wait while we download and install the needed software." +endMessage="Installation complete! Please reboot to activate FileVault." +displayEndMessageDialog=1 # Should endMessage be shown as a dialog? (0|1) +errorMessage="A problem was encountered setting up this Mac. Please contact IT." + +###################################################################### +# Progress 1st Dialog +# +# Showing installation progress using swiftDialog +# No customization below… +###################################################################### +# Complete script meant for running via MDM on device enrollment. This will download +# and install Dialog on the fly before opening Dialog. +# +# Log: /private/var/log/InstallationProgress.log +# This file prevents script from running again on Addigy and Microsoft Endpoint (Intune): +# "/var/db/.Installation1stProgress" +# +# Display a Dialog with a list of applications and indicate when they’ve been installed +# Useful when apps are deployed at random, perhaps without local logging. +# Applies to Mosyle App Catalog installs, VPP app installs, Installomator installs etc. +# The script watches the existence of files in the file system, so that is used to show progress. +# +# Requires Dialog v1.9.1 or later (will be installed) https://github.com/bartreardon/swiftDialog +# +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Based on the work by Adam Codega: +# https://github.com/acodega/dialog-scripts +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +# List of apps/installs to process in “apps” array. +# Provide the display name as you prefer and the path to the app/file. ex: +# "Google Chrome,/Applications/Google Chrome.app" +# A comma separates the display name from the path. Do not use commas in your display name text. +# +# Tip: Check for something like print drivers using the pkg receipt, like: +# "Konica-Minolta drivers,/var/db/receipts/jp.konicaminolta.print.package.C759.plist" +# Or fonts, like: +# "Apple SF Pro Font,/Library/Fonts/SF-Pro.ttf" +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API +# v. 9.3 : 2022-08-29 : Logging changed for current version. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. +# v. 9.2.2 : 2022-06-17 : Improved Dialog installation. Check 1.1.1.1 for internet connection. +# v. 9.2 : 2022-05-19 : Not using GitHub api for download of Dialog, show a dialog when finished to make message more important. Now universal script for all supported MDMs based on LOGO variable. +# v. 9.0 : 2022-05-16 : Based on acodega’s work, I have added progress bar, changed logging and use another log-location, a bit more error handling for Dialog download, added some "|| true"-endings to some lines to not make them fail in Addigy, and some more. +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Check before running +case $LOGO in + addigy|microsoft) + conditionFile="/var/db/.Installation1stProgressDone" + # Addigy and Microsoft Endpoint Manager (Intune) need a check for a touched file + if [ -e "$conditionFile" ]; then + echo "$LOGO setup detected" + echo "$conditionFile exists, so we exit." + exit 0 + else + echo "$conditionFile not found, so we continue…" + fi + ;; +esac + +# Mark: Constants and logging +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +log_message="$instance: Installation 1st Progress with Dialog, v$scriptVersion" +label="D1st-v$scriptVersion" + +log_location="/private/var/log/Installation1stProgress.log" +function printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + exit 90 +fi + +# Location of dialog and dialog command file +dialogApp="/usr/local/bin/dialog" +dialog_command_file="/var/tmp/dialog.log" +counterFile="/var/tmp/Installation1stProgress.plist" + +# Counters +progress_index=0 +step_progress=0 +defaults write $counterFile step -int 0 +progress_total=${#apps[@]} +printlog "Total watched installations: $progress_total" + +# Using LOGO variable to specify MDM and shown logo +case $LOGO in + appstore) + # Apple App Store on Mac + if [[ $(sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + ;; + jamf) + # Jamf Pro + LOGO_PATH="/Library/Application Support/JAMF/Jamf.app/Contents/Resources/AppIcon.icns" + ;; + mosyleb) + # Mosyle Business + LOGO_PATH="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" + ;; + mosylem) + # Mosyle Manager (education) + LOGO_PATH="/Applications/Manager.app/Contents/Resources/AppIcon.icns" + ;; + addigy) + # Addigy + LOGO_PATH="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" + ;; + microsoft) + # Microsoft Endpoint Manager (Intune) + LOGO_PATH="/Library/Intune/Microsoft Intune Agent.app/Contents/Resources/AppIcon.icns" + ;; + ws1) + # Workspace ONE (AirWatch) + LOGO="/Applications/Workspace ONE Intelligent Hub.app/Contents/Resources/AppIcon.icns" + ;; +esac +if [[ ! -a "${LOGO_PATH}" ]]; then + printlog "ERROR in LOGO_PATH '${LOGO_PATH}', setting Mac App Store." + if [[ $(/usr/bin/sw_vers -buildVersion) > "19" ]]; then + LOGO_PATH="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + else + LOGO_PATH="/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi +fi +printlog "LOGO: $LOGO – LOGO_PATH: $LOGO_PATH" + +# Mark: Functions +# execute a dialog command +echo "" > $dialog_command_file || true +function dialog_command(){ + printlog "Dialog-command: $1" + echo "$1" >> $dialog_command_file || true +} + +function appCheck(){ + dialog_command "listitem: $(echo "$app" | cut -d ',' -f1): wait" + while [ ! -e "$(echo "$app" | cut -d ',' -f2)" ]; do + sleep 2 + done + dialog_command "progresstext: Install of “$(echo "$app" | cut -d ',' -f1)” complete" + dialog_command "listitem: $(echo "$app" | cut -d ',' -f1): ✅" + progress_index=$(defaults read $counterFile step) + progress_index=$(( progress_index + 1 )) + defaults write $counterFile step -int $progress_index + dialog_command "progress: $progress_index" + printlog "at item number $progress_index" +} + +# Notify the user using AppleScript +function displayDialog(){ + if [[ "$currentUser" != "" ]]; then + launchctl asuser $currentUserID sudo -u $currentUser osascript -e "button returned of (display dialog \"$message\" buttons {\"OK\"} default button \"OK\" with icon POSIX file \"$LOGO_PATH\")" || true + fi +} + +# Mark: Code +name="Dialog" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg w. app version check +gitusername="bartreardon" +gitreponame="swiftDialog" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="PWA5E9TQ59" +destFile="/Library/Application Support/Dialog/Dialog.app" +versionKey="CFBundleShortVersionString" #CFBundleVersion + +currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)" +printlog "${name} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion}…" + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + + +while [ "$(pgrep -l "Setup Assistant")" != "" ]; do + printlog "Setup Assistant Still Running. PID $setupAssistantProcess." + sleep 1 +done +printlog "Out of Setup Assistant." + +while [ "$(pgrep -l "Finder")" = "" ]; do + printlog "Finder process not found. Assuming device is at login screen. PID $finderProcess" + sleep 1 +done +printlog "Finder is running…" + +currentUser=$(stat -f "%Su" /dev/console) +currentUserID=$(id -u "$currentUser") +printlog "Logged in user is $currentUser with ID $currentUserID" + +# set icon based on whether computer is a desktop or laptop +#hwType=$(system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book" || true) +#if [ "$hwType" != "" ]; then +# LOGO_PATH="SF=laptopcomputer.and.arrow.down,weight=thin,colour1=#51a3ef,colour2=#5154ef" +#else +# LOGO_PATH="SF=desktopcomputer.and.arrow.down,weight=thin,colour1=#51a3ef,colour2=#5154ef" +#fi + +dialogCMD="$dialogApp -p --title \"$title\" \ +--message \"$message\" \ +--icon \"$LOGO_PATH\" \ +--progress $progress_total \ +--button1text \"Please Wait\" \ +--button1disabled" + +# create the list of apps +listitems="" +for app in "${apps[@]}"; do + listitems="$listitems --listitem '$(echo "$app" | cut -d ',' -f1)'" +done + +# final command to execute +dialogCMD="$dialogCMD $listitems" + +printlog "$dialogCMD" + +# Launch dialog and run it in the background sleep for a second to let thing initialise +printlog "About to launch Dialog." +eval "$dialogCMD" & +sleep 2 + +(for app in "${apps[@]}"; do + #step_progress=$(( 1 + progress_index )) + #dialog_command "progress: $step_progress" + sleep 0.5 + appCheck & +done + +wait) + +# Mark: Finishing + +# Prevent re-run of script if conditionFile is set +if [[ ! -z "$conditionFile" ]]; then + printlog "Touching condition file so script will not run again" + touch "$conditionFile" || true + printlog "$(ls -al "$conditionFile" || true)" +fi + +# all done. close off processing and enable the "Done" button +printlog "Finalizing." +dialog_command "progresstext: $endMessage" +dialog_command "progress: complete" +dialog_command "button1text: Done" +dialog_command "button1: enable" + +if [[ $displayEndMessageDialog -eq 1 ]]; then + message="$endMessage" + displayDialog & +fi + +sleep 1 +printlog $(rm -fv $dialog_command_file || true) +printlog $(rm -fv $counterFile || true) + +printlog "Ending" diff --git a/MDM/-install Dialog direct condition.sh b/MDM/-install Dialog direct condition.sh new file mode 100755 index 0000000..2d25e09 --- /dev/null +++ b/MDM/-install Dialog direct condition.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +gitusername="bartreardon" +gitreponame="swiftDialog" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') + +destFile="/Library/Application Support/Dialog/Dialog.app" +versionKey="CFBundleShortVersionString" #CFBundleVersion + +currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + #echo "Let's install…" + exit 0 +else + #echo "No need!" + exit 1 +fi diff --git a/MDM/-install Dialog direct.sh b/MDM/-install Dialog direct.sh new file mode 100755 index 0000000..1b16e3c --- /dev/null +++ b/MDM/-install Dialog direct.sh @@ -0,0 +1,148 @@ +#!/bin/sh + +###################################################################### +# Installation of swiftDialog +# +# No customization below… +###################################################################### +# This script can be used to install swiftDialog directly from GitHub. +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API. +# v. 9.3 : 2022-08-29 : Logging changed for current version. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. +# v. 9.2.2 : 2022-06-17 : Check 1.1.1.1 for internet connection. +# v. 9.2 : 2022-05-19 : Built in installer for Installlomator. Universal script. +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Mark: Constants, logging and caffeinate +log_message="Dialog install, v$scriptVersion" +label="Dialog-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + exit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +name="Dialog" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg w. app version check +gitusername="bartreardon" +gitreponame="swiftDialog" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="PWA5E9TQ59" +destFile="/Library/Application Support/Dialog/Dialog.app" +versionKey="CFBundleShortVersionString" #CFBundleVersion + +currentInstalledVersion="$(defaults read "${destFile}/Contents/Info.plist" $versionKey || true)" +printlog "${name} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion}…" + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +caffexit 0 diff --git a/MDM/-install Installomator direct condition.sh b/MDM/-install Installomator direct condition.sh new file mode 100755 index 0000000..89cdda6 --- /dev/null +++ b/MDM/-install Installomator direct condition.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +gitusername="Installomator" +gitreponame="Installomator" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') + +destFile="/usr/local/Installomator/Installomator.sh" +if [[ ! -e "${destFile}" || "$(${destFile} version)" != "$appNewVersion" ]]; then + #echo "Let's install…" + exit 0 +else + #echo "No need!" + exit 1 +fi diff --git a/MDM/-install Installomator direct.sh b/MDM/-install Installomator direct.sh new file mode 100755 index 0000000..b822e34 --- /dev/null +++ b/MDM/-install Installomator direct.sh @@ -0,0 +1,147 @@ +#!/bin/sh + +###################################################################### +# Installation of Installomator +# +# No customization below… +###################################################################### +# This script can be used to install Installomator directly from GitHub. +###################################################################### +# +# This script made by Søren Theilgaard +# https://github.com/Theile +# Twitter and MacAdmins Slack: @theilgaard +# +# Some functions and code from Installomator: +# https://github.com/Installomator/Installomator +# +###################################################################### +scriptVersion="9.4" +# v. 9.4 : 2022-09-14 : downloadURL can fall back on GitHub API +# v. 9.3 : 2022-08-29 : Logging changed for current version. Improved installation with looping if it fails, so it can try again. Improved GitHub handling. +# v. 9.2.2 : 2022-06-17 : Check 1.1.1.1 for internet connection. +# v. 9.2 : 2022-05-19 : Built in installer for Installlomator. Universal script. +###################################################################### + +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Mark: Constants, logging and caffeinate +log_message="Installomator install, v$scriptVersion" +label="Inst-v$scriptVersion" + +log_location="/private/var/log/Installomator.log" +printlog(){ + timestamp=$(date +%F\ %T) + if [[ "$(whoami)" == "root" ]]; then + echo "$timestamp :: $label : $1" | tee -a $log_location + else + echo "$timestamp :: $label : $1" + fi +} +printlog "[LOG-BEGIN] ${log_message}" + +# Internet check +if [[ "$(nc -z -v -G 10 1.1.1.1 53 2>&1 | grep -io "succeeded")" != "succeeded" ]]; then + printlog "ERROR. No internet connection, we cannot continue." + exit 90 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" || true + pkill caffeinate || true + printlog "[LOG-END] Status $1" + exit $1 +} + +name="Installomator" +printlog "$name check for installation" +# download URL, version and Expected Team ID +# Method for GitHub pkg +gitusername="Installomator" +gitreponame="Installomator" +#printlog "$gitusername $gitreponame" +filetype="pkg" +downloadURL="https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1)" +if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") +fi +#printlog "$downloadURL" +appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') +#printlog "$appNewVersion" +expectedTeamID="JME5BW3F3R" + +destFile="/usr/local/Installomator/Installomator.sh" +currentInstalledVersion="$(${destFile} version 2>/dev/null || true)" +printlog "${destFile} version: $currentInstalledVersion" +if [[ ! -e "${destFile}" || "$currentInstalledVersion" != "$appNewVersion" ]]; then + printlog "$name not found or version not latest." + printlog "${destFile}" + printlog "Installing version ${appNewVersion} ..." + # Create temporary working directory + tmpDir="$(mktemp -d || true)" + printlog "Created working directory '$tmpDir'" + # Download the installer package + printlog "Downloading $name package version $appNewVersion from: $downloadURL" + installationCount=0 + exitCode=9 + while [[ $installationCount -lt 3 && $exitCode -gt 0 ]]; do + curlDownload=$(curl -Ls "$downloadURL" -o "$tmpDir/$name.pkg" || true) + curlDownloadStatus=$(echo $?) + if [[ $curlDownloadStatus -ne 0 ]]; then + printlog "error downloading $downloadURL, with status $curlDownloadStatus" + printlog "${curlDownload}" + exitCode=1 + else + printlog "Download $name succes." + # Verify the download + teamID=$(spctl -a -vv -t install "$tmpDir/$name.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' || true) + printlog "Team ID for downloaded package: $teamID" + # Install the package if Team ID validates + if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then + printlog "$name package verified. Installing package '$tmpDir/$name.pkg'." + pkgInstall=$(installer -verbose -dumplog -pkg "$tmpDir/$name.pkg" -target "/" 2>&1) + pkgInstallStatus=$(echo $?) + if [[ $pkgInstallStatus -ne 0 ]]; then + printlog "ERROR. $name package installation failed." + printlog "${pkgInstall}" + exitCode=2 + else + printlog "Installing $name package succes." + exitCode=0 + fi + else + printlog "ERROR. Package verification failed for $name before package installation could start. Download link may be invalid." + exitCode=3 + fi + fi + ((installationCount++)) + printlog "$installationCount time(s), exitCode $exitCode" + if [[ $installationCount -lt 3 ]]; then + if [[ $exitCode -gt 0 ]]; then + printlog "Sleep a bit before trying download and install again. $installationCount time(s)." + printlog "Remove $(rm -fv "$tmpDir/$name.pkg" || true)" + sleep 2 + fi + else + printlog "Download and install of $name succes." + fi + done + # Remove the temporary working directory + printlog "Deleting working directory '$tmpDir' and its contents." + printlog "Remove $(rm -Rfv "${tmpDir}" || true)" + # Handle installation errors + if [[ $exitCode != 0 ]]; then + printlog "ERROR. Installation of $name failed. Aborting." + caffexit $exitCode + else + printlog "$name version $appNewVersion installed!" + fi +else + printlog "$name version $appNewVersion already found. Perfect!" +fi + +caffexit 0 diff --git a/MDM/App script.sh b/MDM/App script.sh deleted file mode 100755 index c7b4a10..0000000 --- a/MDM/App script.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/zsh -# Installation using Installomator -what="brave" # enter the software to install - -# To be used as a script sent out from a MDM. -# Fill the variable "what" above with a label. -# Script will run this label. -LOGO="appstore" # or "addigy", "microsoft", "mosyleb", "mosylem" -###################################################################### -# Parameters for reinstall/initial install (owner root:wheel): -# "BLOCKING_PROCESS_ACTION=quit_kill INSTALL=force IGNORE_APP_STORE_APPS=yes SYSTEMOWNER=1" -# Parameters for Self Service installed app: -# "BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=all" -# Parameters for security important apps, like browsers (run automaticaly every day): -# "BLOCKING_PROCESS_ACTION=tell_user_then_kill" -# Update of service apps (run automatically): -# "BLOCKING_PROCESS_ACTION=quit_kill NOTIFY=silent" -parameters="BLOCKING_PROCESS_ACTION=tell_user_then_kill NOTIFY=all" -############################################### - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - exit 99 -fi - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -cmdOutput="$(${destFile} ${what} LOGO=$LOGO $parameters LOGGING=WARN || true)" -# Check result -exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" -if [[ ${exitStatus} -ne 0 ]] ; then - echo -e "Error installing ${what}. Exit code ${exitStatus}" - #echo "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - echo "Error installing ${what}. Exit code $?" - caffexit $? -fi - -echo "[$(DATE)][LOG-END]" - -caffexit 0 - -# notify behavior -# NOTIFY=success -# options: -# - success notify the user on success -# - silent no notifications -# - all all notifications (great for Self Service installation) - - -# behavior when blocking processes are found -# BLOCKING_PROCESS_ACTION=tell_user -# options: -# - ignore continue even when blocking processes are found -# - quit app will be told to quit nicely, if running -# - quit_kill told to quit twice, then it will be killed -# Could be great for service apps, if they do not respawn -# - silent_fail exit script without prompt or installation -# - prompt_user show a user dialog for each blocking process found -# abort after three attempts to quit -# (only if user accepts to quit the apps, otherwise -# the update is cancelled). -# - prompt_user_then_kill -# show a user dialog for each blocking process found, -# attempt to quit two times, kill the process finally -# - prompt_user_loop -# Like prompt-user, but clicking "Not Now", will just wait an hour, -# and then it will ask again. -# WARNING! It might block the MDM agent on the machine, as -# the scripts gets stuct in waiting until the hour has passed, -# possibly blocking for other management actions in this time. -# - tell_user User will be showed a notification about the important update, -# but user is only allowed to quit and continue, and then we -# ask the app to quit. -# - tell_user_then_kill -# Show dialog 2 times, and if the quitting fails, the -# blocking processes will be killed. -# - kill kill process without prompting or giving the user a chance to save - - -# logo-icon used in dialog boxes if app is blocking -# LOGO=appstore -# options: -# - appstore Icon is Apple App Store (default) -# - jamf JAMF Pro -# - mosyleb Mosyle Business -# - mosylem Mosyle Manager (Education) -# - addigy Addigy -# path can also be set in the command call, and if file exists, it will be used. -# Like 'LOGO="/System/Applications/App\ Store.app/Contents/Resources/AppIcon.icns"' -# (spaces have to be escaped). - - -# App Store apps handling -# IGNORE_APP_STORE_APPS=no -# options: -# - no If installed app is from App Store (which include VPP installed apps) -# it will not be touched, no matter it's version (default) -# - yes Replace App Store (and VPP) version of app and handle future -# updates using Installomator, even if latest version. -# Shouldn’t give any problems for the user in most cases. -# Known bad example: Slack will loose all settings. - - -# install behavior -# INSTALL="" -# options: -# - When not set, software will only be installed -# if it is newer/different in version -# - force Install even if it’s the same version - - -# Re-opening of closed app -# REOPEN="yes" -# options: -# - yes App wil be reopened if it was closed -# - no App not reopened - - -######################## -# Often used labels: -######################## - -# firefox -# firefox_intl -# brave -# torbrowser -# googlechrome -# netnewswire - -# adobereaderdc -# textmate - -# cyberduck -# keka -# theunarchiver - -# vlc -# handbrake - -# inkscape - -# signal -# telegram -# whatsapp - -# hazel -# devonthink - -# teamviewerqs -# zoom - -# malwarebytes -# githubdesktop -# sublimetext -# textmate -# visualstudiocode - -# microsoftskypeforbusiness -# microsoftteams -# microsoftyammer -# microsoftedgeenterprisestable -# microsoftedgeconsumerstable -# microsoftsharepointplugin -# microsoftdefenderatp - -# googledrivefilestream - -# cdef -# desktoppr -# supportapp -# xink -# wwdc diff --git a/MDM/App-install with Dialog and dockutil/Addigy condition notes.sh b/MDM/App-install with Dialog and dockutil/Addigy condition notes.sh new file mode 100644 index 0000000..41d5d70 --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/Addigy condition notes.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +# Addigy condition +# These are my notes for how I can extract all the label lines from Installomator.sh, evaluate those, and check if installed version is the latest version. +# This script contains functions from Installomator. +label="googlechromepkg" + +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# Functions from Installomator +downloadURLFromGit() { # $1 git user name, $2 git repo name + gitusername=${1?:"no git user name"} + gitreponame=${2?:"no git repo name"} + + if [[ $type == "pkgInDmg" ]]; then + filetype="dmg" + elif [[ $type == "pkgInZip" ]]; then + filetype="zip" + else + filetype=$type + fi + + if [ -n "$archiveName" ]; then + downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1) + if [[ "$(echo $downloadURL | grep -ioE "https.*$archiveName")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }") + fi + else + downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1) + if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype")" == "" ]]; then + printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }") + fi + fi + if [ -z "$downloadURL" ]; then + cleanupAndExit 14 "could not retrieve download URL for $gitusername/$gitreponame" ERROR + else + echo "$downloadURL" + return 0 + fi +} + +versionFromGit() { + # credit: Søren Theilgaard (@theilgaard) + # $1 git user name, $2 git repo name + gitusername=${1?:"no git user name"} + gitreponame=${2?:"no git repo name"} + + #appNewVersion=$(curl -L --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | grep tag_name | cut -d '"' -f 4 | sed 's/[^0-9\.]//g') + appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g') + if [ -z "$appNewVersion" ]; then + printlog "could not retrieve version number for $gitusername/$gitreponame" WARN + appNewVersion="" + else + echo "$appNewVersion" + return 0 + fi +} + + +# Handling of differences in xpath between Catalina and Big Sur +xpath() { + # the xpath tool changes in Big Sur and now requires the `-e` option + if [[ $(sw_vers -buildVersion) > "20A" ]]; then + /usr/bin/xpath -e $@ + # alternative: switch to xmllint (which is not perl) + #xmllint --xpath $@ - + else + /usr/bin/xpath $@ + fi +} + +# from @Pico: https://macadmins.slack.com/archives/CGXNNJXJ9/p1652222365989229?thread_ts=1651786411.413349&cid=CGXNNJXJ9 +getJSONValue() { + # $1: JSON string OR file path to parse (tested to work with up to 1GB string and 2GB file). + # $2: JSON key path to look up (using dot or bracket notation). + printf '%s' "$1" | /usr/bin/osascript -l 'JavaScript' \ + -e "let json = $.NSString.alloc.initWithDataEncoding($.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile$(/usr/bin/uname -r | /usr/bin/awk -F '.' '($1 > 18) { print "AndReturnError(ObjC.wrap())" }'), $.NSUTF8StringEncoding)" \ + -e 'if ($.NSFileManager.defaultManager.fileExistsAtPath(json)) json = $.NSString.stringWithContentsOfFileEncodingError(json, $.NSUTF8StringEncoding, ObjC.wrap())' \ + -e "const value = JSON.parse(json.js)$([ -n "${2%%[.[]*}" ] && echo '.')$2" \ + -e 'if (typeof value === "object") { JSON.stringify(value, null, 4) } else { value }' +} + +# Mark: Script +labelScript=$(grep -E -m 1 -A 30 "^$label"'(\)|\|\\)$' "/usr/local/Installomator/Installomator.sh" | grep -B 30 -m 1 ";;") +echo $labelScript +eval $labelScript +echo $appNewVersion + + + +############################## +printLines=0; while read line; do; if [[ $printLines -eq 1 || "$(echo $line | grep -oE "^googlechromepkg")" != "" ]]; then; printLines=1; echo $line; fi; done < "/usr/local/Installomator/Installomator.sh" + +printLines=0; while read line; do; if [[ $printLines -eq 1 ]]; then; if [[ "$(echo $line | grep ";;")" == "" ]]; then; echo $line; else; printLines=0; fi ; elif [[ "$(echo $line | grep -oE "^googlechromepkg")" != "" ]]; then; printLines=1; fi; done < "/usr/local/Installomator/Installomator.sh" + +labelLines="$(printLines=0; while read line; do; if [[ $printLines -eq 1 ]]; then; if [[ "$(echo $line | grep ";;")" == "" ]]; then; echo $line; else; return; fi ; elif [[ "$(echo $line | grep -oE "^googlechromepkg")" != "" ]]; then; printLines=1; fi; done < "/usr/local/Installomator/Installomator.sh")"; echo $labelLines + +label="googlechromepkg";labelLines="$(printLines=0; while read line; do; if [[ $printLines -eq 1 ]]; then; if [[ "$(echo $line | grep ";;")" == "" ]]; then; echo $line; else; return; fi ; elif [[ "$(echo $line | grep -oE "^$label")" != "" ]]; then; printLines=1; fi; done < "/usr/local/Installomator/Installomator.sh")"; eval $labelLines ; echo $appNewVersion + + +label="googlechromepkg" +labelLines="$(printLines=0 +while read line; do + if [[ $printLines -eq 1 ]]; then + if [[ "$(echo $label | grep ";;")" == "" ]]; then + echo $line + else + return + fi + elif [[ "$(echo $line | grep -oE "^$label")" != "" ]]; then + printLines=1 + fi +done < "/usr/local/Installomator/Installomator.sh")" +eval $labelLines +echo $appNewVersion + + + + + + diff --git a/MDM/App-install with Dialog and dockutil/App VFA SS github.sh b/MDM/App-install with Dialog and dockutil/App VFA SS github.sh new file mode 100755 index 0000000..7671062 --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/App VFA SS github.sh @@ -0,0 +1,279 @@ +#!/bin/sh + +# Installation using Installomator with Dialog showing progress (and posibility of adding to the Dock) +# Installation of software using `valuesfromarguments` to install a custom software using Installomator through GitHub + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +#item="gfxcardstatus" # enter the software to install (if it has a label in future version of Installomator) + +# Label variables below + +# GitHub functions +downloadURLFromGit() { # $1 git user name, $2 git repo name + gitusername=${1?:"no git user name"} + gitreponame=${2?:"no git repo name"} + + if [[ $type == "pkgInDmg" ]]; then + filetype="dmg" + elif [[ $type == "pkgInZip" ]]; then + filetype="zip" + else + filetype=$type + fi + + if [ -n "$archiveName" ]; then + downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*$archiveName" | head -1 || true) + if [[ "$(echo $downloadURL | grep -ioE "https.*$archiveName" || true)" == "" ]]; then + #printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$archiveName\"/ { print \$4; exit }" || true) + fi + else + downloadURL=https://github.com$(curl -sfL "https://github.com/$gitusername/$gitreponame/releases/latest" | tr '"' "\n" | grep -i "^/.*\/releases\/download\/.*\.$filetype" | head -1 || true) + if [[ "$(echo $downloadURL | grep -ioE "https.*.$filetype" || true)" == "" ]]; then + #printlog "Trying GitHub API for download URL." + downloadURL=$(curl -sfL "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | awk -F '"' "/browser_download_url/ && /$filetype\"/ { print \$4; exit }" || true) + fi + fi + if [ -z "$downloadURL" ]; then + echo "could not retrieve download URL for $gitusername/$gitreponame" + exit 1 + else + echo "$downloadURL" + return 0 + fi +} +versionFromGit() { + # credit: Søren Theilgaard (@theilgaard) + # $1 git user name, $2 git repo name + gitusername=${1?:"no git user name"} + gitreponame=${2?:"no git repo name"} + + #appNewVersion=$(curl -L --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | grep tag_name | cut -d '"' -f 4 | sed 's/[^0-9\.]//g' || true) + appNewVersion=$(curl -sLI "https://github.com/$gitusername/$gitreponame/releases/latest" | grep -i "^location" | tr "/" "\n" | tail -1 | sed 's/[^0-9\.]//g' || true) + if [ -z "$appNewVersion" ]; then + #echo "could not retrieve version number for $gitusername/$gitreponame" + appNewVersion="" + else + echo "$appNewVersion" + return 0 + fi +} + +# Variables for label +name="gfxCardStatus" +type="zip" +downloadURL="$(downloadURLFromGit codykrieger gfxCardStatus)" +appNewVersion="$(versionFromGit codykrieger gfxCardStatus)" +expectedTeamID="LF22FTQC25" + +# Dialog icon +icon="" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPath="/Applications/$name.app" + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : github-functions added. Improved appIcon handling. Can add the app to Dock using dockutil. +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + #itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + itemName="$name" + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1 || true) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile || true) + if [[ "$(echo "$appIcon" | grep -io ".icns")" == "" ]]; then + appIcon="${appIcon}.icns" + fi + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator with valuesfromarguments +cmdOutput="$(${destFile} valuesfromarguments LOGO=$LOGO \ + name=${name} \ + type=${type} \ + downloadURL=\"$downloadURL\" \ + appNewVersion=${appNewVersion} \ + expectedTeamID=${expectedTeamID} \ + ${installomatorOptions} || true)" + +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install with Dialog and dockutil/App VFA SS.sh b/MDM/App-install with Dialog and dockutil/App VFA SS.sh new file mode 100755 index 0000000..a7b84a7 --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/App VFA SS.sh @@ -0,0 +1,227 @@ +#!/bin/sh + +# Installation using Installomator with Dialog showing progress (and posibility of adding to the Dock) +# Installation of software using `valuesfromarguments` to install a custom software using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +#item="" # enter the software to install (if it has a label in future version of Installomator) + +# Variables for label +name="ClickShare" +type="appInDmgInZip" +downloadURL="https://www.barco.com$( curl -fs "https://www.barco.com/en/clickshare/app" | grep -A6 -i "macos" | grep -i "FileNumber" | tr '"' "\n" | grep -i "FileNumber" )" +appNewVersion="$(eval "$( echo $downloadURL | sed -E 's/.*(MajorVersion.*BuildVersion=[0-9]*).*/\1/' | sed 's/&//g' )" ; ((MajorVersion++)) ; ((MajorVersion--)); ((MinorVersion++)) ; ((MinorVersion--)); ((PatchVersion++)) ; ((PatchVersion--)); ((BuildVersion++)) ; ((BuildVersion--)); echo "${MajorVersion}.${MinorVersion}.${PatchVersion}-b${BuildVersion}")" +expectedTeamID="P6CDJZR997" + +# Dialog icon +icon="" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPath="/Applications/$name.app" + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : Improved appIcon handling. Can add the app to Dock using dockutil +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +#destFile="/usr/local/Installomator/Installomator.sh" +destFile="/usr/local/Installomator/Installomator10.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + #itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + itemName="$name" + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1 || true) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile || true) + if [[ "$(echo "$appIcon" | grep -io ".icns")" == "" ]]; then + appIcon="${appIcon}.icns" + fi + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator with valuesfromarguments +cmdOutput="$(${destFile} valuesfromarguments LOGO=$LOGO \ + name=${name} \ + type=${type} \ + downloadURL=\"$downloadURL\" \ + appNewVersion=${appNewVersion} \ + expectedTeamID=${expectedTeamID} \ + ${installomatorOptions} || true)" + +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install with Dialog and dockutil/App browser-security.sh b/MDM/App-install with Dialog and dockutil/App browser-security.sh new file mode 100755 index 0000000..d9eb405 --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/App browser-security.sh @@ -0,0 +1,211 @@ +#!/bin/sh + +# Installation using Installomator with Dialog showing progress (and posibility of adding to the Dock) + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +item="firefoxpkg" # enter the software to install +# Examples: microsoftedge, brave, googlechromepkg, firefoxpkg + +# Dialog icon +icon="https://mosylebusinessweb.blob.core.windows.net/envoit-public/customcommand_icon-envoit_3e37cc23e3fd8d29b1fbe85bc3b3923b323627dc83153cf673.png" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPath="/Applications/Firefox.app" + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=tell_user_then_quit NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : Improved appIcon handling. Can add the app to Dock using dockutil +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1 || true) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile || true) + if [[ "$(echo "$appIcon" | grep -io ".icns")" == "" ]]; then + appIcon="${appIcon}.icns" + fi + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator +cmdOutput="$(${destFile} ${item} LOGO=$LOGO ${installomatorOptions} ${installomatorNotify} || true)" +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install with Dialog and dockutil/App normal SS multi-app.sh b/MDM/App-install with Dialog and dockutil/App normal SS multi-app.sh new file mode 100644 index 0000000..9d3d593 --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/App normal SS multi-app.sh @@ -0,0 +1,214 @@ +#!/bin/sh + +# Installation using Installomator with Dialog showing progress (and posibility of adding to the Dock) + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +item="microsoftoffice365" # enter the software to install +# Examples: microsoftedge, brave, googlechromepkg, firefoxpkg + +# Dialog icon +icon="" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPaths=("/Applications/Microsoft Outlook.app" "/Applications/Microsoft Word.app" "/Applications/Microsoft Excel.app" "/Applications/Microsoft PowerPoint.app" "/Applications/Microsoft OneNote.app") + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : Improved appIcon handling. Can add the app to Dock using dockutil +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1 || true) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile || true) + if [[ "$(echo "$appIcon" | grep -io ".icns")" == "" ]]; then + appIcon="${appIcon}.icns" + fi + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator +cmdOutput="$(${destFile} ${item} LOGO=$LOGO ${installomatorOptions} ${installomatorNotify} || true)" +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + for appPath in "${appPaths[@]}"; do + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" --no-restart || true + done + $dockutil --add "/AppThatDoesNotExistAnywhereOnDiskButMakingDockutilRestartTheDock" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install with Dialog and dockutil/App normal SS.sh b/MDM/App-install with Dialog and dockutil/App normal SS.sh new file mode 100644 index 0000000..7326f4a --- /dev/null +++ b/MDM/App-install with Dialog and dockutil/App normal SS.sh @@ -0,0 +1,211 @@ +#!/bin/sh + +# Installation using Installomator with Dialog showing progress (and posibility of adding to the Dock) + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +item="" # enter the software to install +# Examples: microsoftedge, brave, googlechromepkg, firefoxpkg + +# Dialog icon +icon="" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPath="/Applications/.app" + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : Improved appIcon handling. Can add the app to Dock using dockutil +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1 || true) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile || true) + if [[ "$(echo "$appIcon" | grep -io ".icns")" == "" ]]; then + appIcon="${appIcon}.icns" + fi + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator +cmdOutput="$(${destFile} ${item} LOGO=$LOGO ${installomatorOptions} ${installomatorNotify} || true)" +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App VFA.sh b/MDM/App-install/App VFA.sh new file mode 100755 index 0000000..19240cd --- /dev/null +++ b/MDM/App-install/App VFA.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +# Installation using Installomator +# Installation of software using valuesfromarguments to install a custom software using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +#item="" # enter the software to install (if it has a label in future version of Installomator) + +# Variables for label +name="ClickShare" +type="appInDmgInZip" +downloadURL="https://www.barco.com$( curl -fs "https://www.barco.com/en/clickshare/app" | grep -A6 -i "macos" | grep -i "FileNumber" | tr '"' "\n" | grep -i "FileNumber" )" +appNewVersion="$(eval "$( echo $downloadURL | sed -E 's/.*(MajorVersion.*BuildVersion=[0-9]*).*/\1/' | sed 's/&//g' )" ; ((MajorVersion++)) ; ((MajorVersion--)); ((MinorVersion++)) ; ((MinorVersion--)); ((PatchVersion++)) ; ((PatchVersion--)); ((BuildVersion++)) ; ((BuildVersion--)); echo "${MajorVersion}.${MinorVersion}.${PatchVersion}-b${BuildVersion}")" +expectedTeamID="P6CDJZR997" + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user LOGGING=INFO NOTIFY=all" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "what" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $what" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Install software using Installomator with valuesfromarguments +cmdOutput="$(${destFile} valuesfromarguments LOGO=$LOGO \ + name=${name} \ + type=${type} \ + downloadURL=\"$downloadURL\" \ + appNewVersion=${appNewVersion} \ + expectedTeamID=${expectedTeamID} \ + ${installomatorOptions} || true)" + + +# Check result +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +if [[ ${exitStatus} -eq 0 ]] ; then + echo "${what} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" +else + echo "ERROR installing ${what}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App browser-security Auto-install.sh b/MDM/App-install/App browser-security Auto-install.sh new file mode 100644 index 0000000..dfd0ada --- /dev/null +++ b/MDM/App-install/App browser-security Auto-install.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# Installation using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what="firefoxpkg" # enter the software to install +# Examples: microsoftedge, brave, googlechromepkg, firefoxpkg + +installomatorOptions="BLOCKING_PROCESS_ACTION=tell_user_then_quit" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "what" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $what" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Install software using Installomator +cmdOutput="$(${destFile} ${what} LOGO=$LOGO ${installomatorOptions} || true)" + +# Check result +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +if [[ ${exitStatus} -eq 0 ]] ; then + echo "${what} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" +else + echo "ERROR installing ${what}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App browser-security SS.sh b/MDM/App-install/App browser-security SS.sh new file mode 100644 index 0000000..829ae5a --- /dev/null +++ b/MDM/App-install/App browser-security SS.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# Installation using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what="" # enter the software to install +# Examples: microsoftedge, brave, googlechromepkg, firefoxpkg + +installomatorOptions="BLOCKING_PROCESS_ACTION=tell_user_then_quit NOTIFY=all" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "what" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $what" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Install software using Installomator +cmdOutput="$(${destFile} ${what} LOGO=$LOGO ${installomatorOptions} || true)" + +# Check result +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +if [[ ${exitStatus} -eq 0 ]] ; then + echo "${what} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" +else + echo "ERROR installing ${what}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App normal Auto-install.sh b/MDM/App-install/App normal Auto-install.sh new file mode 100644 index 0000000..aa7d624 --- /dev/null +++ b/MDM/App-install/App normal Auto-install.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# Installation using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what="" # enter the software to install +# Examples: adobecreativeclouddesktop, textmate, vlc + +installomatorOptions="BLOCKING_PROCESS_ACTION=tell_user" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "what" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $what" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Install software using Installomator +cmdOutput="$(${destFile} ${what} LOGO=$LOGO ${installomatorOptions} || true)" + +# Check result +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +if [[ ${exitStatus} -eq 0 ]] ; then + echo "${what} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" +else + echo "ERROR installing ${what}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App normal SS.sh b/MDM/App-install/App normal SS.sh new file mode 100644 index 0000000..98aa7c1 --- /dev/null +++ b/MDM/App-install/App normal SS.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +# Installation using Installomator + +LOGO="mosyleb" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +what="" # enter the software to install +# Examples: adobecreativeclouddesktop, textmate, vlc + +installomatorOptions="BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=all" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "what" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $what" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Install software using Installomator +cmdOutput="$(${destFile} ${what} LOGO=$LOGO ${installomatorOptions} || true)" + +# Check result +exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" +if [[ ${exitStatus} -eq 0 ]] ; then + echo "${what} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" +else + echo "ERROR installing ${what}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-install/App service Auto-install.sh b/MDM/App-install/App service Auto-install.sh new file mode 100644 index 0000000..8e0509a --- /dev/null +++ b/MDM/App-install/App service Auto-install.sh @@ -0,0 +1,208 @@ +#!/bin/sh + +# Installation using Installomator + +LOGO="addigy" # "mosyleb", "mosylem", "addigy", "microsoft", "ws1" + +item="xink" # enter the software to install +# Examples: desktoppr, dockutil, supportapp, applenyfonts, applesfpro, applesfmono, applesfcompact, nomad, nudge, shield, xink + +# Dialog icon +icon="" +# icon should be a file system path or an URL to an online PNG. +# In Mosyle an URL can be found by copy picture address from a Custom Command icon. + +# dockutil variables +addToDock="1" # with dockutil after installation (0 if not) +appPath="/Applications/Xink.app" + +# Other variables +dialog_command_file="/var/tmp/dialog.log" +dialogApp="/Library/Application Support/Dialog/Dialog.app" +dockutil="/usr/local/bin/dockutil" + +installomatorOptions="BLOCKING_PROCESS_ACTION=ignore NOTIFY=silent DIALOG_CMD_FILE=${dialog_command_file}" # Separated by space + +# Other installomatorOptions: +# LOGGING=REQ +# LOGGING=DEBUG +# LOGGING=WARN +# BLOCKING_PROCESS_ACTION=ignore +# BLOCKING_PROCESS_ACTION=tell_user +# BLOCKING_PROCESS_ACTION=tell_user_then_quit +# BLOCKING_PROCESS_ACTION=prompt_user +# BLOCKING_PROCESS_ACTION=prompt_user_loop +# BLOCKING_PROCESS_ACTION=prompt_user_then_kill +# BLOCKING_PROCESS_ACTION=quit +# BLOCKING_PROCESS_ACTION=kill +# NOTIFY=all +# NOTIFY=success +# NOTIFY=silent +# IGNORE_APP_STORE_APPS=yes +# INSTALL=force +###################################################################### +# To be used as a script sent out from a MDM. +# Fill the variable "item" above with a label. +# Script will run this label through Installomator. +###################################################################### +# v. 10.1 : Can add the app to Dock using dockutil +# v. 10 : Integration with Dialog and Installomator v. 10 +# v. 9.3 : Better logging handling and installomatorOptions fix. +###################################################################### + +# Mark: Script +# PATH declaration +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +echo "$(date +%F\ %T) [LOG-BEGIN] $item" + +dialogUpdate() { + # $1: dialog command + local dcommand="$1" + + if [[ -n $dialog_command_file ]]; then + echo "$dcommand" >> "$dialog_command_file" + echo "Dialog: $dcommand" + fi +} +checkCmdOutput () { + # $1: cmdOutput + local cmdOutput="$1" + exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" + if [[ ${exitStatus} -eq 0 ]] ; then + echo "${item} succesfully installed." + warnOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "warn" || true )" + echo "$warnOutput" + else + echo "ERROR installing ${item}. Exit code ${exitStatus}" + echo "$cmdOutput" + #errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" + #echo "$errorOutput" + fi +} + +# Check the currently logged in user +currentUser=$(stat -f "%Su" /dev/console) +if [ -z "$currentUser" ] || [ "$currentUser" = "loginwindow" ] || [ "$currentUser" = "_mbsetupuser" ] || [ "$currentUser" = "root" ]; then + echo "ERROR. Logged in user is $currentUser! Cannot proceed." + exit 97 +fi +# Get the current user's UID for dockutil +uid=$(id -u "$currentUser") +# Find the home folder of the user +userHome="$(dscl . -read /users/${currentUser} NFSHomeDirectory | awk '{print $2}')" + +# Verify that Installomator has been installed +destFile="/usr/local/Installomator/Installomator.sh" +if [ ! -e "${destFile}" ]; then + echo "Installomator not found here:" + echo "${destFile}" + echo "Exiting." + exit 99 +fi + +# No sleeping +/usr/bin/caffeinate -d -i -m -u & +caffeinatepid=$! +caffexit () { + kill "$caffeinatepid" + pkill caffeinate + exit $1 +} + +# Mark: Installation begins +installomatorVersion="$(${destFile} version | cut -d "." -f1 || true)" + +if [[ $installomatorVersion -lt 10 ]] || [[ $(sw_vers -buildVersion) < "20A" ]]; then + echo "Installomator should be at least version 10 to support Dialog. Installed version $installomatorVersion." + echo "And macOS 11 Big Sur (build 20A) is required for Dialog. Installed build $(sw_vers -buildVersion)." + installomatorNotify="NOTIFY=all" +else + installomatorNotify="" + # check for Swift Dialog + if [[ ! -d $dialogApp ]]; then + echo "Cannot find dialog at $dialogApp" + # Install using Installlomator + cmdOutput="$(${destFile} dialog LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + + # Configure and display swiftDialog + itemName=$( ${destFile} ${item} RETURN_LABEL_NAME=1 LOGGING=REQ INSTALL=force | tail -1 || true ) + if [[ "$itemName" != "#" ]]; then + message="Installing ${itemName}…" + else + message="Installing ${item}…" + fi + echo "$item $itemName" + + # If no icon defined we are trying to search for installed app icon + if [[ "$icon" == "" ]]; then + appPath=$(mdfind "kind:application AND name:$itemName" | head -1) + appIcon=$(defaults read "${appPath}/Contents/Info.plist" CFBundleIconFile) + icon="${appPath}/Contents/Resources/${appIcon}" + echo "${icon}" + if [ ! -f "${icon}" ]; then + icon="/System/Applications/App Store.app/Contents/Resources/AppIcon.icns" + fi + fi + echo "${icon}" + + # display first screen + open -a "$dialogApp" --args \ + --title none \ + --icon "$icon" \ + --message "$message" \ + --mini \ + --progress 100 \ + --position bottomright \ + --movable \ + --commandfile "$dialog_command_file" + + # give everything a moment to catch up + sleep 0.1 +fi + +# Install software using Installomator +cmdOutput="$(${destFile} ${item} LOGO=$LOGO ${installomatorOptions} ${installomatorNotify} || true)" +checkCmdOutput $cmdOutput + +# Mark: dockutil stuff +if [[ $addToDock -eq 1 ]]; then + dialogUpdate "progresstext: Adding to Dock" + if [[ ! -d $dockutil ]]; then + echo "Cannot find dockutil at $dockutil, trying installation" + # Install using Installlomator + cmdOutput="$(${destFile} dockutil LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore LOGGING=REQ NOTIFY=silent || true)" + checkCmdOutput $cmdOutput + fi + echo "Adding to Dock" + $dockutil --add "${appPath}" "${userHome}/Library/Preferences/com.apple.dock.plist" || true + sleep 1 +else + echo "Not adding to Dock." +fi + +# Mark: Ending +if [[ $installomatorVersion -lt 10 ]]; then + echo "Again skipping Dialog stuff." +else + # close and quit dialog + dialogUpdate "progress: complete" + dialogUpdate "progresstext: Done" + + # pause a moment + sleep 0.5 + + dialogUpdate "quit:" + + # let everything catch up + sleep 0.5 + + # just to be safe + #killall "Dialog" 2>/dev/null || true +fi + +echo "[$(DATE)][LOG-END]" + +caffexit $exitStatus diff --git a/MDM/App-loop script.sh b/MDM/App-loop script.sh deleted file mode 100755 index 8fb33e7..0000000 --- a/MDM/App-loop script.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/bin/zsh -# Installation using Installomator -whatList="microsoftteams microsoftyammer firefox bravebrowser cyberduck vlc signal" # enter the software to install separated with spaces - -# To be used as a script sent out from a MDM. -# Fill the variable "whatList" above with labels separated by space " ". -# Script will loop through these labels. -LOGO="appstore" # or "addigy", "microsoft", "mosyleb", "mosylem" -###################################################################### -# Parameters for reinstall/initial install (owner root:wheel): -# "BLOCKING_PROCESS_ACTION=quit_kill INSTALL=force IGNORE_APP_STORE_APPS=yes SYSTEMOWNER=1" -# Parameters for Self Service installed app: -# "BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=all" -# Parameters for security important apps, like browsers (run automaticaly every day): -# "BLOCKING_PROCESS_ACTION=tell_user_then_kill" -# Update of service apps (run automatically): -# "BLOCKING_PROCESS_ACTION=quit_kill NOTIFY=silent" -parameters="BLOCKING_PROCESS_ACTION=tell_user NOTIFY=all" -###################################################################### - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - exit 99 -fi - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -# Count errors -errorCount=0 - -for what in $whatList; do - #echo $what - # Install software using Installomator - cmdOutput="$(${destFile} ${what} LOGO=$LOGO $parameters LOGGING=WARN || true)" - # Check result - exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" - if [[ ${exitStatus} -ne 0 ]] ; then - echo -e "Error installing ${what}. Exit code ${exitStatus}" - #echo "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - let errorCount++ - fi -done - -echo -echo "Errors: $errorCount" -echo "[$(DATE)][LOG-END]" - -caffexit $errorCount - -# notify behavior -# NOTIFY=success -# options: -# - success notify the user on success -# - silent no notifications -# - all all notifications (great for Self Service installation) - - -# behavior when blocking processes are found -# BLOCKING_PROCESS_ACTION=tell_user -# options: -# - ignore continue even when blocking processes are found -# - quit app will be told to quit nicely, if running -# - quit_kill told to quit twice, then it will be killed -# Could be great for service apps, if they do not respawn -# - silent_fail exit script without prompt or installation -# - prompt_user show a user dialog for each blocking process found -# abort after three attempts to quit -# (only if user accepts to quit the apps, otherwise -# the update is cancelled). -# - prompt_user_then_kill -# show a user dialog for each blocking process found, -# attempt to quit two times, kill the process finally -# - prompt_user_loop -# Like prompt-user, but clicking "Not Now", will just wait an hour, -# and then it will ask again. -# WARNING! It might block the MDM agent on the machine, as -# the scripts gets stuct in waiting until the hour has passed, -# possibly blocking for other management actions in this time. -# - tell_user User will be showed a notification about the important update, -# but user is only allowed to quit and continue, and then we -# ask the app to quit. -# - tell_user_then_kill -# Show dialog 2 times, and if the quitting fails, the -# blocking processes will be killed. -# - kill kill process without prompting or giving the user a chance to save - - -# logo-icon used in dialog boxes if app is blocking -# LOGO=appstore -# options: -# - appstore Icon is Apple App Store (default) -# - jamf JAMF Pro -# - mosyleb Mosyle Business -# - mosylem Mosyle Manager (Education) -# - addigy Addigy -# path can also be set in the command call, and if file exists, it will be used. -# Like 'LOGO="/System/Applications/App\ Store.app/Contents/Resources/AppIcon.icns"' -# (spaces have to be escaped). - - -# App Store apps handling -# IGNORE_APP_STORE_APPS=no -# options: -# - no If installed app is from App Store (which include VPP installed apps) -# it will not be touched, no matter it's version (default) -# - yes Replace App Store (and VPP) version of app and handle future -# updates using Installomator, even if latest version. -# Shouldn’t give any problems for the user in most cases. -# Known bad example: Slack will loose all settings. - - -# install behavior -# INSTALL="" -# options: -# - When not set, software will only be installed -# if it is newer/different in version -# - force Install even if it’s the same version - - -# Re-opening of closed app -# REOPEN="yes" -# options: -# - yes App wil be reopened if it was closed -# - no App not reopened - - -######################## -# Often used labels: -######################## - -# firefox -# firefox_intl -# brave -# torbrowser -# googlechrome -# netnewswire - -# adobereaderdc -# textmate - -# cyberduck -# keka -# theunarchiver - -# vlc -# handbrake - -# inkscape - -# signal -# telegram -# whatsapp - -# hazel -# devonthink - -# teamviewerqs -# zoom - -# malwarebytes -# githubdesktop -# sublimetext -# textmate -# visualstudiocode - -# microsoftskypeforbusiness -# microsoftteams -# microsoftyammer -# microsoftedgeenterprisestable -# microsoftedgeconsumerstable -# microsoftsharepointplugin -# microsoftdefenderatp - -# googledrivefilestream - -# cdef -# desktoppr -# supportapp -# xink -# wwdc diff --git a/MDM/InstallInstallomator.sh b/MDM/InstallInstallomator.sh deleted file mode 100644 index 9bb131f..0000000 --- a/MDM/InstallInstallomator.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -# This script is meant to povide the simplest MDM/management platform agnostic way to install Installomator -# The only requirement is an Internet connection - -export PATH=/usr/bin:/bin:/usr/sbin:/sbin - -# Get the URL of the latest PKG From the Installomator GitHub repo -url=$(curl --silent --fail "https://api.github.com/repos/Installomator/Installomator/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }") -# Expected Team ID of the downloaded PKG -expectedTeamID="JME5BW3F3R" -exitCode=0 - -# Check for Installomator and install if not found -if [ ! -e "/usr/local/Installomator/Installomator.sh" ]; then - echo "Installomator not found. Installing." - # Create temporary working directory - tempDirectory=$( mktemp -d ) - echo "Created working directory '$tempDirectory'" - # Download the installer package - echo "Downloading Installomator package" - curl --location --silent "$url" -o "$tempDirectory/Installomator.pkg" - # Verify the download - teamID=$(spctl -a -vv -t install "$tempDirectory/Installomator.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()') - echo "Team ID for downloaded package: $teamID" - # Install the package if Team ID validates - if [ "$expectedTeamID" = "$teamID" ] || [ "$expectedTeamID" = "" ]; then - echo "Package verified. Installing package Installomator.pkg" - installer -pkg "$tempDirectory/Installomator.pkg" -target / -verbose - exitCode=$? - else - echo "Package verification failed before package installation could start. Download link may be invalid. Aborting." - exitCode=1 - exit $exitCode - fi - # Remove the temporary working directory when done - echo "Deleting working directory '$tempDirectory' and its contents" - rm -Rf "$tempDirectory" -else - echo "Installomator already installed." -fi - -exit $exitCode diff --git a/MDM/Installomator update.sh b/MDM/Installomator update.sh deleted file mode 100755 index 5b6bb67..0000000 --- a/MDM/Installomator update.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# Updating Installomator -# Usefull to push out after deployment if earlier version was deployed in DEP profile - -what="installomator" # enter the software to install -LOGO="appstore" # or "addigy", "microsoft", "mosyleb", "mosylem" - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - exit 99 -fi - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -# Install software using Installomator -cmdOutput="$(${destFile} ${what} LOGO=$LOGO BLOCKING_PROCESS_ACTION=ignore NOTIFY=silent LOGGING=req || true)" - -# Check result -exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" -if [[ ${exitStatus} -eq 0 ]] ; then - echo -e "${what} succesfully installed.\n" -else - echo -e "Error installing ${what}. Exit code ${exitStatus}\n" - #echo "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - caffexit $exitStatus -fi - -echo "[$(DATE)][LOG-END]" -caffexit 0 diff --git a/MDM/MDMAddigy CustomSoftware.sh b/MDM/MDMAddigy CustomSoftware.sh deleted file mode 100755 index e7918fd..0000000 --- a/MDM/MDMAddigy CustomSoftware.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/zsh - -# Specific settings in Addigy to configure Custom Software for installomator. -# Addigy has 3 parts to fill out for this, Installation script, Condition, and Removal steps (see RemoveInstallomator.sh). - -# Mark: Installation script -# Just click “Add” to autogenerate the installer script line by clicking the “Add”-button next to the Installer PKG, replace with first line below -/usr/sbin/installer -pkg "/Library/Addigy/ansible/packages/Installomator (9.1.0)/Installomator-9.1.pkg" -target / - -# Installation using Installomator -whatList="supportapp xink textmate microsoftedge wwdc keka vlc " # enter the software to installed separated with spaces - -# To be used as a script sent out from a MDM. -# Fill the variable "whatList" above with labels separated by space " ". -# Script will loop through these labels and exit with number of errors. -###################################################################### -# Parameters for reinstall/initial install (owner root:wheel): -# "BLOCKING_PROCESS_ACTION=quit_kill INSTALL=force IGNORE_APP_STORE_APPS=yes SYSTEMOWNER=1" -# Parameters for Self Service installed app: -# "BLOCKING_PROCESS_ACTION=prompt_user NOTIFY=all" -# Parameters for security important apps, like browsers (run automaticaly every day): -# "BLOCKING_PROCESS_ACTION=tell_user_then_kill" -# Update of service apps (run automatically): -# "BLOCKING_PROCESS_ACTION=quit_kill NOTIFY=silent" -parameters="BLOCKING_PROCESS_ACTION=quit_kill INSTALL=force IGNORE_APP_STORE_APPS=yes" -###################################################################### - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - exit 99 -fi - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -# Count errors -errorCount=0 - -for what in $whatList; do - #echo $what - # Install software using Installomator - cmdOutput="$(${destFile} ${what} LOGO=addigy $parameters || true)" - # Check result - exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" - if [[ ${exitStatus} -ne 0 ]] ; then - echo -e "Error installing ${what}. Exit code ${exitStatus}" - #echo "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - let errorCount++ - fi -done - -echo -echo "Errors: $errorCount" -echo "[$(DATE)][LOG-END]" - -caffexit $errorCount - -# Mark: Conditions -# Install on success -# Remember to fill out the correct “TARGET_VERSION” and “PKG_ID”, and click "Install on succes". -PKG_ID="com.scriptingosx.Installomator" -TARGET_VERSION="9.1" - -vercomp () { - if [[ $1 == $2 ]]; then - return 0 - fi - local IFS=. - local i ver1=($1) ver2=($2) - # fill empty fields in ver1 with zeros - for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do - ver1[i]=0 - done - for ((i=0; i<${#ver1[@]}; i++)); do - if [[ -z ${ver2[i]} ]]; then - # fill empty fields in ver2 with zeros - ver2[i]=0 - fi - if ((10#${ver1[i]} > 10#${ver2[i]})); then - return 1 - fi - if ((10#${ver1[i]} < 10#${ver2[i]})); then - return 2 - fi - done - return 0 -} - -INSTALLED_VERSION="$(pkgutil --pkg-info $PKG_ID | grep -i "^version" | awk '{print $2}')" - -echo "Current Version: ${INSTALLED_VERSION}" - -vercomp ${TARGET_VERSION} ${INSTALLED_VERSION} -COMP=$? # 0 means the same, 1 means TARGET is newer, 2 means INSTALLED is newer -echo "COMPARISON: ${COMP}" - -if [ "${COMP}" -eq 1 ]; then - echo "Installed version is older than ${TARGET_VERSION}." - exit 0 -else - echo "Installed version is the same or newer than ${TARGET_VERSION}." - exit 1 -fi diff --git a/MDM/MDMMosyle install.sh b/MDM/MDMMosyle install.sh deleted file mode 100644 index 27f9d8d..0000000 --- a/MDM/MDMMosyle install.sh +++ /dev/null @@ -1,79 +0,0 @@ -PKG_ID="com.scriptingosx.Installomator" -TARGET_VERSION="9.1" -URLDOWNLOAD="%MosyleCDNFile:blah-blah-blah%" -###################################################################### -# Installation using Installomator (enter the software to install separated with spaces in the "whatList"-variable) -whatList="handbrake theunarchiver microsoftoffice365" -# Covered by Mosyle Catalog: "brave firefox googlechrome microsoftedge microsoftteams signal sublimetext vlc webex zoom" among others -LOGO="mosyleb" # or "mosylem" -###################################################################### - -## Mark: Code here - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -# Mark: Condition for Installomator installation - -INSTALLED_VERSION="$(pkgutil --pkg-info $PKG_ID 2>/dev/null | grep -i "^version" | awk '{print $2}')" - -echo "Current Version: ${INSTALLED_VERSION}" - -if [[ "$TARGET_VERSION" != "$INSTALLED_VERSION" ]]; then - TMPDIR=$(mktemp -d ) - if ! cd "$TMPDIR"; then - echo "error changing directory $TMPDIR" - caffexit 98 - fi - NAME=$TMPDIR/$(date +%s).pkg - if ! curl -fsL "$URLDOWNLOAD" -o "$NAME"; then - echo "error downloading $URLDOWNLOAD to $NAME." - caffexit 97 - fi - installer -pkg "$NAME" -target / - rm -rf "$TMPDIR" -else - echo "Installomator version $INSTALLED_VERSION already installed!" -fi - - -# Mark: Start Installomator label(s) installation - -# Count errors -errorCount=0 - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - caffexit 99 -fi - -for what in $whatList; do - #echo $item - # Install software using Installomator - cmdOutput="$(${destFile} ${what} LOGO=$LOGO NOTIFY=all BLOCKING_PROCESS_ACTION=tell_user || true)" # NOTIFY=silent BLOCKING_PROCESS_ACTION=quit_kill INSTALL=force - # Check result - exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" - if [[ ${exitStatus} -ne 0 ]] ; then - echo "Error installing ${what}. Exit code ${exitStatus}" - #echo "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - let errorCount++ - fi -done - -echo -echo "Errors: $errorCount" -echo "[$(DATE)][LOG-END]" - -caffexit $errorCount diff --git a/MDM/Manual valuesfromarguments.sh b/MDM/Manual valuesfromarguments.sh deleted file mode 100755 index ee80291..0000000 --- a/MDM/Manual valuesfromarguments.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# Software - -# Installation using Installomator -# Example of installing software using valuesfromarguments to install a custom software - -LOGO="appstore" # or "addigy", "microsoft", "mosyleb", "mosylem" -############################################### - -# Verify that Installomator has been installed -destFile="/usr/local/Installomator/Installomator.sh" -if [ ! -e "${destFile}" ]; then - echo "Installomator not found here:" - echo "${destFile}" - echo "Exiting." - exit 99 -fi - -# No sleeping -/usr/bin/caffeinate -d -i -m -u & -caffeinatepid=$! -caffexit () { - kill "$caffeinatepid" - pkill caffeinate - exit $1 -} - -# Variables to calculate -downloadURL="https://craft-assets.invisionapp.com/CraftManager/production/CraftManager.zip" -appNewVersion=$(curl -fs https://craft-assets.invisionapp.com/CraftManager/production/appcast.xml | xpath -e '//rss/channel/item[1]/enclosure/@sparkle:shortVersionString' 2>/dev/null | cut -d '"' -f2) - -# Install software using Installomator -cmdOutput="$(${destFile} valuesfromarguments LOGO=$LOGO \ - name=CraftManager \ - type=zip \ - downloadURL=$downloadURL \ - appNewVersion=$appNewVersion \ - expectedTeamID=VRXQSNCL5W \ - BLOCKING_PROCESS_ACTION=prompt_user \ - LOGGING=REQ \ - NOTIFY=all || true)" - -# Check result -exitStatus="$( echo "${cmdOutput}" | grep --binary-files=text -i "exit" | tail -1 | sed -E 's/.*exit code ([0-9]).*/\1/g' || true )" -if [[ ${exitStatus} -eq 0 ]] ; then - echo -e "${what} succesfully installed.\n" -else - echo -e "Error installing ${what}. Exit code ${exitStatus}\n" - #printlog "$cmdOutput" - errorOutput="$( echo "${cmdOutput}" | grep --binary-files=text -i "error" || true )" - echo "$errorOutput" - caffexit $exitStatus -fi - -echo "[$(DATE)][LOG-END]" -caffexit 0 diff --git a/MDM/RemoveInstallomator.sh b/MDM/Remove Installomator.sh similarity index 100% rename from MDM/RemoveInstallomator.sh rename to MDM/Remove Installomator.sh