Skip to content

Instantly share code, notes, and snippets.

@andrewzirkel
Last active August 9, 2016 17:42
Show Gist options
  • Save andrewzirkel/26404735ebcd6ce15b7190dac6ae46a6 to your computer and use it in GitHub Desktop.
Save andrewzirkel/26404735ebcd6ce15b7190dac6ae46a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# Instructions:
# Build a single product with CCP, name the output folder like the product, i.e. "Lightroom"
# Install the product on the local machine (I build an everything package and install that)
#
# ./munkiimportAdobeCC.py Lightroom
#
#Notes:
# - Folder name must fuzzy match the product name include case, i.e. "Lightroom".
# - Sometimes you need to prepend "Adobe", ie with "Adobe Acrobat"
# - Check the installs array and Icon and make sure they are what you expect.
# - Packages are imported into testing catalog
# - Change options to munkiimport below
import os
import subprocess
import sys
import plistlib
import pprint
from glob import glob
from matplotlib.cbook import Null
from Carbon.AppleEvents import pLineArrow
from plistlib import Plist
from distutils.tests.test_install_scripts import InstallScriptsTestCase
import cmd
MUNKIIMPORT_OPTIONS = [
"--subdirectory", "apps/Adobe",
"--developer", "Adobe",
"--category", "Adobe",
]
if len(sys.argv) < 2:
sys.exit("This script requires a single argument. See the script comments.")
PKG = sys.argv[1]
def get_path(app):
proc = subprocess.Popen(['/usr/sbin/system_profiler','SPApplicationsDataType','-xml'],stdout=subprocess.PIPE)
installedApps = proc.stdout.read()
installedApps = plistlib.readPlistFromString(installedApps)
installedApps = installedApps[0]['_items']
for app in installedApps:
if PKG in app['_name']:
return app['path']
appPath = get_path(PKG)
if appPath is Null:
exit("Intall app first")
appInfo = plistlib.readPlist(appPath + "/Contents/Info.plist")
installs = {'path':appPath,
'type':'application',
'version_comparison_key':'CFBundleShortVersionString',
'CFBundleIdentifier':appInfo['CFBundleIdentifier'],
'CFBundleShortVersionString':appInfo['CFBundleShortVersionString'],
'CFBundleVersion':appInfo['CFBundleVersion']
}
#set app version
MUNKIIMPORT_OPTIONS += ['--pkgvers', appInfo['CFBundleShortVersionString'] ]
#get installs item from existing app
MUNKIIMPORT_OPTIONS += ['-f', appPath]
#Call munkiimport
product = os.path.abspath(PKG)
if not os.path.isdir(product):
exit
install_pkg_path_glob = glob(os.path.join(product, "Build/*Install.pkg"))
uninstall_pkg_path_glob = glob(os.path.join(product, "Build/*Uninstall.pkg"))
if not install_pkg_path_glob or not uninstall_pkg_path_glob:
exit("'%s' doesn't look like a CCP package"
% product)
install_pkg_path = install_pkg_path_glob[0]
uninstall_pkg_path = uninstall_pkg_path_glob[0]
cmd = [
"/usr/local/munki/munkiimport",
"--nointeractive",
]
cmd += MUNKIIMPORT_OPTIONS
cmd += ["--uninstallerpkg", uninstall_pkg_path,
"--minimum-munki-version", "2.1",
]
cmd.append(install_pkg_path)
subprocess.call(cmd)
#get munki_repo
proc = subprocess.Popen(["defaults","read","com.googlecode.munki.munkiimport","repo_path"],stdout=subprocess.PIPE)
munki_repo = proc.stdout.read().strip()
#get icon
iconGlob = glob(os.path.join(appPath, "Contents/Resources/*[aA]pp*.icns"))
iconPath=munki_repo + "/icons/" + PKG + ".png"
cmd = [ "/usr/bin/sips","-s","format","png",iconGlob[0],
"--out",iconPath]
subprocess.call(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment