This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dock_profiler.py
executable file
·50 lines (44 loc) · 2.5 KB
/
dock_profiler.py
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
#!/usr/bin/python
import argparse
import os
import shutil
import tempfile
import subprocess
p = argparse.ArgumentParser(description="Creates a package for Outset that will install a profile for a specific user on login.")
p.add_argument("-p","--profile", help='path to profile to load. Required', required=True)
p.add_argument("-n","--name", help='name of user to trigger on login. Required', required=True)
p.add_argument("-i","--identifier", help='identifier of package, defaults to "com.organization.profile"', default='com.organization.profile')
p.add_argument("-o","--output", help='path to output package, defaults to "Outset-Profile.pkg"', default='Outset-Profile.pkg')
p.add_argument('--once', help='load profile once, not every login',action='store_true')
p.add_argument("-s","--sign", help='sign package with valid identity',metavar='IDENTITY')
p.add_argument("-v","--version", help='version for package, defaults to 1.0', default='1.0')
arguments = p.parse_args()
libraryPath = 'Library/Profiles'
outsetPath = 'usr/local/outset/login-every'
if (arguments.once):
outsetPath = 'usr/local/outset/login-once'
workingPath = tempfile.mkdtemp()
# Copy the profile into the temporary path
os.makedirs(os.path.join(workingPath, 'Outset-Dock-%s' % arguments.name, libraryPath))
shutil.copy(arguments.profile, os.path.join(workingPath, 'Outset-Dock-%s' % arguments.name, libraryPath))
# Place the script into the outset folder in the temporary path
os.makedirs(os.path.join(workingPath, 'Outset-Dock-%s' % arguments.name, outsetPath))
# This is the base profile installer script
script='''#!/bin/sh
if [[ $USER == "%s" ]]; then
/usr/bin/profiles -IvF "/Library/Profiles/%s"
fi
''' % (arguments.name, os.path.basename(arguments.profile))
# write script to file in temp directory
with open(os.path.join(workingPath, 'Outset-Dock-%s' % arguments.name, outsetPath, 'profile-%s.sh' % arguments.name), 'wb') as outsetScript:
outsetScript.write(script)
os.chmod(os.path.join(workingPath, 'Outset-Dock-%s' % arguments.name, outsetPath, 'profile-%s.sh' % arguments.name), 0755)
# Call productbuild to create a package out of the temp folder
cmd = ['/usr/bin/pkgbuild', '--root', os.path.join(workingPath,'Outset-Dock-%s' % arguments.name), '--identifier', arguments.identifier, '--version', str(arguments.version), arguments.output]
if arguments.sign:
cmd += ['--sign', arguments.sign]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(pbout, pberr) = proc.communicate()
if pberr:
print "Error: %s" % pberr
print pbout