-
-
Save talkingmoose/cc4b1d143bcdf7d6d670ab1b30565694 to your computer and use it in GitHub Desktop.
#!/bin/zsh | |
:<<ABOUT_THIS_SCRIPT | |
------------------------------------------------------------------------------- | |
Written by:William Smith | |
Professional Services Engineer | |
Jamf | |
[email protected] | |
https://gist.github.com/cc4b1d143bcdf7d6d670ab1b30565694 | |
Originally posted: January 14, 2020 | |
Updated: January 31, 2021 | |
Converted download to use Google's IT download URL. | |
https://support.google.com/chrome/a/answer/9915669 | |
Purpose: Checks version of latest available version of Google | |
Chrome online and compares with locally installed version. | |
Downloads and installs if installed version is older or doesn't | |
exist. | |
Instructions: Add this script to Jamf Pro. Set parameters: | |
Parameter 4: Language | |
Except where otherwise noted, this work is licensed under | |
http://creativecommons.org/licenses/by/4.0/ | |
"Always ready. Never prepared." | |
------------------------------------------------------------------------------- | |
ABOUT_THIS_SCRIPT | |
# enter the SHA 256 checksum for the download file (PKG) | |
# download the package and run '/usr/bin/shasum -a 256 /path/to/googlechrome.pkg' | |
# leave blank to to skip the checksum verification (less secure) or if using a $4 script parameter with Jamf Pro | |
sha256Checksum="" # e.g. "67b1e8e036c575782b1c9188dd48fa94d9eabcb81947c8632fd4acac7b01644b" | |
if [ "$4" != "" ] && [ "$sha256Checksum" = "" ] | |
then | |
sha256Checksum=$4 | |
fi | |
# FILE_LOCATIONS -------------------------------------------------------------- | |
# path to this script | |
currentDirectory=$( /usr/bin/dirname "$0" ) | |
# name of this script | |
currentScript=$( /usr/bin/basename -s .bash "$0" ) | |
# create log file in same directory as script | |
log="/Library/Logs/$currentScript.log" | |
# FUNCTIONS ------------------------------------------------------------------- | |
function logcomment() { | |
/bin/date "+%Y-%m-%d %H:%M:%S $1" >> "$log" | |
echo "$1" | |
} | |
function logresult() { | |
if [ $? = 0 ] ; then | |
/bin/date "+%Y-%m-%d %H:%M:%S $1" >> "$log" | |
else | |
/bin/date "+%Y-%m-%d %H:%M:%S $2" >> "$log" | |
fi | |
} | |
# BEGIN SCRIPT ---------------------------------------------------------------- | |
# specify the app bundle name | |
appName="Google Chrome.app" | |
# specify the app bundle name | |
packageName="googlechrome.pkg" | |
# specify the app process name | |
processName="Google Chrome" | |
# check whether application process is running | |
check=$( /usr/bin/pgrep "$processName") | |
if [ "$check" != "" ]; then | |
# get currently logged in user | |
currentUser=$( /usr/bin/stat -f "%Su" /dev/console ) | |
echo "Current user is $currentUser" | |
# uncomment the next two lines if running this script in Jamf Pro Self Service | |
# theCommand="display dialog \"Google Chrome app is currently running. Quit Chrome and try again.\" buttons {\"Stop\"} default button {\"Stop\"} with icon file posix file \"/Applications/Google Chrome.app/Contents/Resources/app.icns\"" | |
# /bin/launchctl asuser "$currentUser" sudo -iu "$currentUser" /usr/bin/osascript -e "$theCommand" | |
echo "$processName is running. Aborting script" | |
exit 0 | |
fi | |
# define download url | |
downloadURL="https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg" # regular release | |
# downloadURL="https://dl.google.com/chrome/mac/beta/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg" # beta release | |
# get the latest version of Google Chrome available from omahaproxy.appspot.com page. | |
latestVersion=$( /usr/bin/curl -s https://omahaproxy.appspot.com/history | awk -F',' '/mac,stable/{print $3; exit}' ) | |
logcomment "Latest version of Google Chrome: $latestVersion" | |
logcomment "Latest version of $appName: $latestVersion" | |
# Get the version number of the currently-installed app, if any. | |
if [ -e "/Applications/$appName" ]; then | |
installedVersion=$( /usr/bin/defaults read "/Applications/$appName/Contents/Info.plist" CFBundleShortVersionString ) | |
echo "Installed version of $appName: $installedVersion" | |
if [ ${latestVersion} = ${installedVersion} ]; then | |
logcomment "$appName is current. Exiting." | |
exit 0 | |
fi | |
else | |
logcomment "$appName is either not installed or not up to date." | |
fi | |
# create temporary working directory | |
workDirectory=$( /usr/bin/basename "$0" ) | |
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" ) | |
echo "Creating working directory '$tempDirectory'" | |
# change directory to temporary working directory | |
echo "Changing directory to working directory '$tempDirectory'" | |
cd "$tempDirectory" | |
# downloading software | |
logcomment "Downloading installer..." | |
/usr/bin/curl "$downloadURL" \ | |
--location \ | |
--silent \ | |
--output "googlechrome.pkg" | |
logresult "Downloaded installer." "Failed to download installer." | |
# checksum the download | |
downloadChecksum=$( /usr/bin/shasum -a 256 "$tempDirectory/$packageName" | /usr/bin/awk '{ print $1 }' ) | |
echo "Checksum for downloaded file: $downloadChecksum" | |
# install the download if checksum validates | |
if [ "$sha256Checksum" = "$downloadChecksum" ] || [ "$sha256Checksum" = "" ]; then | |
echo "Checksum verified. Installing software..." | |
# installing package | |
logcomment "Installing software..." | |
/usr/sbin/installer -pkg "$tempDirectory/$packageName" -target / | |
logresult "Installed $appName." "Failed to install $appName." | |
else | |
echo "Checksum failed. Recalculate the SHA 256 checksum and try again. Or download may not be valid." | |
exit 1 | |
fi | |
# delete working directory | |
logcomment "Deleting installer..." | |
/bin/rm -R "$tempDirectory" | |
logresult "Deleted working directory." "Failed to delete working directory." | |
# END SCRIPT ---------------------------------------------------------------- | |
exit 0 |
Hey Bill, thanks for the script!!
Line 114 appears to be missing the $ character before the "latestversion" variable name - as it stands this writes "Latest version of Google Chrome: latestVersion" to the log file for me.
Currently: logcomment "Latest version of Google Chrome: latestVersion"
Fixed: logcomment "Latest version of Google Chrome: $latestVersion"
Edit - maybe this line is redundant and just needs to be removed though, on second look line 116 seems to be writing the same info to the log? (I had originally assumed one was outputting installed version and one available.. but that doesn't seem to be the case)
Also, any reason you don't do the version check before the check to see if the app is running? For self service, this would seem to remove an unnecessary prompt - if the browser is already up to date there's no reason to tell the user they need to exit Chrome and try again just to have the script detect that it's up to date and exit? (I ended up taking lines 112-128 and inserted them just before line 88 to accomplish this - this way I'm only telling my users to exit Chrome if there's actually an update available)
-Alex
Hi @irodeabikeonce!
Thanks for the catching the typo. I actually have a newer version of the script that I failed to upload. It still had the typo, but takes @greatkemo's request into account to get the installer package instead.
This newer version may address some of your other questions too. Haven't tested it lately, but I believe it worked when I made the changes a while back.
Hi @talkingmoose
looks like that the Download URL for Chrome does not provide a Version Number anymore?
After running the script I get the following error in the Jamf Log:
Script result: Latest version of Google Chrome:
Latest version of Google Chrome.app:
Installed version of Google Chrome.app: 123.0.6312.107
/Library/Application Support/JAMF/tmp/talkingmoose_Download and install Google Chrome.zsh:122: parse error: condition expected: =
Creating working directory '/private/tmp/talkingmoose_Download and install Google Chrome.zsh.Lnb2G3'
Changing directory to working directory '/private/tmp/talkingmoose_Download and install Google Chrome.zsh.Lnb2G3'
Downloading installer...
And thanks a million for all your great work! :-)
Hey Bill,
Maybe you can update this script to point to Google pkg instead.
https://support.google.com/chrome/a/answer/9915669?hl=en
https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
might make things a little easier.
Love your work,
Kamal