#!/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 . # # 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