forked from rimar/wifi-location-changer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·54 lines (41 loc) · 1.74 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
#!/bin/bash
set -eu
chmod +x locationchanger
sudo mkdir -p /usr/local/bin
sudo cp -a locationchanger /usr/local/bin
cp LocationChanger.plist ~/Library/LaunchAgents/
# remove older service if found
launchctl list | grep --quiet "locationchanger" && launchctl unload ~/Library/LaunchAgents/LocationChanger.plist
# conditionalize on macos version
major_version=$(sw_vers -productVersion | awk -F. '{ print $1; }')
if [[ $major_version -ge 11 ]]; then
# "big sur" or later
# service name includes user ID
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
userID=$( id -u $loggedInUser )
service_name="gui/$userID/locationchanger"
# fyi, removal of new service can be done via:
# sudo launchctl bootout $service_name
# bootstrap (install) as necessary
sudo launchctl print $service_name >> /dev/null 2>&1 || sudo launchctl bootstrap gui/$userID ~/Library/LaunchAgents/LocationChanger.plist
sudo launchctl enable $service_name
# kickstart -k will RESTART process, using any updated code
sudo launchctl kickstart -k $service_name
echo "The service \"$service_name\" has been installed and started"
else
# for older macos
launchctl load ~/Library/LaunchAgents/LocationChanger.plist
echo "The service \"locationchanger\" has been installed and started"
fi
# install any external callout that is present
EXTERNAL_CALLOUT_FILE="./locationchanger.callout.sh"
if [[ -f "$EXTERNAL_CALLOUT_FILE" ]]; then
chmod +x $EXTERNAL_CALLOUT_FILE
sudo cp -a $EXTERNAL_CALLOUT_FILE /usr/local/bin
echo "An external callout ($EXTERNAL_CALLOUT_FILE) was installed also"
fi
# install mapping file
MAPPING_FILE="./locationchanger.conf"
if [[ -f "$MAPPING_FILE" ]]; then
sudo cp -a $MAPPING_FILE /usr/local/bin
fi