Google Chrome may not be able to keep itself updated - hit or miss

atomczynski
Contributor III

I have two scripts for Google Chrome and it's a hit or miss if Google Chrome will auto update itself or not.

Thoughts?

Download latest version

#####################################################################################################
#
# ABOUT THIS PROGRAM
#
# NAME
#   GoogleChromeInstall.sh -- Installs the latest Google Chrome version
#
# SYNOPSIS
#   sudo GoogleChromeInstall.sh
#
####################################################################################################
#
# HISTORY
#
#   Version: 1.0
#
#
####################################################################################################
# Script to download and install Google Chrome.
# Only works on Intel systems.
dmgfile="googlechrome.dmg"
volname="Google Chrome"
logfile="/Library/Logs/GoogleChromeInstallScript.log"
url='https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
# Are we running on Intel?
if [ '`/usr/bin/uname -p`'="i386" -o '`/usr/bin/uname -p`'="x86_64" ]; then
        /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}"
else
    /bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}
fi
exit 0

Auto Update

#!/bin/bash
#####################################################################################################
# https://github.com/ryangball/chrome-enable-autoupdates/blob/master/chrome-enable-autoupdates.sh
# for more information visit: https://www.jamf.com/jamf-nation/discussions/28435/force-enable-google-chrome-automatic-updates
# Adam T
#
# 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
3 REPLIES 3

sdagley
Honored Contributor II

@atomczynski Just use Google's enterprise .pkg installer which sets up autoupdate in the postinstall (I'd provide a link, but I use AutoPkg to grab it)

atomczynski
Contributor III

If deployed "on top" of the current install, will it erase the user's profile (bookmarks, history, cookies)?

Is this available for all or only Google Enterprise customers?

sdagley
Honored Contributor II

It just installs the app, so no problems running it on top of existing.

Here's the download page for the .pkg version of Chrome I mentioned: https://chromeenterprise.google/browser/download/ You should find info linked from that page regarding any restrictions on its use.