mirror of
https://github.com/kyleneideck/BackgroundMusic
synced 2024-11-23 20:53:04 +00:00
ac33909b51
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.
67 lines
2.7 KiB
Bash
Executable file
67 lines
2.7 KiB
Bash
Executable file
#!/bin/sh
|
|
# vim: tw=100:
|
|
|
|
# This file is part of Background Music.
|
|
#
|
|
# Background Music is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation, either version 2 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# Background Music is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Background Music. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
# postinstall
|
|
#
|
|
# Copyright © 2017, 2018 Kyle Neideck
|
|
#
|
|
|
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
|
|
|
|
coreaudiod_plist="/System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist"
|
|
dest_volume="$3"
|
|
xpc_helper_path="$(bash safe_install_dir.sh -y)"
|
|
|
|
logger "Installing BGMXPCHelper to $xpc_helper_path"
|
|
cp -Rf "BGMXPCHelper.xpc" "$xpc_helper_path"
|
|
|
|
# TODO: Fail the install and show an error message if this fails.
|
|
bash "post_install.sh" "$xpc_helper_path" "BGMXPCHelper.xpc/Contents/MacOS/BGMXPCHelper" "."
|
|
|
|
# TODO: Verify the installed files, their permissions, the _BGMXPCHelper user/group, etc.
|
|
# TODO: Instead of just sleeping for 5 seconds, wait until coreaudiod is restarted and BGMDevice is
|
|
# ready to use.
|
|
|
|
# The extra or-clauses are fallback versions of the command that restarts coreaudiod. Apparently
|
|
# some of these commands don't work with older versions of launchctl, so I figure there's no
|
|
# harm in trying a bunch of different ways (which should all work).
|
|
(launchctl kill SIGTERM system/com.apple.audio.coreaudiod &>/dev/null || \
|
|
launchctl kill TERM system/com.apple.audio.coreaudiod &>/dev/null || \
|
|
launchctl kill 15 system/com.apple.audio.coreaudiod &>/dev/null || \
|
|
launchctl kill -15 system/com.apple.audio.coreaudiod &>/dev/null || \
|
|
(launchctl unload "$coreaudiod_plist" &>/dev/null && \
|
|
launchctl load "$coreaudiod_plist" &>/dev/null) || \
|
|
killall coreaudiod &>/dev/null) && \
|
|
sleep 5
|
|
|
|
# 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
|
|
|
|
exit 0
|
|
|
|
|