From ac33909b519746caa41ba29ec85dbbfabdd112f6 Mon Sep 17 00:00:00 2001 From: Kyle Neideck Date: Thu, 4 Oct 2018 21:09:18 +1000 Subject: [PATCH] Fix pkg installer not opening BGMApp if relocated. If the user moved BGMApp and then installed a new version from a .pkg, BGMApp would be installed to the same place the old version had been moved to. When pkg/postinstall tried to open BGMApp, it would fail because it assumed BGMApp would be installed to /Applications. Also, the installer now fails with an error message if it can't open BGMApp after finishing the install. Fixes #164. --- package.sh | 3 ++- pkg/postinstall | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.sh b/package.sh index 6a6df03..288cb99 100755 --- a/package.sh +++ b/package.sh @@ -28,7 +28,7 @@ # Based on https://github.com/tekezo/Karabiner-Elements/blob/master/make-package.sh # -# TODO: Code signing. See `man pkgbuild`. +# TODO: Code signing. See `man productbuild`. PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"; export PATH @@ -162,6 +162,7 @@ pkgbuild \ productbuild \ --distribution "pkg/Distribution.xml" \ + --identifier "$pkg_identifier" \ --resources "pkgres" \ --package-path "$out_dir" \ "$pkg" diff --git a/pkg/postinstall b/pkg/postinstall index a256282..59a811e 100755 --- a/pkg/postinstall +++ b/pkg/postinstall @@ -19,7 +19,7 @@ # # postinstall # -# Copyright © 2017 Kyle Neideck +# Copyright © 2017, 2018 Kyle Neideck # PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH @@ -50,7 +50,14 @@ bash "post_install.sh" "$xpc_helper_path" "BGMXPCHelper.xpc/Contents/MacOS/BGMXP killall coreaudiod &>/dev/null) && \ sleep 5 -open "${dest_volume}/Applications/Background Music.app" +# Try opening BGMApp using its bundle ID first so the installer can declare it as "relocatable". +# That way, if the user moves BGMApp and then installs a newer version of Background Music, the +# installer will try to find the old version of BGMApp and put the new one in the same place. +# +# If we can't open BGMApp, it very likely didn't install properly, so we fail the install. +open -b com.bearisdriving.BGM.App || \ + open "${dest_volume}/Applications/Background Music.app" || \ + exit 1 # The installer plays a sound when it finishes, so give BGMApp a second to launch. sleep 1