Skip to content

Commit e50d32e

Browse files
authored
Merge pull request #1564 from sphen13/5.x
Update postflight script to bash to remove Munki-Python requirement
2 parents 6750196 + 49e9c9c commit e50d32e

File tree

1 file changed

+18
-40
lines changed
  • public/assets/client_installer/payload/usr/local/munki

1 file changed

+18
-40
lines changed
Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
1-
#!/usr/local/munki/munki-python
1+
#!/bin/bash
22

3-
import os
4-
import subprocess
5-
import sys
3+
TOUCH_FILE_PATH="/Users/Shared/.com.github.munkireport.run"
4+
LAUNCHD="com.github.munkireport.runner"
5+
LAUNCHD_PLIST="/Library/LaunchDaemons/${LAUNCHD}.plist"
6+
SUBMIT_SCRIPT="/usr/local/munkireport/munkireport-runner"
67

7-
TOUCH_FILE_PATH = '/Users/Shared/.com.github.munkireport.run'
8-
LAUNCHD = 'com.github.munkireport.runner'
9-
LAUNCHD_PATH = '/Library/LaunchDaemons/{}.plist'.format(LAUNCHD)
10-
SUBMIT_SCRIPT = '/usr/local/munkireport/munkireport-runner'
8+
rm -f "$TOUCH_FILE_PATH"
9+
touch "$TOUCH_FILE_PATH"
1110

12-
def write_touch_file():
13-
if os.path.exists(TOUCH_FILE_PATH):
14-
os.remove(TOUCH_FILE_PATH)
15-
16-
if not os.path.exists(TOUCH_FILE_PATH):
17-
with open(TOUCH_FILE_PATH, 'a'):
18-
os.utime(TOUCH_FILE_PATH, None)
19-
20-
def ensure_launchd_loaded():
21-
cmd =[
22-
'/bin/launchctl',
23-
'list'
24-
]
25-
loaded_launchds = subprocess.check_output(cmd).decode('utf-8', 'ignore')
26-
# load the launchd if it's not loaded and is present on disk
27-
if LAUNCHD not in loaded_launchds and os.path.exists(LAUNCHD_PATH):
28-
cmd = [
29-
'/bin/launchctl',
30-
'load',
31-
LAUNCHD_PATH
32-
]
33-
subprocess.check_call(cmd)
34-
35-
def main():
36-
write_touch_file()
37-
ensure_launchd_loaded()
38-
# If the launchd isn't present, call the submit script old school
39-
if not os.path.exists(LAUNCHD_PATH):
40-
subprocess.check_call(SUBMIT_SCRIPT)
41-
42-
if __name__ == '__main__':
43-
main()
11+
if [[ -f "$LAUNCHD_PLIST" ]]; then
12+
if ! launchctl list | grep -q "$LAUNCHD"; then
13+
launchctl bootstrap system "$LAUNCHD_PLIST" 2>/dev/null || \
14+
launchctl load -w "$LAUNCHD_PLIST" 2>/dev/null || true
15+
fi
16+
if ! launchctl list | grep -q "$LAUNCHD"; then
17+
[[ -x "$SUBMIT_SCRIPT" ]] && "$SUBMIT_SCRIPT"
18+
fi
19+
else
20+
[[ -x "$SUBMIT_SCRIPT" ]] && "$SUBMIT_SCRIPT"
21+
fi

0 commit comments

Comments
 (0)