Merge pull request #9 from nickjacques/master

Initial development of uninstall script
This commit is contained in:
Kyle Neideck 2016-04-20 01:32:41 +10:00
commit 4fe8697370
2 changed files with 74 additions and 23 deletions

View file

@ -56,27 +56,7 @@ apps playing audio.
## Uninstall
- Delete `Background Music.app` from `/Applications`.
- Delete `Background Music Device.driver` from `/Library/Audio/Plug-Ins/HAL`.
#### Optional
- Delete `BGMXPCHelper.xpc` from `/usr/local/libexec` or possibly `/Library/Application Support/Background Music`.
- Unregister BGMXPCHelper, delete its user and group, and delete its launchd.plist:
```shell
sudo launchctl bootout system /Library/LaunchDaemons/com.bearisdriving.BGM.XPCHelper.plist
sudo rm /Library/LaunchDaemons/com.bearisdriving.BGM.XPCHelper.plist
sudo dscl . -delete /Users/_BGMXPCHelper
sudo dscl . -delete /Groups/_BGMXPCHelper
```
- Pause apps that are playing audio, if you can.
- Restart `coreaudiod`:
[//]: # ( <sup>(Open `/Applications/Utilities/Terminal.app` and paste the following at the prompt.)</sup> )
```shell
sudo launchctl kill SIGTERM system/com.apple.audio.coreaudiod
```
- Run the `uninstall.sh` script to remove Background Music from your system.
- Go to the Sound section in System Preferences and change your default output device at least once. (If you only have
one device now, either use `Audio MIDI Setup.app` to create a temporary aggregate device, restart any audio apps that
have stopped working or just restart your system.)
@ -129,5 +109,3 @@ change the default device and then change it back again. Failing that, you might
## License
GPLv2 or later

73
uninstall.sh Executable file
View file

@ -0,0 +1,73 @@
#!/bin/bash -e
bold=$(tput bold)
normal=$(tput sgr0)
app_path="/Applications/Background Music.app"
driver_path="/Library/Audio/Plug-Ins/HAL/Background Music Device.driver"
xpc_path1="/usr/local/libexec/BGMXPCHelper.xpc"
xpc_path2="/Library/Application Support/Background Music/BGMXPCHelper.xpc"
file_paths=("${app_path}" "${driver_path}" "${xpc_path1}" "${xpc_path2}")
launchd_plist="/Library/LaunchDaemons/com.bearisdriving.BGM.XPCHelper.plist"
user_group_name="_BGMXPCHelper"
clear
echo "${bold}You are about to uninstall BackgroundMusic and its components!${normal}"
echo "Please pause all audio before continuing."
echo "You must be able to run 'sudo' commands to continue."
echo ""
read -p "Continue (y/n)? " user_prompt
if [ "$user_prompt" == "y" ]; then
# Ensure that the user can use sudo
sudo -v
is_sudo=$?
if [[ "$is_sudo" -ne 0 ]]; then
echo "ERROR: This script must be run by a user with sudo permissions"
exit 1
fi
echo ""
# Remove the files defined in file_paths
for path in "${file_paths[@]}"; do
if [ -e "${path}" ]; then
echo "Deleting \"${path}\""
rm -rf "\"${path}\""
fi
done
echo "Removing BackgroundMusic launchd service"
launchctl list | grep "${launchd_plist}" >/dev/null && sudo launchctl bootout system "${launchd_plist}" || echo " Service does not exist"
echo "Removing BackgroundMusic launchd service configuration file"
if [ -e "${launchd_plist}" ]; then
sudo rm "${launchd_plist}"
fi
echo "Removing BackgroundMusic user"
dscl . -read /Users/"${user_group_name}" 2>/dev/null && sudo dscl . -delete /Users/"${user_group_name}" || echo " User does not exist"
echo "Removing BackgroundMusic group"
dscl . -read /Groups/"${user_group_name}" 2>/dev/null && sudo dscl . -delete /Groups/"${user_group_name}" || echo " Group does not exist"
echo "Restarting CoreAudio"
sudo launchctl kill SIGTERM system/com.apple.audio.coreaudiod && sleep 5
# Invalidate sudo ticket
sudo -k
echo -e "\n${bold}Done! Toggle your sound output device in the Sound control panel to complete the uninstall.${normal}"
osascript -e 'tell application "System Preferences"
activate
reveal anchor "output" of pane "Sound"
end tell' >/dev/null
echo ""
else
echo "Uninstall cancelled."
fi