public
Description: A launchd config and supporting scripts to watch for network location changes and execute a script if it finds a match.
Homepage:
Clone URL: git://github.com/UnderpantsGnome/location_watcher.git
location_watcher / install.sh
100755 46 lines (35 sloc) 1.788 kb
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
#!/bin/bash
 
echo "installing location_watcher"
if [ ! -e "${HOME}/bin/location_watcher" ]; then
echo "creating ~/bin/location_watcher"
  mkdir -p ~/bin/location_watcher
fi
 
echo "writing ~/bin/location_watcher.sh"
sed "s:HOME_DIR:${HOME}:g;s:GROWL_PATH:`which growlnotify`:" < ./location_watcher.sh > ~/bin/location_watcher.sh
 
if [ ! -e "${HOME}/Library/LaunchAgents" ]; then
echo "creating ~/Library/LaunchAgents"
  mkdir -p ~/Library/LaunchAgents
fi
 
if [ ! -e "${HOME}/bin/location_watcher/common" ]; then
echo "creating ~/bin/location_watcher/common"
  echo "#!/bin/bash" > ~/bin/location_watcher/common
  chmod u+x ~/bin/location_watcher/common
  chown ${SUDO_USER} ~/bin/location_watcher/common
fi
 
# take ownership of the file
sudo chown ${USER}:wheel ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist
 
# install a new one pointing to our local script
echo "writing ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist"
sed "s:HOME_DIR:${HOME}:g" < ./com.underpantsgnome.location_watcher.plist > ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist
 
# give the file back to root or it wont load
sudo chown root:wheel ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist
 
# tell launchd to unload it to pickup any changes
echo "unloading ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist"
sudo launchctl unload ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist
 
# tell launchd to load it
echo "loading ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist"
sudo launchctl load ~/Library/LaunchAgents/com.underpantsgnome.location_watcher.plist
 
if [ ! -e "${HOME}/.location_watcher" ]; then
echo "creating ~/.location_watcher"
  cp ./location_watcher ~/.location_watcher
fi