1#!/bin/bash
2chromePath="/Applications/Google Chrome.app"
3chromeVersion=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" CFBundleShortVersionString)
4chromeMajorVersion=$(/usr/bin/awk -F '.' '{print $1}' <<< "$chromeVersion")
5updateURL=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" KSUpdateURL)
6productID=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" KSProductID)
7exitCode="0"
8
9# Check if Chrome is installed
10if [[ ! -e "$chromePath" ]]; then
11 echo "Error: $chromePath not found"
12 exit 1
13fi
14
15# Determine KeystoneRegistration.framework path
16if [[ $chromeMajorVersion -ge 75 ]] ; then
17 frameworkPath="$chromePath/Contents/Frameworks/Google Chrome Framework.framework/Versions/$chromeVersion/Frameworks/KeystoneRegistration.framework"
18 resourcesPath="$chromePath/Contents/Frameworks/Google Chrome Framework.framework/Versions/$chromeVersion/Resources"
19else
20 frameworkPath="$chromePath/Contents/Versions/$chromeVersion/Google Chrome Framework.framework/Versions/A/Frameworks/KeystoneRegistration.framework"
21 resourcesPath="$chromePath/Contents/Versions/$chromeVersion/Google Chrome Framework.framework/Versions/A/Resources"
22fi
23
24# Check if framework exists
25if [[ ! -e "$frameworkPath" ]]; then
26 echo "Error: KeystoneRegistration.framework not found"
27 exit 1
28fi
29
30# Run preflight script to ensure suitable environment for Keystone installation
31if ! "$resourcesPath/keystone_promote_preflight.sh" > /dev/null ; then
32 exitCode="$?"
33 echo "Error: keystone_promote_preflight.sh failed with code $exitCode"
34 exit "$exitCode"
35fi
36
37# Install the current Keystone
38if ! "$frameworkPath/Resources/ksinstall" --install "$frameworkPath/Resources/Keystone.tbz" --force 2>/dev/null ; then
39 exitCode="$?"
40 echo "Error: Keystone install failed with code $exitCode"
41 exit "$exitCode"
42else
43 echo "Keystone installed"
44fi
45
46# Registers Chrome with Keystone
47if ! /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/ksadmin
48 --register
49 --productid "$productID"
50 --version "$chromeVersion"
51 --xcpath "$chromePath"
52 --url "$updateURL"
53 --tag-path "$chromePath/Contents/Info.plist"
54 --tag-key "KSChannelID"
55 --brand-path "/Library/Google/Google Chrome Brand.plist"
56 --brand-key "KSBrandID"
57 --version-path "$chromePath/Contents/Info.plist"
58 --version-key "KSVersion"
59then
60 exitCode="$?"
61 echo "Error: Failed to register Chrome with Keystone - code $exitCode"
62 exit "$exitCode"
63else
64 echo "Registered Chrome with Keystone"
65fi
66
67# Run postflight script to change owner, group, and permissions on the Chrome application
68if ! "$resourcesPath/keystone_promote_postflight.sh" "$chromePath" > /dev/null ; then
69 echo "Error: keystone_promote_postflight.sh failed with code $exitCode"
70fi
71
72exit 0