From 800c356b0135e5a887c4449101f73b7cb077a813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Theilgaard?= Date: Wed, 10 Nov 2021 15:29:59 +0100 Subject: [PATCH] updae/installation detection --- fragments/functions.sh | 14 ++++++++++++-- fragments/main.sh | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index 446bbd5..4e30ed7 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -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 } diff --git a/fragments/main.sh b/fragments/main.sh index dfba2c9..e7708ee 100644 --- a/fragments/main.sh +++ b/fragments/main.sh @@ -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