diff --git a/SharedProcessors/GoogleChromeUpdateInfoProvider.py b/SharedProcessors/GoogleChromeUpdateInfoProvider.py new file mode 100644 index 0000000..d3f7bad --- /dev/null +++ b/SharedProcessors/GoogleChromeUpdateInfoProvider.py @@ -0,0 +1,148 @@ +#!/usr/local/autopkg/python +# +# based upon a script written by JasonWalker +# +# Related: +# - https://github.com/hjuutilainen/adminscripts/blob/master/chrome-enable-autoupdates.py +# - https://gist.github.com/pudquick/8cd029d0967ee6f5ee353ed5a967f33c +# +import uuid +from xml.etree import ElementTree as ET + +import requests +from autopkglib import Processor, ProcessorError + +__all__ = ["GoogleChromeUpdateInfoProvider"] + + +class GoogleChromeUpdateInfoProvider(Processor): + """Gets a static url for latest Chrome Download""" + + description = ( + "Provides download information for the latest version of Google Chrome." + ) + input_variables = { + # "chrome_channel": { + # "required": False, + # "default": "stable", + # "description": "Update channel (e.g., stable, beta, dev).", + # }, + "chrome_os": { + "required": False, + "default": "win", + "description": "Operating system (e.g., win, mac, linux).", + }, + # "chrome_arch": { + # "required": False, + # "default": "x64", + # "description": "Architecture (e.g., x64, x86).", + # }, + "chrome_os_version": { + "required": False, + "default": "10.0", + "description": "Operating system version (e.g., 10.0, 6.2).", + }, + # "chrome_version": { + # "required": False, + # "default": "", + # "description": "Target Chrome version. Leave empty for the latest available.", + # }, + "chrome_appid": { + "required": False, + "default": "{8A69D345-D564-463C-AFF1-A69D9E530F96}", + "description": "For MacOS set to `com.google.Chrome`.", + }, + } + output_variables = { + "chrome_package_name": {"description": "Name of the Chrome package."}, + "chrome_package_sha256": {"description": "SHA256 hash of the Chrome package."}, + "chrome_package_size": {"description": "Size of the Chrome package."}, + "chrome_download_urls": { + "description": "List of download URLs for the Chrome package." + }, + "url": {"description": "A single download url for the Chrome package."}, + } + + def main(self): + """Execution starts here""" + + request_id = str(uuid.uuid4()).upper() + # session_id = str(uuid.uuid4()).upper() + + # channel = self.env.get("chrome_channel") + os = self.env.get("chrome_os") + # arch = self.env.get("chrome_arch") + os_version = self.env.get("chrome_os_version") + # chrome_version = self.env.get("chrome_version", "") + chrome_appid = self.env.get("chrome_appid", "") + + # update_request = f""" + # + # + # + # + # + # """ + + # from: https://gist.github.com/pudquick/8cd029d0967ee6f5ee353ed5a967f33c + update_request = f""" + + + + + + + """ + + update_request_url = "https://tools.google.com/service/update2" + + headers = { + "Content-Type": "application/x-www-form-urlencoded", + "X-Goog-Update-Interactivity": "fg", + } + + response = requests.post( + url=update_request_url, headers=headers, data=update_request, timeout=90 + ) + if not response.ok: + raise ProcessorError( + f"Error reported: {response.status_code} : {response.text}" + ) + + content_xml = ET.fromstring(response.content) + try: + package_name = content_xml.find( + "app/updatecheck/manifest/packages/package" + ).get("name") + package_sha256 = content_xml.find( + "app/updatecheck/manifest/packages/package" + ).get("hash_sha256") + package_size = content_xml.find( + "app/updatecheck/manifest/packages/package" + ).get("size") + except AttributeError as err: + self.output(response.text) + raise err + + urls = [ + url.get("codebase") + for url in content_xml.findall("app/updatecheck/urls/url") + ] + + self.env["chrome_package_name"] = package_name + self.env["chrome_package_sha256"] = package_sha256 + self.env["chrome_package_size"] = package_size + self.env["chrome_download_urls"] = urls + + # Note, it might make sense to filter the list in a smarter way: + self.env["url"] = urls[-1] + + # self.output( + # f"\nUpdates found:\nName: {package_name}\nSHA256: {package_sha256}\nSize: {package_size}\nDownload URLs: {urls}" + # ) + + +if __name__ == "__main__": + processor = GoogleChromeUpdateInfoProvider() + processor.execute_shell() diff --git a/Test-Recipes/GoogleChromeUpdateInfoProvider.test.recipe.yaml b/Test-Recipes/GoogleChromeUpdateInfoProvider.test.recipe.yaml new file mode 100644 index 0000000..7bfd85c --- /dev/null +++ b/Test-Recipes/GoogleChromeUpdateInfoProvider.test.recipe.yaml @@ -0,0 +1,24 @@ +--- +Description: Test GoogleChromeUpdateInfoProvider Processor +Identifier: com.github.jgstew.test.GoogleChromeUpdateInfoProvider +Input: + NAME: GoogleChromeUpdateInfoProviderTest +MinimumVersion: "2.3" +Process: + - Processor: com.github.jgstew.SharedProcessors/GoogleChromeUpdateInfoProvider + + - Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString + Arguments: + input_string: "%chrome_package_name%" + assert_string: "chrome_installer." + + - Processor: com.github.jgstew.SharedProcessors/GoogleChromeUpdateInfoProvider + Arguments: + chrome_os: mac + chrome_os_version: "10.12" + chrome_appid: com.google.Chrome + + - Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString + Arguments: + input_string: "%chrome_package_name%" + assert_string: "GoogleChrome-"