diff --git a/Pandoc/Pandoc.download.recipe b/Pandoc/Pandoc.download.recipe new file mode 100644 index 00000000..e59f4410 --- /dev/null +++ b/Pandoc/Pandoc.download.recipe @@ -0,0 +1,74 @@ + + + + + Description + Download recipe for the latest version of Pandoc. + +Set PRERELEASE to a non-empty string to download prereleases, either +via Input in an override or via the -k option, +i.e.: `-k PRERELEASE=yes + +To download Apple Silicon use: "arm64" in the DOWNLOAD_ARCH variable +To download Intel use: "x86_64" in the DOWNLOAD_ARCH variable + Identifier + com.github.dataJAR-recipes.download.Pandoc + Input + + NAME + Pandoc + DOWNLOAD_ARCH + arm64 + PRERELEASE + + + MinimumVersion + 1.1 + Process + + + Arguments + + github_repo + jgm/pandoc + asset_regex + pandoc-([0-9]+(\.[0-9]+)+)-%DOWNLOAD_ARCH%-macOS\.pkg$ + include_prereleases + %PRERELEASE% + + Processor + GitHubReleasesInfoProvider + + + Arguments + + filename + %NAME%.pkg + url + %url% + + Processor + URLDownloader + + + Processor + EndOfCheckPhase + + + Arguments + + input_path + %pathname% + expected_authority_names + + Developer ID Installer: John Macfarlane (5U2WKE6DES) + Developer ID Certification Authority + Apple Root CA + + + Processor + CodeSignatureVerifier + + + + diff --git a/Pandoc/Pandoc.munki.recipe b/Pandoc/Pandoc.munki.recipe new file mode 100644 index 00000000..6d147453 --- /dev/null +++ b/Pandoc/Pandoc.munki.recipe @@ -0,0 +1,204 @@ + + + + + Description + Downloads the latest version of Pandoc and imports it into Munki. + +For Intel use: "x86_64" in the SUPPORTED_ARCH variable +For Apple Silicon use: "arm64" in the SUPPORTED_ARCH variable + Identifier + com.github.dataJAR-recipes.munki.Pandoc + Input + + MUNKI_REPO_SUBDIR + apps/%NAME% + SUPPORTED_ARCH + arm64 + NAME + Pandoc + pkginfo + + catalogs + + testing + + description + The universal markup converter + +Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. + developer + John Macfarlane + display_name + Pandoc + name + %NAME% + supported_architectures + + %SUPPORTED_ARCH% + + unattended_install + + unattended_uninstall + + + + MinimumVersion + 1.1 + ParentRecipe + com.github.dataJAR-recipes.download.Pandoc + Process + + + Processor + FlatPkgUnpacker + Arguments + + flat_pkg_path + %pathname% + destination_path + %RECIPE_CACHE_DIR%/unpack + + + + Processor + PkgPayloadUnpacker + Arguments + + pkg_payload_path + %RECIPE_CACHE_DIR%/unpack/pandoc.pkg/Payload + destination_path + %RECIPE_CACHE_DIR%/%NAME% + purge_destination + + + + + Processor + PandocVersioner + Arguments + + binary_path + %RECIPE_CACHE_DIR%/%NAME%/usr/local/bin/pandoc + + + + Processor + MunkiPkginfoMerger + Arguments + + additional_pkginfo + + installcheck_script + #!/usr/local/munki/munki-python +# pylint: disable = invalid-name + +''' +Copyright (c) 2024, dataJAR Ltd. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither data JAR Ltd nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + THIS SOFTWARE IS PROVIDED BY DATA JAR LTD 'AS IS' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL DATA JAR LTD BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SUPPORT FOR THIS PROGRAM + This program is distributed 'as is' by DATA JAR LTD. + For more information or support, please utilise the following resources: + http://www.datajar.co.uk + +DESCRIPTION + +See docstring in main() + +''' + +import os +import subprocess +import sys +sys.path.insert(0, '/usr/local/munki') +from munkilib.pkgutils import MunkiLooseVersion as LooseVersion + + +def main(): + ''' + Returns the the version from the Pandoc binary + + Exit 1 if Pandoc is installed and newer than what we have in Munki. + + ''' + + binary_path = '/usr/local/bin/pandoc' + munki_version = '%version%' + binary_version = None + + # If binary exists + if os.path.isfile(binary_path): + # Get binary version, from: https://github.com/jgm/pandoc/blob/58cc5cc57ee4721acde7c7ef99bf964252611805/doc/getting-started.md?plain=1#L303 + # raise if we error + try: + binary_version = subprocess.check_output([binary_path, '--version'] + ).split()[1].decode('utf-8') + except subprocess.CalledProcessError: + print("Encountered an error when ascertaining Pandoc version, " + "proceeding with install...") + sys.exit(0) + # If binary is missing + else: + print("Cannot find {}, proceeding with install...".format(binary_path)) + sys.exit(0) + + # Check binary_version against munki_version + if LooseVersion(binary_version) < LooseVersion(munki_version): + print("Older version of Pandoc, proceeding with install...") + sys.exit(0) + print("Version of Pandoc same or newer than the munki version, skipping...") + sys.exit(1) + + +if __name__ == '__main__': + main() + version + %version% + + + + + Processor + MunkiImporter + Arguments + + pkg_path + %pathname% + repo_subdirectory + %MUNKI_REPO_SUBDIR% + + + + Processor + PathDeleter + Arguments + + path_list + + %RECIPE_CACHE_DIR%/%NAME%/ + %RECIPE_CACHE_DIR%/unpack/ + + + + + + diff --git a/Pandoc/PandocVersioner.py b/Pandoc/PandocVersioner.py new file mode 100755 index 00000000..360f91fe --- /dev/null +++ b/Pandoc/PandocVersioner.py @@ -0,0 +1,106 @@ +#!/usr/local/autopkg/python +# pylint: disable = invalid-name + +''' +Copyright (c) 2024, dataJAR Ltd. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither data JAR Ltd nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + THIS SOFTWARE IS PROVIDED BY DATA JAR LTD 'AS IS' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL DATA JAR LTD BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +SUPPORT FOR THIS PROGRAM + This program is distributed 'as is' by DATA JAR LTD. + For more information or support, please utilise the following resources: + http://www.datajar.co.uk +DESCRIPTION +See docstring for PandocVersioner class +''' + +# Standard Imports +from __future__ import absolute_import +import subprocess +import os + +# AutoPkg imports +# pylint: disable = import-error +from autopkglib import Processor, ProcessorError + + +__all__ = ['PandocVersioner'] +__version__ = '1.0' + + +# pylint: disable = too-few-public-methods +class PandocVersioner(Processor): + ''' + Returns the version from the pandoc binary + + Raising if the key is not found. + ''' + + description = __doc__ + input_variables = { + 'binary_path': { + 'required': True, + 'description': ('Path to the pandoc binary.'), + }, + } + + output_variables = { + 'version': { + 'description': ('Version of the pandoc binary.'), + }, + } + + def main(self): + ''' + See docstring for PandocVersioner class + ''' + + # var declaration + version = None + + # Progress notification + self.output("Looking for: {}".format(self.env['binary_path'])) + + # If binary exists + if os.path.isfile(self.env['binary_path']): + # Get binary version, from https://github.com/jgm/pandoc/blob/58cc5cc57ee4721acde7c7ef99bf964252611805/doc/getting-started.md?plain=1#L303 + # raise if we error + try: + version = subprocess.check_output([self.env['binary_path'], '--version'] + ).split()[1].decode('utf-8') + except subprocess.CalledProcessError: + raise ProcessorError("Encountered an error when trying to get the " + "pandoc binary version...") + # Raise if binary is missing + else: + raise ProcessorError("Cannot access pandoc binary at path: {}" + .format(self.env['binary_path'])) + + # We should only get here if we have passed the above, but this is belt and braces + if version: + self.env['version'] = version + self.output("version: {}".format( + self.env['version'])) + else: + raise ProcessorError("version is None") + + +if __name__ == '__main__': + PROCESSOR = PandocVersioner()