forked from ryangball/chrome-enable-autoupdates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome-enable-autoupdates.sh
executable file
·70 lines (59 loc) · 2.65 KB
/
chrome-enable-autoupdates.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# This script enables system wide automatic updates for Google Chrome.
# Written by Ryan Ball after somehow becoming responsible for it
# Spawned from this thread: https://www.jamf.com/jamf-nation/discussions/23323/how-to-update-chrome-automatically
# Bash version of this script (which I also contributed a tiny piece to):
# https://github.com/hjuutilainen/adminscripts/blob/master/chrome-enable-autoupdates.py
chromePath="/Applications/Google Chrome.app"
chromeVersion=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" CFBundleShortVersionString)
chromeMajorVersion=$(/usr/bin/awk -F '.' '{print $1}' <<< "$chromeVersion")
updateURL=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" KSUpdateURL)
productID=$(/usr/bin/defaults read "$chromePath/Contents/Info.plist" KSProductID)
exitCode="0"
# Check if Chrome is installed
if [[ ! -e "$chromePath" ]]; then
echo "Error: $chromePath not found"
exit 1
fi
# Determine KeystoneRegistration.framework path
if [[ $chromeMajorVersion -ge 75 ]] ; then
frameworkPath="$chromePath/Contents/Frameworks/Google Chrome Framework.framework/Versions/Current/Frameworks/KeystoneRegistration.framework"
resourcesPath="$chromePath/Contents/Frameworks/Google Chrome Framework.framework/Versions/Current/Resources"
else
frameworkPath="$chromePath/Contents/Versions/$chromeVersion/Google Chrome Framework.framework/Versions/A/Frameworks/KeystoneRegistration.framework"
resourcesPath="$chromePath/Contents/Versions/$chromeVersion/Google Chrome Framework.framework/Versions/A/Resources"
fi
# Check if framework exists
if [[ ! -e "$frameworkPath" ]]; then
echo "Error: KeystoneRegistration.framework not found"
exit 1
fi
# Install the current Keystone
if ! "$frameworkPath/Resources/ksinstall" --install "$frameworkPath/Resources/Keystone.tbz" --force 2>/dev/null ; then
exitCode="$?"
echo "Error: Keystone install failed with code $exitCode"
exit "$exitCode"
else
echo "Keystone installed"
fi
# Registers Chrome with Keystone
if ! /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/ksadmin \
--register \
--productid "$productID" \
--version "$chromeVersion" \
--xcpath "$chromePath" \
--url "$updateURL" \
--tag-path "$chromePath/Contents/Info.plist" \
--tag-key "KSChannelID" \
--brand-path "/Library/Google/Google Chrome Brand.plist" \
--brand-key "KSBrandID" \
--version-path "$chromePath/Contents/Info.plist" \
--version-key "KSVersion"
then
exitCode="$?"
echo "Error: Failed to register Chrome with Keystone - code $exitCode"
exit "$exitCode"
else
echo "Registered Chrome with Keystone"
fi
exit 0