How to update Chrome automatically

LewisLebentz
New Contributor II

I have just written a blog post on how to automatically update Google Chrome using Jamf if anyone is interested. You can find my blog post here:

https://lew.im/2017/03/auto-update-chrome/

I have seen a few different methods posted here, but most require some admin intervention (uploading new packages, changing version numbers etc.) but this method is fully automated. Create the Extension Attribute, Smart Group and Policy and you're good to go! Every time Google release a new version of Chrome, this script will automatically grab it and install it on your Macs.

132 REPLIES 132

danlaw777
Contributor III

thanks @msw-sa Im going to get this script on my macs this weekend . i appreciate the help

jarredondo
New Contributor II

Thanks!

jarredondo
New Contributor II

@msw-sa This is awesome! I tried it out on a test unit, and it worked perfectly. If you don't mind me asking, what is your execution frequency set to and what is toggled on your maintenance tab?

Heavy_D
Contributor III

@ryan.ball I have not got any errors on this script but it should still be working well, that Python script works I tested that one very nice!

#!/bin/bash
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/$chromeVersion/Frameworks/KeystoneRegistration.framework"
    resourcesPath="$chromePath/Contents/Frameworks/Google Chrome Framework.framework/Versions/$chromeVersion/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

# Run preflight script to ensure suitable environment for Keystone installation
if ! "$resourcesPath/keystone_promote_preflight.sh" > /dev/null ; then
    exitCode="$?"
    echo "Error: keystone_promote_preflight.sh failed with code $exitCode"
    exit "$exitCode"
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

# Run postflight script to change owner, group, and permissions on the Chrome application
if ! "$resourcesPath/keystone_promote_postflight.sh" "$chromePath" > /dev/null ; then
    echo "Error: keystone_promote_postflight.sh failed with code $exitCode"
fi

exit 0

sdagley
Esteemed Contributor II

It looks like Google now offers their own .pkg installer for Chrome. Better yet, the postinstall script in the official .pkg sets up automatic updates. See the thread Updates to Google Chrome deployment for macOS for more information.

rpayne
Contributor II

@LewisLebentz Out of curiosity, what criteria did you use for your smart group? I don't see it outlined in your blog.

djacome
New Contributor

@LewisLebentz Thank you!!!! Any tips on Zero touch deploy?

dvasquez
Valued Contributor

the script still looks to be working well.

Dumb question, this script will enable a device running chrome and is an older version to update.

I understand the smart group and the extension attribute inclusion to achieve this. 

I just wanted to verify my thinking. 

Thank you for all the hard work!

kbednar
New Contributor II

Does anyone have an updated download link for Chrome? 
https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg is downloading 98.0.4758.102 instead of the current version (106.0.5249.61 at the time of this post).

rhooper
Contributor III

Will this work with the m1 devices? Also I see it is python below the shebang but I thought macs used python3. No?

rhooper
Contributor III

I found that when I ran the following script on an M1 device I was able to attain the chrome version 106.x.x.x and not downgraded to v98.x.x.x

I have not tested it on an Intel Mac yet but will. Tonight I tested this on 2 devices, wiping them and letting them instal version 104... then ran this script about a dozen times with great results each time!

#!/bin/sh

dmgfile="googlechrome.dmg"
volname="Google Chrome"
logfile="/Library/Logs/GoogleChromeInstallScript.log"

url='https://dl.google.com/chrome/mac/universal/stable/CHFA/googlechrome.dmg'

#url='https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmgThis url goes to a downgraded chrome version 98.x.x.x, so it is commented out.


/bin/echo "--" >> ${logfile}
/bin/echo "`date`: Downloading latest version." >> ${logfile}
/usr/bin/curl -s -o /tmp/${dmgfile} ${url}
/bin/echo "`date`: Mounting installer disk image." >> ${logfile}
/usr/bin/hdiutil attach /tmp/${dmgfile} -nobrowse -quiet
/bin/echo "`date`: Installing..." >> ${logfile}
ditto -rsrc "/Volumes/${volname}/Google Chrome.app" "/Applications/Google Chrome.app"
/bin/sleep 10
/bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
/usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep "${volname}" | awk '{print $1}') -quiet
/bin/sleep 10
/bin/echo "`date`: Deleting disk image." >> ${logfile}
/bin/rm /tmp/"${dmgfile}"

exit 0

kbednar
New Contributor II

Do you know if https://dl.google.com/chrome/mac/universal/stable/CHFA/googlechrome.dmg will continue to have the latest Chrome version or will the link need to be updated everytime?

@kbednar  I found that link url='https://dl.google.com/chrome/mac/universal/stable/CHFA/googlechrome.dmg' works, however it said that it could not update. 
But it does work after the user selects Enable Automatic updates in the Pop-up (drop-Down) window that appears.