-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·120 lines (97 loc) · 2.85 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /bin/bash
# File: install.sh
# Author: James Fator ([email protected])
# Description: Primary installation script for the BTHSControl project.
# Running: "install.sh"
SERVICESDIR="/Library/Services/"
AVRCPAGENTDIR="$SERVICESDIR/AVRCPAgent"
LAUNCHAGENTDIR="/Library/LaunchAgents/"
LAUNCHAGENTPLIST="$LAUNCHAGENTDIR/com.bths.AVRCPAgent.plist"
PLUGIN_DIR="./AVRCPAgent/PlugIns/"
launchctlUnload () {
# If the launchagent can't be found it returns an error but it
# isn't necessarily wrong. Ignore errors for this line only.
set +e
LAUNCHAGENTSTATUS=$((launchctl list com.bths.AVRCPAgent) 2>&1)
set -e
if [[ $LAUNCHAGENTSTATUS != "Could not find service"* ]]; then
echo "Deactivating Service: AVRCPAgent"
launchctl unload $LAUNCHAGENTPLIST
fi
}
build () {
echo "Building"
# Any commands that fail will cause the script to fail.
set -e
# BTHSControl
echo "Building plug-in: BTHSControl"
xcodebuild -project BTHSControl.xcodeproj
if [ ! -d "$PLUGIN_DIR" ]; then
mkdir "$PLUGIN_DIR"
fi
cp -r ./build/Release/BTHSControl.bundle "$PLUGIN_DIR"
}
install () {
echo "Installing"
# Any commands that fail will cause the script to fail.
set -e
# Check that plug-in dir exists
if [ ! -d "$PLUGIN_DIR" ]; then
echo "No plug-in found. Must run with './install.sh build' first."
return
fi
# AVRCPAgent
echo "Setting up Service: AVRCPAgent"
sudo cp -r ./AVRCPAgent $SERVICESDIR
# LaunchAgent
echo "Setting up LaunchAgent: com.bths.AVRCPAgent"
sudo cp ./com.bths.AVRCPAgent.plist $LAUNCHAGENTDIR
sudo chmod 755 $LAUNCHAGENTPLIST
# Unload the service if it is loaded
launchctlUnload
echo "Activating Service: AVRCPAgent"
launchctl load $LAUNCHAGENTPLIST
echo "Installation complete!"
}
uninstall () {
echo "Uninstalling"
# Remove AVRCPAgent
echo "Removing Service: AVRCPAgent"
sudo rm -r $AVRCPAGENTDIR
# Unload LaunchAgent if it is loaded
launchctlUnload
# Remove LaunchAgent
echo "Removing LaunchAgent: com.bths.AVRCPAgent"
sudo rm $LAUNCHAGENTPLIST
echo "Uninstallation complete!"
}
printUsage () {
echo "Usage $0 [build|install|uninstall]"
exit
}
# Check for sudo from within the script
if [[ $( sudo sh -c 'echo $EUID' ) != 0 ]]; then
echo "You need to have sudo access to install"
exit
fi
if [ $# -eq 0 ] || ( [ $1 != "build" ] &&
[ $1 != "install" ] &&
[ $1 != "uninstall" ] )
then
printUsage
elif [ $1 == "build" ]
then
build
elif [ $1 == "install" ]
then
install
elif [ $1 == "uninstall" ]
then
if [ $# -eq 2 ] && [ $2 == "old" ]
then
echo "Uninstalling old"
SERVICESDIR="/System/Library/CoreServices/"
AVRCPAGENTDIR="$SERVICESDIR/AVRCPAgent"
fi
uninstall
fi