1 Commits

Author SHA1 Message Date
Søren Theilgaard
b42bd7e408 Trapping the script
Using these signals:
```
SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM SIGTSTP
```

Fixed #272
2022-02-08 13:11:08 +01:00
9 changed files with 140 additions and 180 deletions

View File

@@ -1,10 +1,7 @@
## v9.0.1 ## v10
- improved logging levels throughout the script #408 - Now we trap the script, so if it is cancelled, we will run cleanupAndExit anyway, and have mounted diskimages unmounted and temporary files and folders removed.
- fixed a bug for `pkgindmg` style labels #408 -
- changed the criteria used to locate an app in the case the it cannot be found in the default locations, this should help with some apps with similar name (Virtual Box and Box Drive, #401) #413
- new label: WhiteBox Packages (`packages`) #415
- modified label: `loom` (added Apple silicon download) #417
## v9 ## v9

View File

@@ -301,8 +301,8 @@ if [[ $(/usr/bin/arch) == "arm64" ]]; then
rosetta2=no rosetta2=no
fi fi
fi fi
VERSION="9.0.1" VERSION="9.0"
VERSIONDATE="2022-02-20" VERSIONDATE="2022-02-08"
# MARK: Functions # MARK: Functions
@@ -324,10 +324,8 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
reopenClosedProcess reopenClosedProcess
if [[ -n $2 && $1 -ne 0 ]]; then if [[ -n $2 && $1 -ne 0 ]]; then
printlog "ERROR: $2" $3 printlog "ERROR: $2" $3
else
printlog "$2" $3
fi fi
printlog "################## End Installomator, exit code $1 \n" REQ 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
@@ -484,7 +482,7 @@ versionFromGit() {
appNewVersion=$(curl --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 --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | grep tag_name | cut -d '"' -f 4 | sed 's/[^0-9\.]//g')
if [ -z "$appNewVersion" ]; then if [ -z "$appNewVersion" ]; then
printlog "could not retrieve version number for $gitusername/$gitreponame" WARN printlog "could not retrieve version number for $gitusername/$gitreponame"
appNewVersion="" appNewVersion=""
else else
echo "$appNewVersion" echo "$appNewVersion"
@@ -528,34 +526,19 @@ getAppVersion() {
fi fi
fi fi
# get app in targetDir, /Applications, or /Applications/Utilities # get app in /Applications, or /Applications/Utilities, or find using Spotlight
if [[ -d "$targetDir/$appName" ]]; then if [[ -d "/Applications/$appName" ]]; then
applist="$targetDir/$appName"
elif [[ -d "/Applications/$appName" ]]; then
applist="/Applications/$appName" applist="/Applications/$appName"
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# targetDir="/Applications"
# fi
elif [[ -d "/Applications/Utilities/$appName" ]]; then elif [[ -d "/Applications/Utilities/$appName" ]]; then
applist="/Applications/Utilities/$appName" applist="/Applications/Utilities/$appName"
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# targetDir="/Applications/Utilities"
# fi
else else
# applist=$(mdfind "kind:application $appName" -0 ) applist=$(mdfind "kind:application $appName" -0 )
printlog "name: $name, appName: $appName"
applist=$(mdfind "kind:application AND name:$name" -0 )
# printlog "App(s) found: ${applist}" DEBUG
# applist=$(mdfind "kind:application AND name:$appName" -0 )
fi fi
if [[ -z applist ]]; then if [[ -z applist ]]; then
printlog "No previous app found" INFO printlog "No previous app found" DEBUG
else else
printlog "App(s) found: ${applist}" INFO printlog "App(s) found: ${applist}" DEBUG
fi fi
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# printlog "targetDir for installation: $targetDir" INFO
# fi
appPathArray=( ${(0)applist} ) appPathArray=( ${(0)applist} )
@@ -578,10 +561,10 @@ getAppVersion() {
fi fi
fi fi
else else
printlog "could not determine location of $appName" WARN printlog "could not determine location of $appName"
fi fi
else else
printlog "could not find $appName" WARN printlog "could not find $appName"
fi fi
} }
@@ -708,7 +691,7 @@ reopenClosedProcess() {
processuser=$(ps aux | grep -i "${appName}" | grep -vi "grep" | awk '{print $1}') processuser=$(ps aux | grep -i "${appName}" | grep -vi "grep" | awk '{print $1}')
printlog "Reopened ${appName} as $processuser" printlog "Reopened ${appName} as $processuser"
else else
printlog "App not closed, so no reopen." INFO printlog "App not closed, so no reopen." DEBUG
fi fi
} }
@@ -718,7 +701,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
# check if app exists # check if app exists
if [ ! -e "$appPath" ]; then if [ ! -e "$appPath" ]; then
cleanupAndExit 8 "could not find: $appPath" ERROR cleanupAndExit 8 "could not find: $appPath" DEBUG
fi fi
# verify with spctl # verify with spctl
@@ -750,12 +733,10 @@ installAppWithPath() { # $1: path to app to install in $targetDir
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No new version to install" WARN cleanupAndExit 0 "No new version to install" INFO
else else
printlog "Using force to install anyway." printlog "Using force to install anyway."
fi fi
elif [[ -z $appversion ]]; then
printlog "Installing $name version $appNewVersion on versionKey $versionKey."
else else
printlog "Downloaded version of $name is $appNewVersion on versionKey $versionKey (replacing version $appversion)." printlog "Downloaded version of $name is $appNewVersion on versionKey $versionKey (replacing version $appversion)."
fi fi
@@ -771,7 +752,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
printlog "notifying" printlog "notifying"
displaynotification "$message" "Error updating $name!" displaynotification "$message" "Error updating $name!"
fi fi
cleanupAndExit 6 "Installed macOS is too old for this app." ERROR cleanupAndExit 6 "Installed macOS is too old for this app." INFO
fi fi
fi fi
@@ -910,7 +891,7 @@ installFromPKG() {
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No new version to install" WARN cleanupAndExit 0 "No new version to install" INFO
else else
printlog "Using force to install anyway." printlog "Using force to install anyway."
fi fi
@@ -984,28 +965,27 @@ installPkgInDmg() {
if [[ -z $pkgName ]]; then if [[ -z $pkgName ]]; then
# find first file ending with 'pkg' # find first file ending with 'pkg'
findfiles=$(find "$dmgmount" -iname "*.pkg" -type f -maxdepth 1 ) findfiles=$(find "$dmgmount" -iname "*.pkg" -type f -maxdepth 1 )
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg in dmg $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg in dmg $archiveName" ERROR
fi fi
archiveName="${filearray[1]}" archiveName="${filearray[1]}"
printlog "found pkg: $archiveName"
else else
if [[ -s "$dmgmount/$pkgName" ]] ; then # was: $tmpDir if ls "$tmpDir/$pkgName" ; then
archiveName="$dmgmount/$pkgName" archiveName="$tmpDir/$pkgName"
else else
# try searching for pkg # try searching for pkg
findfiles=$(find "$dmgmount" -iname "$pkgName") # was: $tmpDir findfiles=$(find "$tmpDir" -iname "$pkgName")
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg “$pkgName” in dmg $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg “$pkgName” in zip $archiveName" ERROR
fi fi
# it is now safe to overwrite archiveName for installFromPKG # it is now safe to overwrite archiveName for installFromPKG
archiveName="${filearray[1]}" archiveName="${filearray[1]}"
printlog "found pkg: $archiveName"
fi fi
fi fi
printlog "found pkg: $archiveName"
# installFromPkgs # installFromPkgs
installFromPKG installFromPKG
@@ -1020,7 +1000,6 @@ installPkgInZip() {
if [[ -z $pkgName ]]; then if [[ -z $pkgName ]]; then
# find first file ending with 'pkg' # find first file ending with 'pkg'
findfiles=$(find "$tmpDir" -iname "*.pkg" -type f -maxdepth 2 ) findfiles=$(find "$tmpDir" -iname "*.pkg" -type f -maxdepth 2 )
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg in zip $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg in zip $archiveName" ERROR
@@ -1097,13 +1076,13 @@ runUpdateTool() {
printlog "Error running $updateTool, Procceding with normal installation. Exit Status: $updateStatus Error:\n$logoutput" WARN printlog "Error running $updateTool, Procceding with normal installation. Exit Status: $updateStatus Error:\n$logoutput" WARN
return 1 return 1
if [[ $type == updateronly ]]; then if [[ $type == updateronly ]]; then
cleanupAndExit 77 "No Download URL Set, this is an update only application and the updater failed" ERROR cleanupAndExit 77 "No Download URL Set, this is an update only application and the updater failed" WARN
fi fi
elif [[ $updateStatus -eq 0 ]]; then elif [[ $updateStatus -eq 0 ]]; then
printlog "Debugging enabled, update tool output was:\n$logoutput" DEBUG printlog "Debugging enabled, update tool output was:\n$logoutput" DEBUG
fi fi
else else
printlog "couldn't find $updateTool, continuing normally" WARN printlog "couldn't find $updateTool, continuing normally"
return 1 return 1
fi fi
return 0 return 0
@@ -1171,21 +1150,21 @@ fi
# MARK: argument parsing # MARK: argument parsing
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
if [[ -z $label ]]; then # check if label is set inside script if [[ -z $label ]]; then # check if label is set inside script
printlog "no label provided, printing labels" REQ printlog "no label provided, printing labels"
grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "$0" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "$0" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort
#grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "${labelFile}" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort #grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "${labelFile}" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort
exit 0 exit 0
fi fi
elif [[ $1 == "/" ]]; then elif [[ $1 == "/" ]]; then
# jamf uses sends '/' as the first argument # jamf uses sends '/' as the first argument
printlog "shifting arguments for Jamf" REQ printlog "shifting arguments for Jamf"
shift 3 shift 3
fi fi
while [[ -n $1 ]]; do while [[ -n $1 ]]; do
if [[ $1 =~ ".*\=.*" ]]; then if [[ $1 =~ ".*\=.*" ]]; then
# if an argument contains an = character, send it to eval # if an argument contains an = character, send it to eval
printlog "setting variable from argument $1" REQ printlog "setting variable from argument $1"
eval $1 eval $1
else else
# assume it's a label # assume it's a label
@@ -1257,31 +1236,31 @@ currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print
# MARK: check for root # MARK: check for root
if [[ "$(whoami)" != "root" && "$DEBUG" -eq 0 ]]; then if [[ "$(whoami)" != "root" && "$DEBUG" -eq 0 ]]; then
# not running as root # not running as root
cleanupAndExit 6 "not running as root, exiting" ERROR cleanupAndExit 6 "not running as root, exiting"
fi fi
# MARK: labels in case statement # MARK: labels in case statement
case $label in case $label in
longversion) longversion)
# print the script version # print the script version
printlog "Installomater: version $VERSION ($VERSIONDATE)" REQ printlog "Installomater: version $VERSION ($VERSIONDATE)"
exit 0 exit 0
;; ;;
valuesfromarguments) valuesfromarguments)
if [[ -z $name ]]; then if [[ -z $name ]]; then
printlog "need to provide 'name'" ERROR printlog "need to provide 'name'"
exit 1 exit 1
fi fi
if [[ -z $type ]]; then if [[ -z $type ]]; then
printlog "need to provide 'type'" ERROR printlog "need to provide 'type'"
exit 1 exit 1
fi fi
if [[ -z $downloadURL ]]; then if [[ -z $downloadURL ]]; then
printlog "need to provide 'downloadURL'" ERROR printlog "need to provide 'downloadURL'"
exit 1 exit 1
fi fi
if [[ -z $expectedTeamID ]]; then if [[ -z $expectedTeamID ]]; then
printlog "need to provide 'expectedTeamID'" ERROR printlog "need to provide 'expectedTeamID'"
exit 1 exit 1
fi fi
;; ;;
@@ -2816,11 +2795,7 @@ loom)
# credit: Lance Stephens (@pythoninthegrass on MacAdmins Slack) # credit: Lance Stephens (@pythoninthegrass on MacAdmins Slack)
name="Loom" name="Loom"
type="dmg" type="dmg"
if [[ $(arch) == "arm64" ]]; then downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /dmg/ {print $3}' | head -1)
downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /arm64/ && /dmg/ {print $3}' | head -1)
elif [[ $(arch) == "i386" ]]; then
downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /dmg/ {print $3}' | head -1)
fi
appNewVersion=$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/version/ {print $2}' ) appNewVersion=$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/version/ {print $2}' )
expectedTeamID="QGD2ZPXZZG" expectedTeamID="QGD2ZPXZZG"
;; ;;
@@ -3519,15 +3494,6 @@ pacifist)
downloadURL="https://charlessoft.com/cgi-bin/pacifist_download.cgi?type=dmg" downloadURL="https://charlessoft.com/cgi-bin/pacifist_download.cgi?type=dmg"
expectedTeamID="HRLUCP7QP4" expectedTeamID="HRLUCP7QP4"
;; ;;
packages)
#NOTE: Packages is signed but _not_ notarized, so spctl will reject it
name="Packages"
type="pkgInDmg"
pkgName="Install Packages.pkg"
downloadURL="http://s.sudre.free.fr/Software/files/Packages.dmg"
expectedTeamID="NL5M9E394P"
;;
pandoc) pandoc)
name="Pandoc" name="Pandoc"
type="pkg" type="pkg"
@@ -4639,13 +4605,13 @@ zulujdk8)
*) *)
# unknown label # unknown label
#printlog "unknown label $label" #printlog "unknown label $label"
cleanupAndExit 1 "unknown label $label" ERROR cleanupAndExit 1 "unknown label $label"
;; ;;
esac esac
# Are we only asked to return label name # Are we only asked to return label name
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
printlog "Only returning label name." REQ printlog "Only returning label name."
printlog "$name" printlog "$name"
echo "$name" echo "$name"
exit exit
@@ -4656,7 +4622,7 @@ fi
if [[ ${INTERRUPT_DND} = "no" ]]; then if [[ ${INTERRUPT_DND} = "no" ]]; then
# Check if a fullscreen app is active # Check if a fullscreen app is active
if hasDisplaySleepAssertion; then if hasDisplaySleepAssertion; then
cleanupAndExit 1 "active display sleep assertion detected, aborting" ERROR cleanupAndExit 1 "active display sleep assertion detected, aborting"
fi fi
fi fi
@@ -4701,9 +4667,9 @@ if [[ ! -a "${LOGO}" ]]; then
LOGO="/Applications/App Store.app/Contents/Resources/AppIcon.icns" LOGO="/Applications/App Store.app/Contents/Resources/AppIcon.icns"
fi fi
fi fi
printlog "LOGO=${LOGO}" INFO printlog "LOGO=${LOGO}"
printlog "Label type: $type" INFO printlog "Label type: $type"
# MARK: extract info from data # MARK: extract info from data
if [ -z "$archiveName" ]; then if [ -z "$archiveName" ]; then
@@ -4725,7 +4691,7 @@ if [ -z "$archiveName" ]; then
;; ;;
esac esac
fi fi
printlog "archiveName: $archiveName" INFO printlog "archiveName: $archiveName" DEBUG
if [ -z "$appName" ]; then if [ -z "$appName" ]; then
# when not given derive from name # when not given derive from name
@@ -4743,13 +4709,14 @@ if [ -z "$targetDir" ]; then
updateronly) updateronly)
;; ;;
*) *)
cleanupAndExit 99 "Cannot handle type $type" ERROR printlog "Cannot handle type $type"
cleanupAndExit 99
;; ;;
esac esac
fi fi
if [[ -z $blockingProcesses ]]; then if [[ -z $blockingProcesses ]]; then
printlog "no blocking processes defined, using $name as default" INFO printlog "no blocking processes defined, using $name as default"
blockingProcesses=( $name ) blockingProcesses=( $name )
fi fi
@@ -4765,7 +4732,8 @@ fi
# MARK: change directory to temporary working directory # MARK: change directory to temporary working directory
printlog "Changing directory to $tmpDir" DEBUG printlog "Changing directory to $tmpDir" DEBUG
if ! cd "$tmpDir"; then if ! cd "$tmpDir"; then
cleanupAndExit 1 "error changing directory $tmpDir" ERROR printlog "error changing directory $tmpDir"
cleanupAndExit 1
fi fi
# MARK: get installed version # MARK: get installed version
@@ -4788,10 +4756,10 @@ if [[ -n $appNewVersion ]]; then
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No newer version." WARN cleanupAndExit 0 "No newer version."
fi fi
else else
printlog "DEBUG mode 1 enabled, not exiting, but there is no new version of app." WARN printlog "DEBUG mode 1 enabled, not exiting, but there is no new version of app."
fi fi
fi fi
else else
@@ -4810,7 +4778,7 @@ if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
cleanupAndExit 0 cleanupAndExit 0
fi # otherwise continue fi # otherwise continue
else else
printlog "DEBUG mode 1 enabled, not running update tool" WARN printlog "DEBUG mode 1 enabled, not running update tool"
fi fi
fi fi
@@ -4833,14 +4801,14 @@ else
deduplicatelogs "$curlDownload" deduplicatelogs "$curlDownload"
if [[ $curlDownloadStatus -ne 0 ]]; then if [[ $curlDownloadStatus -ne 0 ]]; then
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then #if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
printlog "error downloading $downloadURL" ERROR 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
printlog "notifying" printlog "notifying"
if [[ $updateDetected == "YES" ]]; then if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "Error updating $name" displaynotification "$message" "Error updating $name" ERROR
else else
displaynotification "$message" "Error installing $name" displaynotification "$message" "Error installing $name" ERROR
fi fi
fi fi
printlog "File list: $(ls -lh "$archiveName")" ERROR printlog "File list: $(ls -lh "$archiveName")" ERROR
@@ -4905,7 +4873,8 @@ case $type in
installAppInDmgInZip installAppInDmgInZip
;; ;;
*) *)
cleanupAndExit 99 "Cannot handle type $type" ERROR printlog "Cannot handle type $type"
cleanupAndExit 99
;; ;;
esac esac

View File

@@ -255,7 +255,6 @@ opera
ottomatic ottomatic
overflow overflow
pacifist pacifist
packages
pandoc pandoc
paretosecurity paretosecurity
parsec parsec

View File

@@ -1,4 +1,9 @@
# MARK: check minimal macOS requirement # MARK: 3 Arguments
# Start trapping the script
trap_with_arg func_trap SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM SIGTSTP
# check minimal macOS requirement
autoload is-at-least autoload is-at-least
installedOSversion=$(sw_vers -productVersion) installedOSversion=$(sw_vers -productVersion)
@@ -10,21 +15,21 @@ fi
# MARK: argument parsing # MARK: argument parsing
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
if [[ -z $label ]]; then # check if label is set inside script if [[ -z $label ]]; then # check if label is set inside script
printlog "no label provided, printing labels" REQ printlog "no label provided, printing labels"
grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "$0" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "$0" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort
#grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "${labelFile}" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort #grep -E '^[a-z0-9\_-]*(\)|\|\\)$' "${labelFile}" | tr -d ')|\' | grep -v -E '^(broken.*|longversion|version|valuesfromarguments)$' | sort
exit 0 exit 0
fi fi
elif [[ $1 == "/" ]]; then elif [[ $1 == "/" ]]; then
# jamf uses sends '/' as the first argument # jamf uses sends '/' as the first argument
printlog "shifting arguments for Jamf" REQ printlog "shifting arguments for Jamf"
shift 3 shift 3
fi fi
while [[ -n $1 ]]; do while [[ -n $1 ]]; do
if [[ $1 =~ ".*\=.*" ]]; then if [[ $1 =~ ".*\=.*" ]]; then
# if an argument contains an = character, send it to eval # if an argument contains an = character, send it to eval
printlog "setting variable from argument $1" REQ printlog "setting variable from argument $1"
eval $1 eval $1
else else
# assume it's a label # assume it's a label
@@ -96,33 +101,33 @@ currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print
# MARK: check for root # MARK: check for root
if [[ "$(whoami)" != "root" && "$DEBUG" -eq 0 ]]; then if [[ "$(whoami)" != "root" && "$DEBUG" -eq 0 ]]; then
# not running as root # not running as root
cleanupAndExit 6 "not running as root, exiting" ERROR cleanupAndExit 6 "not running as root, exiting"
fi fi
# MARK: labels in case statement # MARK: labels in case statement
case $label in case $label in
longversion) longversion)
# print the script version # print the script version
printlog "Installomater: version $VERSION ($VERSIONDATE)" REQ printlog "Installomater: version $VERSION ($VERSIONDATE)"
exit 0 exit 0
;; ;;
valuesfromarguments) valuesfromarguments)
if [[ -z $name ]]; then if [[ -z $name ]]; then
printlog "need to provide 'name'" ERROR printlog "need to provide 'name'"
exit 1 exit 1
fi fi
if [[ -z $type ]]; then if [[ -z $type ]]; then
printlog "need to provide 'type'" ERROR printlog "need to provide 'type'"
exit 1 exit 1
fi fi
if [[ -z $downloadURL ]]; then if [[ -z $downloadURL ]]; then
printlog "need to provide 'downloadURL'" ERROR printlog "need to provide 'downloadURL'"
exit 1 exit 1
fi fi
if [[ -z $expectedTeamID ]]; then if [[ -z $expectedTeamID ]]; then
printlog "need to provide 'expectedTeamID'" ERROR printlog "need to provide 'expectedTeamID'"
exit 1 exit 1
fi fi
;; ;;
# label descriptions start here # Mark: label descriptions start here

