-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch.sh
executable file
·56 lines (40 loc) · 1.15 KB
/
launch.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
#!/bin/sh
# Substitute some environment variables in a plist file, then
# load it into launchd
if [ $# -lt 1 ]; then
echo "Usage: $0 whichplist"
echo "Eg: $0 surfboard"
exit 1
fi
which=$1
cd "$(dirname "$0")"
SURFPATH="$(pwd -P)"
if [ ! -f $which.plist ]; then
echo "$which.plist does not exist"
exit 1
fi
SURFDIR=${SURFDIR:=$HOME/surfboard}
if [ ! -d $SURFDIR ]; then
echo "$SURFDIR directory does not exist. Create it, or set SURFDIR to the path"
exit 1
fi
PASSWD=$SURFDIR/surfboard_password.txt
if [ ! -f $PASSWD ]; then
echo "$PASSWD does not exist"
exit 1
fi
if [ $(stat -L -f %Op $PASSWD) != "100600" ]; then
echo "Changing permissions on $PASSWD"
chmod 0600 $PASSWD
fi
SURF_IP=${SURF_IP:=192.168.100.1}
echo "USER=$USER"
echo "SURFDIR=$SURFDIR"
echo "SURFPATH=$SURFPATH"
echo "SURF_IP=$SURF_IP"
tmpfile=$(mktemp)
trap 'rm -f $tmpfile;' EXIT
sed -e s/\$USER/$USER/ -e s,\$SURFDIR,$SURFDIR, -e s,\$SURFPATH,$SURFPATH, -e s/\$SURF_IP/$SURF_IP/ $which.plist > $tmpfile
sudo cp $tmpfile /Library/LaunchDaemons/$which.plist
sudo launchctl load /Library/LaunchDaemons/$which.plist
sudo launchctl list | fgrep $which