This commit is contained in:
Søren Theilgaard
2022-01-12 21:34:16 +01:00
parent c0ce59a1ec
commit 99b908f646
2 changed files with 90 additions and 39 deletions

View File

@@ -1,23 +1,24 @@
# MARK: Functions # MARK: Functions
cleanupAndExit() { # $1 = exit code, $2 message cleanupAndExit() { # $1 = exit code, $2 message, $3 level
if [[ -n $2 && $1 -ne 0 ]]; then
printlog "ERROR: $2"
fi
if [ "$DEBUG" -ne 1 ]; then if [ "$DEBUG" -ne 1 ]; then
# remove the temporary working directory when done # remove the temporary working directory when done
printlog "Deleting $tmpDir" printlog "Deleting $tmpDir" DEBUG
rm -Rf "$tmpDir" rm -Rf "$tmpDir"
fi fi
if [ -n "$dmgmount" ]; then if [ -n "$dmgmount" ]; then
# unmount disk image # unmount disk image
printlog "Unmounting $dmgmount" printlog "Unmounting $dmgmount" DEBUG
hdiutil detach "$dmgmount" hdiutil detach "$dmgmount"
fi fi
# If we closed any processes, reopen the app again # If we closed any processes, reopen the app again
reopenClosedProcess reopenClosedProcess
printlog "################## End Installomator, exit code $1 \n\n" if [[ -n $2 && $1 -ne 0 ]]; then
printlog "ERROR: $2" $3
fi
printlog "################## End Installomator, exit code $1 \n\n" REQ
# if label is wrong and we wanted name of the label, then return ################## # if label is wrong and we wanted name of the label, then return ##################
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
echo "#" echo "#"
@@ -294,7 +295,7 @@ getAppVersion() {
checkRunningProcesses() { checkRunningProcesses() {
# don't check in DEBUG mode 1 # don't check in DEBUG mode 1
if [[ $DEBUG -eq 1 ]]; then if [[ $DEBUG -eq 1 ]]; then
printlog "DEBUG mode 1, not checking for blocking processes" printlog "DEBUG mode 1, not checking for blocking processes" DEBUG
return return
fi fi
@@ -386,7 +387,7 @@ checkRunningProcesses() {
cleanupAndExit 11 "could not quit all processes, aborting..." cleanupAndExit 11 "could not quit all processes, aborting..."
fi fi
printlog "no more blocking processes, continue with update" printlog "no more blocking processes, continue with update" REQ
} }
reopenClosedProcess() { reopenClosedProcess() {
@@ -401,7 +402,7 @@ reopenClosedProcess() {
# don't reopen in DEBUG mode 1 # don't reopen in DEBUG mode 1
if [[ $DEBUG -eq 1 ]]; then if [[ $DEBUG -eq 1 ]]; then
printlog "DEBUG mode 1, not reopening anything" printlog "DEBUG mode 1, not reopening anything" DEBUG
return return
fi fi
@@ -428,15 +429,21 @@ installAppWithPath() { # $1: path to app to install in $targetDir
fi fi
# verify with spctl # verify with spctl
printlog "Verifying: $appPath" printlog "Verifying: $appPath" INFO
if ! teamID=$(spctl -a -vv "$appPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' ); then appVerify=$(spctl -a -vv "$appPath" 2>&1 )
cleanupAndExit 4 "Error verifying $appPath" appVerifyStatus=$(echo $?)
teamID=$(echo $appVerify | awk '/origin=/ {print $NF }' | tr -d '()' )
deduplicatelogs "$appVerify"
printlog "Debugging enabled, App Verification output was: $logoutput" DEBUG
if [[ $appVerifyStatus -ne 0 ]] ; then
#if ! teamID=$(spctl -a -vv "$appPath" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()' ); then
cleanupAndExit 4 "Error verifying $appPath error: $logoutput" ERROR
fi fi
printlog "Team ID matching: $teamID (expected: $expectedTeamID )" INFO
printlog "Team ID matching: $teamID (expected: $expectedTeamID )"
if [ "$expectedTeamID" != "$teamID" ]; then if [ "$expectedTeamID" != "$teamID" ]; then
cleanupAndExit 5 "Team IDs do not match" cleanupAndExit 5 "Team IDs do not match" ERROR
fi fi
# app versioncheck # app versioncheck
@@ -474,13 +481,13 @@ installAppWithPath() { # $1: path to app to install in $targetDir
# skip install for DEBUG 1 # skip install for DEBUG 1
if [ "$DEBUG" -eq 1 ]; then if [ "$DEBUG" -eq 1 ]; then
printlog "DEBUG mode 1 enabled, skipping remove, copy and chown steps" printlog "DEBUG mode 1 enabled, skipping remove, copy and chown steps" DEBUG
return 0 return 0
fi fi
# skip install for DEBUG 2 # skip install for DEBUG 2
if [ "$DEBUG" -eq 2 ]; then if [ "$DEBUG" -eq 2 ]; then
printlog "DEBUG mode 2 enabled, exiting" printlog "DEBUG mode 2 enabled, exiting" DEBUG
cleanupAndExit 0 cleanupAndExit 0
fi fi
@@ -551,24 +558,26 @@ installFromPKG() {
# verify with spctl # verify with spctl
printlog "Verifying: $archiveName" printlog "Verifying: $archiveName"
if ! spctlout=$(spctl -a -vv -t install "$archiveName" 2>&1 ); then spctlOut=$(spctl -a -vv -t install "$archiveName" 2>&1 )
printlog "Error verifying $archiveName" spctlStatus=$(echo $?)
cleanupAndExit 4 printlog "spctlOut is $spctlOut" DEBUG
teamID=$(echo $spctlOut | awk -F '(' '/origin=/ {print $2 }' | tr -d '()' )
deduplicatelogs "$spctlOut" # Why this?
if [[ $spctlStatus -ne 0 ]] ; then
#if ! spctlout=$(spctl -a -vv -t install "$archiveName" 2>&1 ); then
cleanupAndExit 4 "Error verifying $archiveName error: $logoutput" ERROR
fi fi
teamID=$(echo $spctlout | awk -F '(' '/origin=/ {print $2 }' | tr -d '()' )
# Apple signed software has no teamID, grab entire origin instead # Apple signed software has no teamID, grab entire origin instead
if [[ -z $teamID ]]; then if [[ -z $teamID ]]; then
teamID=$(echo $spctlout | awk -F '=' '/origin=/ {print $NF }') teamID=$(echo $spctlout | awk -F '=' '/origin=/ {print $NF }')
fi fi
printlog "Team ID: $teamID (expected: $expectedTeamID )" printlog "Team ID: $teamID (expected: $expectedTeamID )"
if [ "$expectedTeamID" != "$teamID" ]; then if [ "$expectedTeamID" != "$teamID" ]; then
printlog "Team IDs do not match!" cleanupAndExit 5 "Team IDs do not match!" ERROR
cleanupAndExit 5
fi fi
# Check version of pkg to be installed if packageID is set # Check version of pkg to be installed if packageID is set
@@ -597,22 +606,39 @@ installFromPKG() {
# skip install for DEBUG 1 # skip install for DEBUG 1
if [ "$DEBUG" -eq 1 ]; then if [ "$DEBUG" -eq 1 ]; then
printlog "DEBUG enabled, skipping installation" printlog "DEBUG enabled, skipping installation" DEBUG
return 0 return 0
fi fi
# skip install for DEBUG 2 # skip install for DEBUG 2
if [ "$DEBUG" -eq 2 ]; then if [ "$DEBUG" -eq 2 ]; then
printlog "DEBUG mode 2 enabled, exiting" cleanupAndExit 0 "DEBUG mode 2 enabled, exiting" DEBUG
cleanupAndExit 0
fi fi
# install pkg # install pkg
printlog "Installing $archiveName to $targetDir" printlog "Installing $archiveName to $targetDir"
if ! installer -pkg "$archiveName" -tgt "$targetDir" ; then pkgInstall=$(installer -verbose -dumplog -pkg "$archiveName" -tgt "$targetDir" 2>&1)
printlog "error installing $archiveName" pkgInstallStatus=$(echo $?)
cleanupAndExit 9 sleep 1
pkgEndTime=$(date "+$LogDateFormat")
pkgInstall+=$(echo "Output of /var/log/install.log below this line.\n")
pkgInstall+=$(echo "----------------------------------------------------------\n")
pkgInstall+=$(awk -v "b=$starttime" -v "e=$pkgEndTime" -F ',' '$1 >= b && $1 <= e' /var/log/install.log)
deduplicatelogs "$pkgInstall"
if [[ $pkgInstallStatus -ne 0 ]] && [[ $logoutput == *"requires Rosetta 2"* ]] && [[ $rosetta2 == no ]]; then
printlog "Package requires Rosetta 2, Installing Rosetta 2 and Installing Package" INFO
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
rosetta2=yes
installFromPKG
fi fi
if [ $pkginstallstatus -ne 0 ] ; then
#if ! installer -pkg "$archiveName" -tgt "$targetDir" ; then
cleanupAndExit 9 "Error installing $archiveName error: $logoutput" ERROR
fi
printlog "Debugging enabled, installer output was: $logoutput" DEBUG
} }
installFromZIP() { installFromZIP() {
@@ -738,12 +764,29 @@ runUpdateTool() {
if [[ -x $updateTool ]]; then if [[ -x $updateTool ]]; then
printlog "running $updateTool $updateToolArguments" printlog "running $updateTool $updateToolArguments"
if [[ -n $updateToolRunAsCurrentUser ]]; then if [[ -n $updateToolRunAsCurrentUser ]]; then
runAsUser $updateTool ${updateToolArguments} updateOutput=$(runAsUser $updateTool ${updateToolArguments} 2>&1)
updateStatus=$(echo $?)
else else
$updateTool ${updateToolArguments} updateOutput=$($updateTool ${updateToolArguments} 2>&1)
updateStatus=$(echo $?)
fi fi
if [[ $? -ne 0 ]]; then sleep 1
cleanupAndExit 15 "Error running $updateTool" updateEndTime=$(date "+$updateToolLogDateFormat")
deduplicatelogs $updateOutput
if [[ -n $updateToolLog ]]; then
updateOutput+=$(echo "Output of Installer log of $updateToolLog below this line.\n")
updateOutput+=$(echo "----------------------------------------------------------\n")
updateOutput+=$(awk -v "b=$updatestarttime" -v "e=$updateEndTime" -F ',' '$1 >= b && $1 <= e' $updateToolLog)
fi
if [[ $updateStatus -ne 0 ]]; then
printlog "Error running $updateTool, Procceding with normal installation. Exit Status: $updateStatus Error: $logoutput" WARN
return 1
if [[ $type == updateronly ]]; then
cleanupAndExit 77 "No Download URL Set, this is an update only application and the updater failed" WARN
fi
elif [[ $updateStatus -eq 0 ]]; then
printlog "Debugging enabled, update tool output was: $logoutput" DEBUG
fi fi
else else
printlog "couldn't find $updateTool, continuing normally" printlog "couldn't find $updateTool, continuing normally"

View File

@@ -35,14 +35,17 @@ case $LOGO in
mosyleb) mosyleb)
# Mosyle Business # Mosyle Business
LOGO="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns" LOGO="/Applications/Self-Service.app/Contents/Resources/AppIcon.icns"
if [[ -z $MDMProfileName ]]; then; MDMProfileName="Mosyle Corporation MDM"; fi
;; ;;
mosylem) mosylem)
# Mosyle Manager (education) # Mosyle Manager (education)
LOGO="/Applications/Manager.app/Contents/Resources/AppIcon.icns" LOGO="/Applications/Manager.app/Contents/Resources/AppIcon.icns"
if [[ -z $MDMProfileName ]]; then; MDMProfileName="Mosyle Corporation MDM"; fi
;; ;;
addigy) addigy)
# Addigy # Addigy
LOGO="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns" LOGO="/Library/Addigy/macmanage/MacManage.app/Contents/Resources/atom.icns"
if [[ -z $MDMProfileName ]]; then; MDMProfileName="MDM Profile"; fi
;; ;;
esac esac
if [[ ! -a "${LOGO}" ]]; then if [[ ! -a "${LOGO}" ]]; then
@@ -112,7 +115,7 @@ else
fi fi
# MARK: change directory to temporary working directory # MARK: change directory to temporary working directory
printlog "Changing directory to $tmpDir" printlog "Changing directory to $tmpDir" DEBUG
if ! cd "$tmpDir"; then if ! cd "$tmpDir"; then
printlog "error changing directory $tmpDir" printlog "error changing directory $tmpDir"
cleanupAndExit 1 cleanupAndExit 1
@@ -178,7 +181,12 @@ else
displaynotification "Downloading new $name" "Download in progress …" displaynotification "Downloading new $name" "Download in progress …"
fi fi
fi fi
if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then curlDownload=$(curl -v -fsL --show-error "$downloadURL" -o "$archiveName" 2>&1)
curlDownloadStatus=$(echo $?)
deduplicatelogs "$curlDownload"
printlog "curl output was: $logoutput" DEBUG
if [[ $curlDownloadStatus -ne 0 ]]; then
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
printlog "error downloading $downloadURL" printlog "error downloading $downloadURL"
message="$name update/installation failed. This will be logged, so IT can follow up." message="$name update/installation failed. This will be logged, so IT can follow up."
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
@@ -189,7 +197,7 @@ else
displaynotification "$message" "Error installing $name" displaynotification "$message" "Error installing $name"
fi fi
fi fi
cleanupAndExit 2 cleanupAndExit 2 "Error downloading $downloadURL error: $logoutput" ERROR
fi fi
fi fi