summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2018-07-04 01:29:39 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2018-07-07 04:54:45 +0200
commitf81d41682ec26c489264351679924fae76884a3d (patch)
tree9a91fcf7f0cc8baa75d42e22b72f753327516395
parent447c6554a4ecb120c407459bb4a173e414ce25e2 (diff)
[pkg] import more osx boilerplate
-rw-r--r--assets/riseupvpn.icnsbin0 -> 1359609 bytes
-rw-r--r--assets/riseupvpn.svg80
-rwxr-xr-xosx/quickpkg557
-rwxr-xr-xosx/scripts/postinstall13
-rwxr-xr-xosx/scripts/preinstall12
-rw-r--r--osx/scripts/se.leap.bitmask-helper.plist26
6 files changed, 688 insertions, 0 deletions
diff --git a/assets/riseupvpn.icns b/assets/riseupvpn.icns
new file mode 100644
index 0000000..b4c9a20
--- /dev/null
+++ b/assets/riseupvpn.icns
Binary files differ
diff --git a/assets/riseupvpn.svg b/assets/riseupvpn.svg
new file mode 100644
index 0000000..a19c6c6
--- /dev/null
+++ b/assets/riseupvpn.svg
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="128"
+ height="128"
+ viewBox="0 0 33.866666 33.866668"
+ version="1.1"
+ id="svg896"
+ inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
+ sodipodi:docname="riseupvpn-launcher.svg">
+ <defs
+ id="defs890" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#d7d7d7"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="5.12"
+ inkscape:cx="26.899914"
+ inkscape:cy="56.22909"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ units="px"
+ inkscape:window-width="1869"
+ inkscape:window-height="1025"
+ inkscape:window-x="51"
+ inkscape:window-y="27"
+ inkscape:window-maximized="1">
+ <inkscape:grid
+ type="xygrid"
+ id="grid1471"
+ empspacing="4" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata893">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-263.13332)">
+ <path
+ style="fill:#006cb2;fill-opacity:1;stroke-width:0.26458335"
+ d="M 15.617988,295.66418 C 9.9401302,292.50672 5.6959906,287.52131 4.7342129,282.87951 4.4622971,281.56718 4.4516145,281.24899 4.4519256,274.47112 l 2.394e-4,-6.47461 0.5616386,-0.36177 c 2.3734615,-1.52883 4.8841786,-2.55103 7.4419094,-3.06699 5.221864,-1.05337 10.639669,0.003 15.485448,3.16684 l 0.398232,0.25998 v 6.50684 c 0,6.8044 -0.01093,7.13134 -0.280843,8.43104 -0.956329,4.6043 -4.632206,9.09553 -10.057782,12.28874 -1.576255,0.9277 -1.527525,0.91863 -2.382844,0.44299 z"
+ id="path5137"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="csccssscssscc" />
+ <path
+ inkscape:connector-curvature="0"
+ style="fill:#007cc3;fill-opacity:1;stroke-width:0.26458335"
+ d="m 16.396917,264.17336 c -1.317958,-4.7e-4 -2.635612,0.13103 -3.941076,0.39437 -2.5577318,0.51596 -5.068528,1.53812 -7.4419895,3.06696 l -0.5615828,0.36177 -4.707e-4,6.47466 c -2.394e-4,6.77787 0.010371,7.096 0.2822554,8.40832 0.9617776,4.64181 5.2059168,9.62724 10.8837756,12.7847 h 1.19e-4 c 0.368953,0.20517 0.569745,0.32326 0.805249,0.31706 v -31.80747 c -0.0088,-2e-5 -0.01755,-4.8e-4 -0.02641,-4.8e-4 z"
+ id="path887" />
+ <path
+ style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458338"
+ d="m 16.989143,272.54844 c 0,0 -0.315707,-0.61165 -0.336761,-0.69601 -0.02106,-0.0844 -0.189431,-0.94909 -0.189431,-0.94909 l 0.210485,-0.37963 0.463046,-0.696 0.673531,-0.52727 0.168377,-0.0633 1.620684,-0.61164 0.147331,-0.14764 -0.168385,-0.25308 -0.231523,-0.12655 -0.424879,-0.10907 -1.064407,-0.10907 -0.825967,0.007 -0.568293,0.12654 -0.505146,-0.18981 -0.63143,-0.0844 -0.9261,-0.0211 -0.463054,-0.0211 -0.778761,0.29527 -1.178677,1.37091 -0.147339,0.52727 -0.08418,0.464 -0.399908,0.86473 -0.252577,0.82254 -0.126285,0.88582 v 0.18982 l -0.610384,0.92799 -0.336761,0.69601 v 0.99126 l 0.10523,2.04581 0.189431,0.73821 0.378861,0.6749 0.4841,0.44292 0.210477,0.8647 0.799815,1.77155 0.947154,1.13886 0.06311,0.0633 0.336761,1.70835 -1.157623,2.10911 -0.363408,0.28169 -0.272426,0.22054 -0.467179,-0.0129 -0.260603,0.13452 -0.316122,0.0134 -0.190994,0.19047 -0.408963,-0.0616 -0.4044091,-0.0196 -0.311982,0.24606 -0.044916,0.36556 0.207365,-0.23472 0.3488649,-0.10158 0.03654,0.33552 0.5512672,-0.18726 0.316122,-0.0134 0.557721,0.0667 c 0,0 0.483518,-0.0316 0.567216,-0.0407 0.0837,-0.009 0.597276,0.0411 0.597276,0.0411 l 0.376644,-0.041 0.199723,0.0844 0.267456,-0.0716 0.290265,0.13818 0.418488,-0.0455 0.05401,-0.28169 -0.01596,-0.14678 0.28571,0.0962 0.232049,0.18692 0.150642,0.21701 -0.0088,-0.27495 -0.182953,-0.31946 c 0,0 -0.125159,-0.17737 -0.208857,-0.16824 -0.0837,0.009 -0.408971,-0.0616 -0.408971,-0.0616 l -0.223321,0.088 -0.243857,-0.10085 -0.239677,0.13226 -0.220665,-0.0822 -0.106491,-0.20049 -0.153322,-0.0471 0.164763,-0.42962 0.378861,-0.52859 0.505146,-0.84364 0.442,-0.5273 0.168385,-0.21088 c 0,0 0.210477,-0.31633 0.210477,-0.40071 0,-0.0844 0.04212,-0.97016 0.04212,-0.97016 l -0.273623,-0.56947 -0.126285,-0.46402 2.441546,0.59059 h 0.147331 l 2.083731,1.49744 0.294669,0.37959 0.10523,1.49729 -0.04212,0.33746 -0.147338,0.27419 -0.105358,0.16875 -0.09101,0.23675 -0.06215,0.1583 -0.386712,0.11988 -0.393086,-0.0709 -0.238209,-0.0294 -0.437428,0.0633 -0.184118,0.19713 -0.07084,0.24475 0.05712,0.24744 0.09172,-0.24769 0.124641,-0.16724 0.121984,-0.0388 0.0094,0.21174 0.163957,0.10406 0.338995,-0.15563 0.166646,-0.0242 0.05409,0.22658 0.508999,-0.01 0.345035,-0.11394 0.282886,0.0443 0.410893,0.047 0.142823,-0.0417 0.112881,-0.10156 0.182442,0.37841 0.0024,-0.42654 -0.176722,-0.48581 -0.256358,-0.15463 0.04324,-0.12712 -0.189423,-0.35849 0.02106,-1.37079 1.052392,1.2444 1.389154,1.09674 c 0,0 0.947146,0.33749 1.03133,0.33749 0.08419,0 0.736677,-0.0844 0.736677,-0.0844 l 0.420954,-0.69598 -0.315715,-0.94908 0.126284,-0.31642 -0.673531,-0.88574 -1.426794,-1.45279 -0.341213,-1.14141 0.02106,-0.78037 -0.315707,-0.82257 -0.357816,-0.65376 0.210477,-0.65377 -0.168377,-0.94904 -0.717785,-1.61568 0.265151,-0.0448 -0.444984,-0.77034 0.289101,-0.0918 -0.508218,-0.82847 0.213764,-0.11524 -0.380944,-0.62543 0.124202,-0.0696 -0.460971,-0.37337 0.168384,-0.0875 -1.199723,-0.84051 z"
+ id="path5892"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="csccccccccccccccccccccccccccccccccccccccccccccccccccccccscccccccccccccsccccccccccccscccccccccccccccccccccccccccccccccccccccccccscccccccccccccccccccccccc" />
+ </g>
+</svg>
diff --git a/osx/quickpkg b/osx/quickpkg
new file mode 100755
index 0000000..a8d0498
--- /dev/null
+++ b/osx/quickpkg
@@ -0,0 +1,557 @@
+#!/usr/bin/python
+
+import argparse
+import string
+import os
+import subprocess
+import tempfile
+import shutil
+import stat
+
+# includes FoundationPlist since some apps store their Info.plist
+# as binary PropertyLists
+
+# FoundationPlist:
+
+# Copyright 2009-2014 Greg Neagle.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""FoundationPlist.py -- a tool to generate and parse MacOSX .plist files.
+
+This is intended as a drop-in replacement for Python's included plistlib,
+with a few caveats:
+ - readPlist() and writePlist() operate only on a filepath,
+ not a file object.
+ - there is no support for the deprecated functions:
+ readPlistFromResource()
+ writePlistToResource()
+ - there is no support for the deprecated Plist class.
+
+The Property List (.plist) file format is a simple XML pickle supporting
+basic object types, like dictionaries, lists, numbers and strings.
+Usually the top level object is a dictionary.
+
+To write out a plist file, use the writePlist(rootObject, filepath)
+function. 'rootObject' is the top level object, 'filepath' is a
+filename.
+
+To parse a plist from a file, use the readPlist(filepath) function,
+with a file name. It returns the top level object (again, usually a
+dictionary).
+
+To work with plist data in strings, you can use readPlistFromString()
+and writePlistToString().
+"""
+
+from Foundation import NSData, \
+ NSPropertyListSerialization, \
+ NSPropertyListMutableContainersAndLeaves, \
+ NSPropertyListXMLFormat_v1_0
+
+
+class FoundationPlistException(Exception):
+ '''Base error for this module'''
+ pass
+
+
+class NSPropertyListSerializationException(FoundationPlistException):
+ '''Read error for this module'''
+ pass
+
+
+class NSPropertyListWriteException(FoundationPlistException):
+ '''Write error for this module'''
+ pass
+
+
+# private functions
+def _dataToPlist(data):
+ '''low-level function that parses a data object into a propertyList object'''
+ darwin_vers = int(os.uname()[2].split('.')[0])
+ if darwin_vers > 10:
+ (plistObject, plistFormat, error) = (
+ NSPropertyListSerialization.propertyListWithData_options_format_error_(
+ data, NSPropertyListMutableContainersAndLeaves, None, None))
+ else:
+ # 10.5 doesn't support propertyListWithData:options:format:error:
+ # 10.6's PyObjC wrapper for propertyListWithData:options:format:error:
+ # is broken
+ # so use the older NSPropertyListSerialization function
+ (plistObject, plistFormat, error) = (
+ NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(
+ data, NSPropertyListMutableContainersAndLeaves, None, None))
+ if plistObject is None:
+ if error is None:
+ error = "Plist data is invalid and could not be deserialized."
+ raise NSPropertyListSerializationException(error)
+ else:
+ return plistObject
+
+
+def _plistToData(plistObject):
+ '''low-level function that creates NSData from a plist object'''
+ darwin_vers = int(os.uname()[2].split('.')[0])
+ if darwin_vers > 10:
+ (data, error) = (
+ NSPropertyListSerialization.dataWithPropertyList_format_options_error_(
+ plistObject, NSPropertyListXMLFormat_v1_0, 0, None))
+ else:
+ # use the older NSPropertyListSerialization function on 10.6 and 10.5
+ (data, error) = (
+ NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_(
+ plistObject, NSPropertyListXMLFormat_v1_0, None))
+ if data is None:
+ if error is None:
+ error = "Property list invalid for format."
+ raise NSPropertyListSerializationException(error)
+ return data
+
+
+# public functions
+def readPlist(filepath):
+ '''Read a .plist file from filepath. Return the unpacked root object
+ (which is usually a dictionary).'''
+ try:
+ data = NSData.dataWithContentsOfFile_(filepath)
+ except NSPropertyListSerializationException, error:
+ # insert filepath info into error message
+ errmsg = (u'%s in %s' % (error, filepath))
+ raise NSPropertyListSerializationException(errmsg)
+ return _dataToPlist(data)
+
+
+def readPlistFromString(aString):
+ '''Read a plist data from a string. Return the root object.'''
+ data = buffer(aString)
+ return _dataToPlist(data)
+
+
+def writePlist(plistObject, filepath):
+ '''Write 'plistObject' as a plist to filepath.'''
+ plistData = _plistToData(plistObject)
+ if plistData.writeToFile_atomically_(filepath, True):
+ return
+ else:
+ raise NSPropertyListWriteException(
+ u"Failed to write plist data to %s" % filepath)
+
+
+def writePlistToString(plistObject):
+ '''Create a plist-formatted string from plistObject.'''
+ return str(_plistToData(plistObject))
+
+
+#
+# quickpkg
+#
+
+
+quickpkg_version = '0.5'
+supported_extensions = ['dmg', 'app', 'zip']
+
+
+# modeled after munkiimport but to build a pkg
+
+
+def logger(log, v=0):
+ if args.verbosity >= v:
+ print log
+
+
+def cmdexec(command, stdin=''):
+ """Execute a command."""
+ # if 'command' is a string, split the string into components
+ if isinstance(command, str):
+ command = command.split()
+
+ proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+ (stdout, stderr) = proc.communicate(stdin)
+
+ logger("cmdexec: %s, result: %s, error: %s" % (command, stdout, stderr), 3)
+
+ # strip trailing whitespace, which would mess with string comparisons
+ return {"return_code": proc.returncode, "stderr": stderr.rstrip(), "stdout": stdout.rstrip()}
+
+
+# from munkicommons.py
+def getFirstPlist(textString):
+ """Gets the next plist from a text string that may contain one or
+ more text-style plists.
+ Returns a tuple - the first plist (if any) and the remaining
+ string after the plist"""
+ plist_header = '<?xml version'
+ plist_footer = '</plist>'
+ plist_start_index = textString.find(plist_header)
+ if plist_start_index == -1:
+ # not found
+ return ("", textString)
+ plist_end_index = textString.find(
+ plist_footer, plist_start_index + len(plist_header))
+ if plist_end_index == -1:
+ # not found
+ return ("", textString)
+ # adjust end value
+ plist_end_index = plist_end_index + len(plist_footer)
+ return (textString[plist_start_index:plist_end_index],
+ textString[plist_end_index:])
+
+
+def dmg_has_sla(dmgpath):
+ has_sla = False
+ imageinfo_cmd = ['/usr/bin/hdiutil', 'imageinfo', dmgpath, '-plist']
+ result = cmdexec(imageinfo_cmd)
+ if result["return_code"] != 0:
+ print "error getting imageinfo! %s, %s" % (result["return_code"], result["stderr"])
+ return False
+ result_plist = result["stdout"]
+ imageinfo_dict = readPlistFromString(result_plist)
+ properties = imageinfo_dict.get('Properties')
+ if properties is not None:
+ has_sla = properties.get('Software License Agreement', False)
+ return has_sla
+
+
+def attachdmg(dmgpath):
+ global dmg_was_mounted
+ info_cmd = ["hdiutil", "info", "-plist"]
+ info_result = cmdexec(info_cmd)
+ if info_result["return_code"] == 0:
+ # parse the plist output
+ (theplist, alltext) = getFirstPlist(info_result["stdout"])
+ info_dict = readPlistFromString(theplist)
+ volpaths = []
+ if "images" in info_dict.keys():
+ for y in info_dict["images"]:
+ if "image-path" in y.keys():
+ if os.path.samefile(y["image-path"], dmgpath):
+ for x in y.get("system-entities"):
+ if "mount-point" in x.keys():
+ volpaths.append(x["mount-point"])
+ dmg_was_mounted = True
+ return volpaths
+ else:
+ print "error getting hdiutil info"
+ print "(%d, %s)" % (info_result["returncode"], info_result["stderr"])
+ cleanup_and_exit(1)
+
+ attachcmd = ["/usr/bin/hdiutil",
+ "attach",
+ dmgpath,
+ "-mountrandom",
+ "/private/tmp",
+ "-plist",
+ "-nobrowse"]
+ if dmg_has_sla(dmgpath):
+ stdin = "Y\n"
+ print "NOTE: Disk image %s has a license agreement!" % dmgpath
+ else:
+ stdin = ''
+ result = cmdexec(attachcmd, stdin)
+ if result["return_code"] == 0:
+ # parse the plist output
+ (theplist, alltext) = getFirstPlist(result["stdout"])
+ resultdict = readPlistFromString(theplist)
+ volpaths = []
+ for x in resultdict["system-entities"]:
+ if x["potentially-mountable"]:
+ if x["volume-kind"] == 'hfs':
+ volpaths.append(x["mount-point"])
+ # return the paths to mounted volume
+ return volpaths
+ else:
+ print "error mounting disk image"
+ print "(%d, %s)" % (result["returncode"], result["stderr"])
+ cleanup_and_exit(1)
+
+
+def detachpaths(volpaths):
+ for x in volpaths:
+ if os.path.exists(x):
+ if os.path.ismount(x):
+ detachcmd = ["/usr/bin/hdiutil", "detach", x]
+ cmdexec(detachcmd)
+
+
+def finditemswithextension(dirpath, item_extension):
+ foundapps = []
+ if os.path.exists(dirpath):
+ for x in os.listdir(dirpath):
+ (item_basename, item_extension) = os.path.splitext(x)
+ item_extension = string.lstrip(item_extension, '.')
+ if item_extension == 'app':
+ foundapps.append(os.path.join(dirpath, x))
+ else:
+ print "path %s does not exist" % dirpath
+ cleanup_and_exit(1)
+ return foundapps
+
+
+def appNameAndVersion(app_path):
+ info_path = os.path.join(app_path, "Contents/Info.plist")
+ if not os.path.exists(info_path):
+ print "Application at path %s does not have Info.plist" % app_path
+ # TODO: cleanup volumes here
+ cleanup_and_exit(1)
+ info_plist = readPlist(info_path)
+ app_name = info_plist.get("CFBundleName")
+ if app_name is None:
+ app_name = info_plist.get("CFBundleDisplayName")
+ if app_name is None:
+ (app_name, app_ext) = os.path.splitext(os.path.basename(app_path))
+ app_identifier = info_plist.get("CFBundleIdentifier")
+ app_version = info_plist.get("CFBundleShortVersionString")
+ if app_version is None:
+ app_version = info_plist.get("CFBundleVersion")
+ return (app_name, app_identifier, app_version)
+
+
+def cleanup_and_exit(returncode):
+ global dmgvolumepaths
+ global dmg_was_mounted
+ global tmp_path
+
+ if args.clean:
+ if not dmg_was_mounted:
+ detachpaths(dmgvolumepaths)
+ if tmp_path is not None:
+ shutil.rmtree(tmp_path)
+ exit(returncode)
+
+
+if __name__ == "__main__":
+
+ parser = argparse.ArgumentParser(description="""Attempts to build a pkg from the input.
+ Installer item can be a dmg, zip, or app.""",
+ epilog="""Example: quickpkg /path/to/installer_item""")
+
+ # takes a path as input
+ parser.add_argument('item_path', help="path to the installer item")
+
+ scripts_group = parser.add_argument_group('Installation Scripts',
+ '''These options will set the installation scripts. You pass an entire folder of scripts,
+ just like the option of `pkgbuild` or you can give a file for the preinstall or postinstall
+ scripts respectively. If you give both the --scripts and either one or both of --preinstall
+ and --postinstall, quickpkg will attempt to merge, but throw an error if it cannot.''')
+ scripts_group.add_argument('--scripts', help="path to a folder with scripts")
+ scripts_group.add_argument('--preinstall', '--pre', help="path to the preinstall script")
+ scripts_group.add_argument('--postinstall', '--post', help="path to the postinstall script")
+
+ parser.add_argument('--ownership', choices=['recommended', 'preserve', 'preserve-other'],
+ help="will be passed through to pkgbuild")
+ parser.add_argument('--output', '--out', '-o',
+ help='''path where the package file will be created. If you give the full filename
+ then you can use '{name}', '{version}' and '{identifier}' as placeholders.
+ If this is a directory, then the
+ package will be created with the default filename {name}-{version}.pkg''')
+
+ parser.add_argument('--clean', dest='clean', action='store_true', help="clean up temp files (DEFAULT)")
+ parser.add_argument('--no-clean', dest='clean', action='store_false', help=" do NOT clean up temp files")
+ parser.set_defaults(clean=True)
+
+ parser.add_argument('--relocatable', dest='relocatable', action='store_true',
+ help="sets BundleIsRelocatable in the PackageInfo to true")
+ parser.add_argument('--no-relocatable', dest='relocatable', action='store_false',
+ help="sets BundleIsRelocatable in the PackageInfo (DEFAULT is false)")
+ parser.set_defaults(relocatable=False)
+
+
+ parser.add_argument("-v", "--verbosity", action="count", default=0, help="controls amount of logging output (max -vvv)")
+ parser.add_argument('--version', help='prints the version', action='version', version=quickpkg_version)
+
+ args = parser.parse_args()
+
+ # remove trailing '/' from path
+ item_path = string.rstrip(args.item_path, '/')
+
+ if item_path.startswith('~'):
+ item_path = os.path.expanduser(item_path)
+ item_path = os.path.abspath(item_path)
+
+ # get file extension
+ (item_basename, item_extension) = os.path.splitext(item_path)
+ item_extension = string.lstrip(item_extension, '.')
+
+ # is extension supported
+ if item_extension not in supported_extensions:
+ print ".%s is not a supported extension!" % item_extension
+ exit(1)
+
+ foundapps = []
+
+ # if item is an app, just pass it on
+ if item_extension == 'app':
+ if not os.path.exists(item_path):
+ print "This does not seem to be an Application!"
+ exit(1)
+ foundapps.append(item_path)
+
+ dmgvolumepaths = []
+ tmp_path = None
+ dmg_was_mounted = False
+ tmp_scripts_path = None
+ tmp_path = tempfile.mkdtemp()
+ payload_path = os.path.join(tmp_path, "payload")
+ os.makedirs(payload_path)
+
+ # if item is a dmg, mount it and find useful contents
+ if item_extension == 'dmg':
+ dmgvolumepaths = attachdmg(item_path)
+ for x in dmgvolumepaths:
+ moreapps = finditemswithextension(x, 'app')
+ foundapps.extend(moreapps)
+ if len(foundapps) == 0:
+ print "Could not find an application!"
+ cleanup_and_exit(1)
+ elif len(foundapps) > 1:
+ print "Found too many Applications! Can't decide!"
+ print foundapps
+ cleanup_and_exit(1)
+
+ # if item is zip, unzip to tmp location and find useful contents
+ if item_extension == 'zip':
+ unarchive_path = os.path.join(tmp_path, "unarchive")
+ unzip_cmd = ["/usr/bin/unzip", "-d", unarchive_path, item_path]
+ result = cmdexec(unzip_cmd)
+ if result["return_code"] != 0:
+ print "An error occured while unzipping:"
+ print "%d, %s" % (result["return_code"], result["stderr"])
+ cleanup_and_exit(1)
+ foundapps = finditemswithextension(unarchive_path, 'app')
+ if len(foundapps) == 0:
+ print "Could not find an application!"
+ cleanup_and_exit(1)
+ elif len(foundapps) > 1:
+ print "Found too many Applications! Can't decide!"
+ print foundapps
+ cleanup_and_exit(1)
+
+ logger("Found application: %s" % foundapps[0], 1)
+
+ # copy found app to payload folder
+ app_name = os.path.basename(foundapps[0])
+ app_path = os.path.join(payload_path, app_name)
+ shutil.copytree(foundapps[0], app_path)
+
+ # extract version and other metadata
+ (app_name, app_identifier, app_version) = appNameAndVersion(app_path)
+
+ logger("Name: %s, ID: %s, Version: %s" % (app_name, app_identifier, app_version), 1)
+
+ # create the component plist
+ component_plist = os.path.join(tmp_path, app_identifier) + ".plist"
+ analyzecmd = ["/usr/bin/pkgbuild",
+ "--analyze",
+ "--root", payload_path,
+ "--identifier", app_identifier,
+ "--version", app_version,
+ "--install-location", "/Applications",
+ component_plist]
+ result = cmdexec(analyzecmd)
+
+ logger(result["stdout"], 1)
+ if result["return_code"] != 0:
+ print "Error Code: %d " % result["return_code"]
+ print result["stderr"]
+ cleanup_and_exit(1)
+
+ if not args.relocatable:
+ # read and change component plist
+ components = readPlist(component_plist)
+ # component plist is an array of components
+ for bundle in components:
+ if "BundleIsRelocatable" in bundle.keys():
+ bundle["BundleIsRelocatable"] = False
+ writePlist(components, component_plist)
+
+ pkg_name = "{name}-{version}.pkg"
+ if args.output:
+ if os.path.isdir(args.output):
+ pkg_path = os.path.join(args.output, pkg_name)
+ else:
+ pkg_path = args.output
+ else:
+ pkg_path = pkg_name
+ nospace_app_name = app_name.replace(' ', '') # remove spaces
+ pkg_path = pkg_path.format(name=nospace_app_name, version=app_version, identifier=app_identifier)
+
+ if not pkg_path.endswith('pkg'):
+ pkg_path += '.pkg'
+
+ # run pkgutil to build result
+ pkgcmd = ["/usr/bin/pkgbuild",
+ "--root", payload_path,
+ "--component-plist", component_plist,
+ "--identifier", app_identifier,
+ "--version", app_version,
+ "--install-location", "/Applications",
+ pkg_path]
+
+ if args.scripts and not os.path.exists(args.scripts):
+ print "scripts folder %s does not exist!" % args.scripts
+ cleanup_and_exit(1)
+
+ if args.postinstall or args.preinstall:
+ tmp_scripts_path = os.path.join(tmp_dir, "scripts")
+ os.makedirs(tmp_scripts_path)
+
+ if args.scripts:
+ logger("copying %s to tmp scripts folder %s" % (args.scripts, tmp_scripts_path), 1)
+ shutil.rmtree(tmp_scripts_path)
+ shutil.copytree(args.scripts, tmp_scripts_path)
+ if args.postinstall:
+ if not os.path.exists(args.postinstall):
+ print "postinstall file %s does not exist!" % args.postinstall
+ cleanup_and_exit(1)
+ postinstall_path = os.path.join(tmp_scripts_path, "postinstall")
+ if os.path.exists(postinstall_path):
+ print "postinstall script already exists in %s" % args.scripts
+ cleanup_and_exit(1)
+ logger("copying %s to %s" % (args.postinstall, postinstall_path), 1)
+ shutil.copy2(args.postinstall, postinstall_path)
+ os.chmod(postinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
+ stat.S_IRGRP | stat.S_IXGRP |
+ stat.S_IROTH | stat.S_IXOTH)
+ if args.preinstall:
+ if not os.path.exists(args.preinstall):
+ print "preinstall file %s does not exist!" % args.preinstall
+ cleanup_and_exit(1)
+ preinstall_path = os.path.join(tmp_scripts_path, "preinstall")
+ if os.path.exists(preinstall_path):
+ print "preinstall script already exists in %s" % args.scripts
+ cleanup_and_exit(1)
+ logger("copying %s to %s" % (args.preinstall, preinstall_path), 1)
+ shutil.copy2(args.preinstall, preinstall_path)
+ os.chmod(preinstall_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
+ stat.S_IRGRP | stat.S_IXGRP |
+ stat.S_IROTH | stat.S_IXOTH)
+
+ if tmp_scripts_path:
+ logger("scripts path: %s" % tmp_scripts_path, 1)
+ pkgcmd.extend(["--scripts", tmp_scripts_path])
+ elif args.scripts:
+ logger("scripts path: %s" % args.scripts, 1)
+ pkgcmd.extend(["--scripts", args.scripts])
+
+ if args.ownership:
+ pkgcmd.extend(["--ownership", args.ownership])
+
+ result = cmdexec(pkgcmd)
+
+ logger(result["stdout"], 1)
+ if result["return_code"] != 0:
+ print "Error Code: %d " % result["return_code"]
+ print result["stderr"]
+ else:
+ print pkg_path
+
+ cleanup_and_exit(0)
diff --git a/osx/scripts/postinstall b/osx/scripts/postinstall
new file mode 100755
index 0000000..9343039
--- /dev/null
+++ b/osx/scripts/postinstall
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Bitmask Post-Instalation script
+# (c) LEAP Encryption access Project
+# We copy the bitmask-helper plist to the LaunchDaemons folder, and load the bitmask-helper that runs as root.
+
+LOG=/tmp/bitmask-install.log
+
+chmod +x /Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/bitmask-helper
+cp se.leap.bitmask-helper.plist /Library/LaunchDaemons/ \
+ && echo `date` ":: Bitmask post-install: copied bitmask-helper Plist." >> $LOG
+launchctl load /Library/LaunchDaemons/se.leap.bitmask-helper.plist && echo `date` ":: Bitmask post-install: loaded bitmask-helper." >> $LOG
+echo `date` ":: Bitmask post-install: ok." >> $LOG
+exit 0
diff --git a/osx/scripts/preinstall b/osx/scripts/preinstall
new file mode 100755
index 0000000..1ae68f9
--- /dev/null
+++ b/osx/scripts/preinstall
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Bitmask Pre-Instalation script
+# (c) LEAP Encryption access Project
+# We unload the bitmask-helper if it is running, because we can be installing an upgrade.
+
+LOG=/tmp/bitmask-install.log
+
+ps aux | grep [b]itmask-helper \
+ && launchctl unload /Library/LaunchDaemons/se.leap.bitmask-helper.plist \
+ && echo `date` ":: Bitmask pre-install: unloaded bitmask-helper." >> $LOG
+echo `date` ":: Bitmask pre-install: ok." >> $LOG
+exit 0
diff --git a/osx/scripts/se.leap.bitmask-helper.plist b/osx/scripts/se.leap.bitmask-helper.plist
new file mode 100644
index 0000000..8ebfb94
--- /dev/null
+++ b/osx/scripts/se.leap.bitmask-helper.plist
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>WorkingDirectory</key>
+ <string>/Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/</string>
+ <key>StandardOutPath</key>
+ <string>bitmask-helper.log</string>
+ <key>StandardErrorPath</key>
+ <string>bitmask-helper-err.log</string>
+ <key>GroupName</key>
+ <string>daemon</string>
+ <key>RunAtLoad</key>
+ <true/>
+ <key>SessionCreate</key>
+ <true/>
+ <key>KeepAlive</key>
+ <true/>
+ <key>ThrottleInterval</key>
+ <integer>5</integer>
+ <key>Label</key>
+ <string>se.leap.BitmaskHelper</string>
+ <key>Program</key>
+ <string>/Applications/RiseupVPN.app/Contents/Resources/bitmask-helper/bitmask-helper</string>
+</dict>
+</plist>