View File

@@ -1,4 +1,4 @@
# MARK: Functions # MARK: 2 Functions
cleanupAndExit() { # $1 = exit code, $2 message, $3 level cleanupAndExit() { # $1 = exit code, $2 message, $3 level
if [ -n "$dmgmount" ]; then if [ -n "$dmgmount" ]; then
@@ -18,10 +18,8 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
reopenClosedProcess reopenClosedProcess
if [[ -n $2 && $1 -ne 0 ]]; then if [[ -n $2 && $1 -ne 0 ]]; then
printlog "ERROR: $2" $3 printlog "ERROR: $2" $3
else
printlog "$2" $3
fi fi
printlog "################## End Installomator, exit code $1 \n" REQ 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
@@ -31,6 +29,17 @@ cleanupAndExit() { # $1 = exit code, $2 message, $3 level
exit "$1" exit "$1"
} }
# Two functions to trap the script
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}
func_trap() {
cleanupAndExit 255 "Installomator has been terminated with: $1" ERROR
}
runAsUser() { runAsUser() {
if [[ $currentUser != "loginwindow" ]]; then if [[ $currentUser != "loginwindow" ]]; then
uid=$(id -u "$currentUser") uid=$(id -u "$currentUser")
@@ -178,7 +187,7 @@ versionFromGit() {
appNewVersion=$(curl --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 --silent --fail "https://api.github.com/repos/$gitusername/$gitreponame/releases/latest" | grep tag_name | cut -d '"' -f 4 | sed 's/[^0-9\.]//g')
if [ -z "$appNewVersion" ]; then if [ -z "$appNewVersion" ]; then
printlog "could not retrieve version number for $gitusername/$gitreponame" WARN printlog "could not retrieve version number for $gitusername/$gitreponame"
appNewVersion="" appNewVersion=""
else else
echo "$appNewVersion" echo "$appNewVersion"
@@ -222,34 +231,19 @@ getAppVersion() {
fi fi
fi fi
# get app in targetDir, /Applications, or /Applications/Utilities # get app in /Applications, or /Applications/Utilities, or find using Spotlight
if [[ -d "$targetDir/$appName" ]]; then if [[ -d "/Applications/$appName" ]]; then
applist="$targetDir/$appName"
elif [[ -d "/Applications/$appName" ]]; then
applist="/Applications/$appName" applist="/Applications/$appName"
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# targetDir="/Applications"
# fi
elif [[ -d "/Applications/Utilities/$appName" ]]; then elif [[ -d "/Applications/Utilities/$appName" ]]; then
applist="/Applications/Utilities/$appName" applist="/Applications/Utilities/$appName"
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# targetDir="/Applications/Utilities"
# fi
else else
# applist=$(mdfind "kind:application $appName" -0 ) applist=$(mdfind "kind:application $appName" -0 )
printlog "name: $name, appName: $appName"
applist=$(mdfind "kind:application AND name:$name" -0 )
# printlog "App(s) found: ${applist}" DEBUG
# applist=$(mdfind "kind:application AND name:$appName" -0 )
fi fi
if [[ -z applist ]]; then if [[ -z applist ]]; then
printlog "No previous app found" INFO printlog "No previous app found" DEBUG
else else
printlog "App(s) found: ${applist}" INFO printlog "App(s) found: ${applist}" DEBUG
fi fi
# if [[ $type =~ '^(dmg|zip|tbz|app.*)$' ]]; then
# printlog "targetDir for installation: $targetDir" INFO
# fi
appPathArray=( ${(0)applist} ) appPathArray=( ${(0)applist} )
@@ -272,10 +266,10 @@ getAppVersion() {
fi fi
fi fi
else else
printlog "could not determine location of $appName" WARN printlog "could not determine location of $appName"
fi fi
else else
printlog "could not find $appName" WARN printlog "could not find $appName"
fi fi
} }
@@ -402,7 +396,7 @@ reopenClosedProcess() {
processuser=$(ps aux | grep -i "${appName}" | grep -vi "grep" | awk '{print $1}') processuser=$(ps aux | grep -i "${appName}" | grep -vi "grep" | awk '{print $1}')
printlog "Reopened ${appName} as $processuser" printlog "Reopened ${appName} as $processuser"
else else
printlog "App not closed, so no reopen." INFO printlog "App not closed, so no reopen." DEBUG
fi fi
} }
@@ -412,7 +406,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
# check if app exists # check if app exists
if [ ! -e "$appPath" ]; then if [ ! -e "$appPath" ]; then
cleanupAndExit 8 "could not find: $appPath" ERROR cleanupAndExit 8 "could not find: $appPath" DEBUG
fi fi
# verify with spctl # verify with spctl
@@ -444,12 +438,10 @@ installAppWithPath() { # $1: path to app to install in $targetDir
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No new version to install" WARN cleanupAndExit 0 "No new version to install" INFO
else else
printlog "Using force to install anyway." printlog "Using force to install anyway."
fi fi
elif [[ -z $appversion ]]; then
printlog "Installing $name version $appNewVersion on versionKey $versionKey."
else else
printlog "Downloaded version of $name is $appNewVersion on versionKey $versionKey (replacing version $appversion)." printlog "Downloaded version of $name is $appNewVersion on versionKey $versionKey (replacing version $appversion)."
fi fi
@@ -465,7 +457,7 @@ installAppWithPath() { # $1: path to app to install in $targetDir
printlog "notifying" printlog "notifying"
displaynotification "$message" "Error updating $name!" displaynotification "$message" "Error updating $name!"
fi fi
cleanupAndExit 6 "Installed macOS is too old for this app." ERROR cleanupAndExit 6 "Installed macOS is too old for this app." INFO
fi fi
fi fi
@@ -604,7 +596,7 @@ installFromPKG() {
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No new version to install" WARN cleanupAndExit 0 "No new version to install" INFO
else else
printlog "Using force to install anyway." printlog "Using force to install anyway."
fi fi
@@ -678,28 +670,27 @@ installPkgInDmg() {
if [[ -z $pkgName ]]; then if [[ -z $pkgName ]]; then
# find first file ending with 'pkg' # find first file ending with 'pkg'
findfiles=$(find "$dmgmount" -iname "*.pkg" -type f -maxdepth 1 ) findfiles=$(find "$dmgmount" -iname "*.pkg" -type f -maxdepth 1 )
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg in dmg $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg in dmg $archiveName" ERROR
fi fi
archiveName="${filearray[1]}" archiveName="${filearray[1]}"
printlog "found pkg: $archiveName"
else else
if [[ -s "$dmgmount/$pkgName" ]] ; then # was: $tmpDir if ls "$tmpDir/$pkgName" ; then
archiveName="$dmgmount/$pkgName" archiveName="$tmpDir/$pkgName"
else else
# try searching for pkg # try searching for pkg
findfiles=$(find "$dmgmount" -iname "$pkgName") # was: $tmpDir findfiles=$(find "$tmpDir" -iname "$pkgName")
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg “$pkgName” in dmg $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg “$pkgName” in zip $archiveName" ERROR
fi fi
# it is now safe to overwrite archiveName for installFromPKG # it is now safe to overwrite archiveName for installFromPKG
archiveName="${filearray[1]}" archiveName="${filearray[1]}"
printlog "found pkg: $archiveName"
fi fi
fi fi
printlog "found pkg: $archiveName"
# installFromPkgs # installFromPkgs
installFromPKG installFromPKG
@@ -714,7 +705,6 @@ installPkgInZip() {
if [[ -z $pkgName ]]; then if [[ -z $pkgName ]]; then
# find first file ending with 'pkg' # find first file ending with 'pkg'
findfiles=$(find "$tmpDir" -iname "*.pkg" -type f -maxdepth 2 ) findfiles=$(find "$tmpDir" -iname "*.pkg" -type f -maxdepth 2 )
printlog "Found pkg(s):\n$findfiles" DEBUG
filearray=( ${(f)findfiles} ) filearray=( ${(f)findfiles} )
if [[ ${#filearray} -eq 0 ]]; then if [[ ${#filearray} -eq 0 ]]; then
cleanupAndExit 20 "couldn't find pkg in zip $archiveName" ERROR cleanupAndExit 20 "couldn't find pkg in zip $archiveName" ERROR
@@ -791,13 +781,13 @@ runUpdateTool() {
printlog "Error running $updateTool, Procceding with normal installation. Exit Status: $updateStatus Error:\n$logoutput" WARN printlog "Error running $updateTool, Procceding with normal installation. Exit Status: $updateStatus Error:\n$logoutput" WARN
return 1 return 1
if [[ $type == updateronly ]]; then if [[ $type == updateronly ]]; then
cleanupAndExit 77 "No Download URL Set, this is an update only application and the updater failed" ERROR cleanupAndExit 77 "No Download URL Set, this is an update only application and the updater failed" WARN
fi fi
elif [[ $updateStatus -eq 0 ]]; then elif [[ $updateStatus -eq 0 ]]; then
printlog "Debugging enabled, update tool output was:\n$logoutput" DEBUG printlog "Debugging enabled, update tool output was:\n$logoutput" DEBUG
fi fi
else else
printlog "couldn't find $updateTool, continuing normally" WARN printlog "couldn't find $updateTool, continuing normally"
return 1 return 1
fi fi
return 0 return 0

View File

@@ -2,11 +2,7 @@ loom)
# credit: Lance Stephens (@pythoninthegrass on MacAdmins Slack) # credit: Lance Stephens (@pythoninthegrass on MacAdmins Slack)
name="Loom" name="Loom"
type="dmg" type="dmg"
if [[ $(arch) == "arm64" ]]; then downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /dmg/ {print $3}' | head -1)
downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /arm64/ && /dmg/ {print $3}' | head -1)
elif [[ $(arch) == "i386" ]]; then
downloadURL=https://cdn.loom.com/desktop-packages/$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/url/ && /dmg/ {print $3}' | head -1)
fi
appNewVersion=$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/version/ {print $2}' ) appNewVersion=$(curl -fs https://s3-us-west-2.amazonaws.com/loom.desktop.packages/loom-inc-production/desktop-packages/latest-mac.yml | awk '/version/ {print $2}' )
expectedTeamID="QGD2ZPXZZG" expectedTeamID="QGD2ZPXZZG"
;; ;;

View File

@@ -1,13 +1,14 @@
# Mark: 4 Main
*) *)
# unknown label # unknown label
#printlog "unknown label $label" #printlog "unknown label $label"
cleanupAndExit 1 "unknown label $label" ERROR cleanupAndExit 1 "unknown label $label"
;; ;;
esac esac
# Are we only asked to return label name # Are we only asked to return label name
if [[ $RETURN_LABEL_NAME -eq 1 ]]; then if [[ $RETURN_LABEL_NAME -eq 1 ]]; then
printlog "Only returning label name." REQ printlog "Only returning label name."
printlog "$name" printlog "$name"
echo "$name" echo "$name"
exit exit
@@ -18,7 +19,7 @@ fi
if [[ ${INTERRUPT_DND} = "no" ]]; then if [[ ${INTERRUPT_DND} = "no" ]]; then
# Check if a fullscreen app is active # Check if a fullscreen app is active
if hasDisplaySleepAssertion; then if hasDisplaySleepAssertion; then
cleanupAndExit 1 "active display sleep assertion detected, aborting" ERROR cleanupAndExit 1 "active display sleep assertion detected, aborting"
fi fi
fi fi
@@ -63,9 +64,9 @@ if [[ ! -a "${LOGO}" ]]; then
LOGO="/Applications/App Store.app/Contents/Resources/AppIcon.icns" LOGO="/Applications/App Store.app/Contents/Resources/AppIcon.icns"
fi fi
fi fi
printlog "LOGO=${LOGO}" INFO printlog "LOGO=${LOGO}"
printlog "Label type: $type" INFO printlog "Label type: $type"
# MARK: extract info from data # MARK: extract info from data
if [ -z "$archiveName" ]; then if [ -z "$archiveName" ]; then
@@ -87,7 +88,7 @@ if [ -z "$archiveName" ]; then
;; ;;
esac esac
fi fi
printlog "archiveName: $archiveName" INFO printlog "archiveName: $archiveName" DEBUG
if [ -z "$appName" ]; then if [ -z "$appName" ]; then
# when not given derive from name # when not given derive from name
@@ -105,13 +106,14 @@ if [ -z "$targetDir" ]; then
updateronly) updateronly)
;; ;;
*) *)
cleanupAndExit 99 "Cannot handle type $type" ERROR printlog "Cannot handle type $type"
cleanupAndExit 99
;; ;;
esac esac
fi fi
if [[ -z $blockingProcesses ]]; then if [[ -z $blockingProcesses ]]; then
printlog "no blocking processes defined, using $name as default" INFO printlog "no blocking processes defined, using $name as default"
blockingProcesses=( $name ) blockingProcesses=( $name )
fi fi
@@ -127,7 +129,8 @@ fi
# MARK: change directory to temporary working directory # MARK: change directory to temporary working directory
printlog "Changing directory to $tmpDir" DEBUG printlog "Changing directory to $tmpDir" DEBUG
if ! cd "$tmpDir"; then if ! cd "$tmpDir"; then
cleanupAndExit 1 "error changing directory $tmpDir" ERROR printlog "error changing directory $tmpDir"
cleanupAndExit 1
fi fi
# MARK: get installed version # MARK: get installed version
@@ -150,10 +153,10 @@ if [[ -n $appNewVersion ]]; then
printlog "notifying" printlog "notifying"
displaynotification "$message" "No update for $name!" displaynotification "$message" "No update for $name!"
fi fi
cleanupAndExit 0 "No newer version." WARN cleanupAndExit 0 "No newer version."
fi fi
else else
printlog "DEBUG mode 1 enabled, not exiting, but there is no new version of app." WARN printlog "DEBUG mode 1 enabled, not exiting, but there is no new version of app."
fi fi
fi fi
else else
@@ -172,7 +175,7 @@ if [[ (-n $appversion && -n "$updateTool") || "$type" == "updateronly" ]]; then
cleanupAndExit 0 cleanupAndExit 0
fi # otherwise continue fi # otherwise continue
else else
printlog "DEBUG mode 1 enabled, not running update tool" WARN printlog "DEBUG mode 1 enabled, not running update tool"
fi fi
fi fi
@@ -195,14 +198,14 @@ else
deduplicatelogs "$curlDownload" deduplicatelogs "$curlDownload"
if [[ $curlDownloadStatus -ne 0 ]]; then if [[ $curlDownloadStatus -ne 0 ]]; then
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then #if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
printlog "error downloading $downloadURL" ERROR 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
printlog "notifying" printlog "notifying"
if [[ $updateDetected == "YES" ]]; then if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "Error updating $name" displaynotification "$message" "Error updating $name" ERROR
else else
displaynotification "$message" "Error installing $name" displaynotification "$message" "Error installing $name" ERROR
fi fi
fi fi
printlog "File list: $(ls -lh "$archiveName")" ERROR printlog "File list: $(ls -lh "$archiveName")" ERROR
@@ -267,7 +270,8 @@ case $type in
installAppInDmgInZip installAppInDmgInZip
;; ;;
*) *)
cleanupAndExit 99 "Cannot handle type $type" ERROR printlog "Cannot handle type $type"
cleanupAndExit 99
;; ;;
esac esac

View File

@@ -1 +1 @@
9.0.1 9.1beta