From 4c869601a4af8b75aac4bb26b47ec73e3b8ebd40 Mon Sep 17 00:00:00 2001 From: Jon Morrow Date: Tue, 16 Oct 2018 09:15:07 -0700 Subject: [PATCH] Fixes tray app upgrades on mac We need to close the tray app and remove it before the new version can be installed. If the app was running we restart the app. Signed-off-by: Jon Morrow --- omnibus/package-scripts/chef-workstation/postinst | 14 ++++++++++++++ script.sh | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 script.sh diff --git a/omnibus/package-scripts/chef-workstation/postinst b/omnibus/package-scripts/chef-workstation/postinst index bc67662ad7..6f8a36231a 100755 --- a/omnibus/package-scripts/chef-workstation/postinst +++ b/omnibus/package-scripts/chef-workstation/postinst @@ -33,6 +33,13 @@ for binary in $binaries; do done if is_darwin; then + restart_required=false + # Close the app if it is running. + if [ $(osascript -e 'application "Chef Workstation App" is running') = 'true' ]; then + restart_required=true + echo "Closing Chef Workstation App..." + osascript -e 'quit app "Chef Workstation App"' > /dev/null 2>&1; + fi # chef-workstation-app is configured to build Mac as a zip file instead # of a directory. Otherwise, the mac pkgbuild command will find the Chef Workstation App # within the larger Chef Workstatoin package, and will not include it in the Chef Workstation @@ -40,11 +47,18 @@ if is_darwin; then echo "Moving Chef Workstation App to the Applications folder" pushd $INSTALLER_DIR/components/chef-workstation-app unzip chef-workstation-app-mac.zip + sudo rm -rf "/Applications/Chef Workstation App.app" sudo mv "mac/Chef Workstation App.app" /Applications rm -r mac popd ln -sf $INSTALLER_DIR/bin/uninstall_chef_workstation $PREFIX/bin || error_exit "Cannot link uninstall_chef_workstation to $PREFIX/bin" + + # Restart the app if it was running. + if $restart_required; then + echo "Restarting Chef Workstation App..." + osascript -e 'open app "Chef Workstation App"' > /dev/null 2>&1; + fi else # linux - postinst does not run for windows. cwa_app_path="$INSTALLER_DIR/components/chef-workstation-app/chef-workstation-app" ldd "$cwa_app_path" | grep "not found" >/dev/null 2>&1 diff --git a/script.sh b/script.sh new file mode 100755 index 0000000000..474b82885b --- /dev/null +++ b/script.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +restart_required=false + # Close the app if it is running. + if [ $(osascript -e 'application "Chef Workstation App" is running') = 'true' ]; then + restart_required=true + echo "Closing Chef Workstation App..." + osascript -e 'quit app "Chef Workstation App"' > /dev/null 2>&1; + fi + +# Restart the app if it was running. + if $restart_required; then + echo "Restarting Chef Workstation App..." + osascript -e 'open app "Chef Workstation App"' > /dev/null 2>&1; + fi