updae/installation detection

This commit is contained in:
Søren Theilgaard
2021-11-10 15:29:59 +01:00
parent 51ba24f5e2
commit 800c356b01
2 changed files with 27 additions and 5 deletions

View File

@@ -148,6 +148,7 @@ getAppVersion() {
appversion="$(pkgutil --pkg-info-plist ${packageID} 2>/dev/null | grep -A 1 pkg-version | tail -1 | sed -E 's/.*>([0-9.]*)<.*/\1/g')"
if [[ $appversion != "" ]]; then
printlog "found packageID $packageID installed, version $appversion"
updateDetected="YES"
return
else
printlog "No version found using packageID $packageID"
@@ -162,7 +163,11 @@ getAppVersion() {
else
applist=$(mdfind "kind:application $appName" -0 )
fi
printlog "App(s) found: ${applist}"
if [[ -z applist ]]; then
printlog "No previous app found"
else
printlog "App(s) found: ${applist}"
fi
appPathArray=( ${(0)applist} )
@@ -173,6 +178,7 @@ getAppVersion() {
#appversion=$(mdls -name kMDItemVersion -raw $installedAppPath )
appversion=$(defaults read $installedAppPath/Contents/Info.plist $versionKey) #Not dependant on Spotlight indexing
printlog "found app at $installedAppPath, version $appversion"
updateDetected="YES"
# Is current app from App Store
if [[ -d "$installedAppPath"/Contents/_MASReceipt ]];then
printlog "Installed $appName is from App Store, use “IGNORE_APP_STORE_APPS=yes” to replace."
@@ -612,7 +618,11 @@ finishing() {
if [[ $currentUser != "loginwindow" && ( $NOTIFY == "success" || $NOTIFY == "all" ) ]]; then
printlog "notifying"
displaynotification "$message" "$name update/installation complete!"
if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "$name update complete!"
else
displaynotification "$message" "$name installation complete!"
fi
fi
}

View File

@@ -169,14 +169,22 @@ else
printlog "Downloading $downloadURL to $archiveName"
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "Downloading $name update" "Download in progress …"
if [[ $updateDetected == "YES" ]]; then
displaynotification "Downloading $name update" "Download in progress …"
else
displaynotification "Downloading new $name" "Download in progress …"
fi
fi
if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
printlog "error downloading $downloadURL"
message="$name update/installation failed. This will be logged, so IT can follow up."
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "$message" "Error installing/updating $name"
if [[ $updateDetected == "YES" ]]; then
displaynotification "$message" "Error updating $name"
else
displaynotification "$message" "Error installing $name"
fi
fi
cleanupAndExit 2
fi
@@ -199,7 +207,11 @@ fi
printlog "Installing $name"
if [[ $currentUser != "loginwindow" && $NOTIFY == "all" ]]; then
printlog "notifying"
displaynotification "Installing $name" "Installation in progress …"
if [[ $updateDetected == "YES" ]]; then
displaynotification "Updating $name" "Installation in progress …"
else
displaynotification "Installing $name" "Installation in progress …"
fi
fi
case $type in