This repository has been archived by the owner on Apr 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_casper_cache.py
76 lines (66 loc) · 2.86 KB
/
install_casper_cache.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
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
#!/usr/bin/env python
'''
Copright 2013 Sar Haidar, Massachusetts Institute of Technology, All Rights Reserved.
Last Modified: 11/12/13
Description:
I wrote this to get out of the hassle of packaging some apps or mounting some dmg's and then uploading the pkg to Casper.
I wanted to upload to the Casper share what the vendor provides and then setup a policy to 'Cache' the app and then
run this script to install the cached file(s).
Script reads files ending in 'dmg', 'zip', and 'pkg' in the client Casper cache directory and installs the software.
How to use:
First and foremost, make sure that the startup_disk (line 19) is accurate on the client or change accordingly
Upload pkg, dmg, or zip to Casper share
Setup policy to "cache" app instead of the default "install" and in that same policy tell it to run this script "After"
Future improvements:
- Automatically get startup_disk
'''
import glob, os, shutil, subprocess
i = 0
startup_disk = "/Volumes/Macintosh HD" # Make sure that this is correct on the client
pkg_path = "/Library/Application Support/JAMF/Waiting Room/"
mounted_pkg = ""
mnt_pkg_path = ""
def install_pkg(pkg_abspath, mnt_pkg_path):
subprocess.call(['installer','-package', pkg_abspath, '-target', startup_disk])
print "Successfully installed", pkg_abspath
def install_app(pkg_abspath, mnt_pkg_path):
subprocess.call(['cp','-R',pkg_abspath,'/Applications'])
print "Successfully installed", pkg_abspath
def mnt_dmg(pkg_name):
global mounted_pkg, mnt_pkg_path
if pkg_name.endswith(".dmg"):
p1 = subprocess.Popen(['hdiutil', 'mount', pkg_name, '-nobrowse'], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['grep', '-o', '/Volumes/.*'], stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close()
mnt_pkg_path = (p2.communicate()[0]).rstrip()
p2.stdout.close()
mounted_pkg = os.listdir(mnt_pkg_path)
elif pkg_name.endswith(".zip"):
subprocess.call(['unzip', '-u',pkg_name, '-d', pkg_path+'folder'])
mnt_pkg_path = pkg_path+'folder'
mounted_pkg = os.listdir(mnt_pkg_path)
print mounted_pkg
return mounted_pkg, mnt_pkg_path
def unmnt_dmg(mnt_pkg_path):
subprocess.call(['hdiutil', 'unmount', mnt_pkg_path])
def del_pkg(pkg_path):
shutil.rmtree(pkg_path)
while i < len(glob.glob(pkg_path+"*.*")):
pkg_name = glob.glob(pkg_path+"*.*")[i]
if pkg_name.endswith(".dmg") or pkg_name.endswith(".zip"):
mnt_dmg(pkg_name)
for item in mounted_pkg:
if item.endswith(".app"):
pkg_abspath = mnt_pkg_path+'/'+item
install_app(pkg_abspath, mnt_pkg_path)
elif item.endswith(".pkg") or item.endswith(".mpkg"):
pkg_abspath = mnt_pkg_path+'/'+item
print pkg_abspath
install_pkg(pkg_abspath, mnt_pkg_path)
if "/Volumes" in mnt_pkg_path:
unmnt_dmg(mnt_pkg_path)
elif pkg_name.endswith(".pkg"):
subprocess.call(['sudo','installer','-package', pkg_name, '-target', startup_disk])
print "Successfully installed", pkg_name
i += 1
del_pkg(pkg_path)