-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchd-flowd
executable file
·100 lines (84 loc) · 2.33 KB
/
launchd-flowd
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
#!/usr/bin/env bash
#
# Synopsis:
# Schema flowd server for called from Mac OS/X launchd.
# Usage:
# launchd-flowd path/to/<schema>.flow
#
# <key>ProgramArguments</key>
# <array>
# <string>/usr/local/setspace/sbin/launchd-flowd</string>
# <string>etc/fffile5.flow</string>
# </array>
# <key>WorkingDirectory</key>
# <string>/usr/local/setspace/schema/fffile5</string>
# Note:
# The SIP security palavar may imply a rethink of locating this script
# in /usr/local/setspace/sbin. sbin/ is only readable by user setspace,
# which seems to cause issues with SIP. still learning.
#
log()
{
echo "$(date +'%Y/%m/%d %H:%M:%S'): $@"
}
die()
{
echo "ERROR: $@" >&2
exit 2
}
leave()
{
log 'good bye, cruel world'
}
test $# = 1 || die 'wrong number of arguments'
FLOW=$1
log 'hello, world'
trap leave EXIT
test -n "$SETSPACE_ROOT" || die "environment var not defined: SETSPACE_ROOT"
log "SETSPACE_ROOT=$SETSPACE_ROOT"
log "flow file: $FLOW"
log "current directory: $(pwd)"
#
# source in global $SETSPACE_ROOT/etc/profile
#
PROFILE=$SETSPACE_ROOT/etc/profile
log "source: $PROFILE"
test -r $PROFILE || die "can not read setspace profile: $PROFILE"
. $PROFILE || die "sourcing setspace profile failed: $PROFILE"
#
# source in schema specific profile
#
PROFILE=etc/profile
log "source: $PROFILE"
test -r etc/profile || die "can not read schema profile: $PROFILE"
. $PROFILE || die "sourcing schema profile failed: $PROFILE"
WHICH_OS=$(uname -s)
log "operating system: $WHICH_OS"
# on macos, always add gnu tools from mac ports
if [ "$WHICH_OS" = Darwin ]; then
log 'checking for gnu tools from mac ports ...'
# always add gnu tools in mac ports
test -d /opt/local/bin && PATH=/opt/local/bin:$PATH
test -d /opt/local/libexec/gnubin &&
PATH=/opt/local/libexec/gnubin:$PATH
fi
log "PATH=$PATH"
log "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
log 'clearing run/ directory of stale files ...'
find run -follow -type f -name 'flowd*' | while run ZAP_RUN; do
log "zap state run/ file: $ZAP_RUN"
rm $ZAP_RUN
done
INITX=sbin/launchd-flowd-init
if [ -x $INITX ]; then
log "$INITX exists, so initializing ..."
$INITX || die "launchd-flow-init failed: exit status=$?"
else
log 'WARN (ok): $INITX does not exist'
fi
log 'dumping process environment ...'
env | sort | while read E; do
log "$E"
done
log "execing flowd server $FLOW ..."
exec flowd server $FLOW