Wednesday, November 5, 2014

chrome for enterprise auto download

In a work environment normally you want to download one copy of an update to one computer, and then copy it to the rest of the computers.  This way you don't clog up your office's internet connection.  While proxys can work, they are often tricky to configure.

Google has a version of chrome that will install for all users on a computer, that you can manage (like disable group updates, and configure some other settings).  Details are at: http://wpkg.org/Google_Chrome.  They also have a script that will download proper version of chrome and rename it so you can deploy it using a tool to the computers in your enterprise (which is designed to work with their deployment tool but I made it work with some slight modifications).

Chrome has an rss feed at http://googlechromereleases.blogspot.com/ which will notify you when there's an update.  While you could check it every day, how likely are you going to miss the day it came out, and then end up either downloading it during the day (clogging people's bandwidth), or waiting another day to schedule the download?
Below is my batch script for checking the rss feed, and if it sees there's an updated chrome, will call a script that download it automatically.

Now when you see there's a new version of chrome, it's already downloaded (if you scheduled the checking script to run every night).  I then create a package using local update publisher or wsus package publisher.


rem -----------------------------------------------------------------------------------------------
@echo off
set updatesloc=\\server\share\folder\google-chrome
rem set debug=1 if you have any problems.
set debug=0
if %debug%==1 echo grabbing the feed at %time%
wget http://googlechromereleases.blogspot.com/ -O %temp%\chrome-updates-feed.html
rem searching the feed for the current chrome version, and breaking out as soon as we
rem find the first one (that's not for chrome OS).

if %debug%==1 echo searching the downloaded feed for the current version at %time%
for /f "tokens=8" %%v in ('find /i "The stable channel has been updated to " %temp%\Chrome-updates-feed.html ^|find /v "Chrome OS"') do (
set curver=%%v
goto endverfind
)
:endverfind

if %debug%==1 echo searching the directory of downloaded updates to see if we already have the current version %time%
rem if the curver string length is less then three characters it's probably not valid.
rem google uses very long version numbers like: 38.0.2125.111
if "%curver:~3,1%"=="" goto end

for /f "tokens=1" %%d in ('dir /s /b %updatesloc% ^|find /c "%curver%"') do set curverdownloaded=%%d
if %debug%==1 echo search complete now to figure out what to do %time%
if %curverdownloaded%==0 goto downloadnewver
if %curverdownloaded%==0 goto gotcurver

:gotcurver
echo got the current version, %curver% nothing to do
goto end

:downloadnewver
echo need to download the newest version %curver%, at %time%
c:\windows\syswow64\cscript.exe %updatesloc%\update-chrome.vbs
goto end

:end
echo %time%
rem -------------------------------------------------------------------


my modified download vbscript (based heavily on the script at http://wpkg.org/Google_Chrome)
make sure you've downloaded dsofile
www.microsoft.com/downloads/details.aspx?FamilyID=9ba6fac6-520b-4a0a-878a-53ec8300c4c2&DisplayLang=en
and that you have wget in your path, wget is needed for the batch file above also.
http://gnuwin32.sourceforge.net/packages/wget.htm


'------------------------------------------------------------------------
' update-chrome.vbs -- stored in %updatesloc%\google-chrome
'from http://wpkg.org/Google_Chrome
Option Explicit
Dim objFSO, objFile, strFileProperties, objShell, strChromePath, strChromeURL
Dim strVersion, objResult, strChromeFilename, objOleFile, arrComments
Dim strTemplateFilename, ForReading, ForWriting, strText
Dim strNewText

strChromePath = "j:\patches\google-chrome\"
'strChromePath = "c:\downloads\"
strChromeFilename = "GoogleChromeStandaloneEnterprise.msi"
strTemplateFilename = "google-chrome-template.xml"
strChromeURL = "https://dl.google.com/edgedl/chrome/install/" & _
strChromeFilename

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOleFile = CreateObject("DSOFile.OleDocumentProperties")

objShell.CurrentDirectory = strChromePath
' wget downloaded from http://users.ugent.be/~bpuype/wget/
objResult = objShell.Run("wget --limit-rate=200k --no-check-certificate " & strChromeURL, 1, True)
If objFSO.FileExists(strChromePath & strChromeFilename) Then
' Grab version number. Requires Office installation, or DSOFile.dll
' from http://support.microsoft.com/kb/224351
objOleFile.Open(strChromePath & strChromeFilename)
arrComments = Split(objOleFile.SummaryProperties.Comments, " ", 2)
strVersion = arrComments(0)
objOleFile.Close

' Make a copy of the file
Set objFile = objFSO.GetFile(strChromePath & strChromeFilename)
objFile.Copy strChromePath & "GoogleChromeStandaloneEnterprise-" & _
strVersion & ".msi", True
' Delete the original file
objFile.Delete True
' Update package definitions
' updateXML strTemplateFilename, _
' "..\..\packages\google-chrome.xml" ' legacy tree
' updateXML strTemplateFilename, _
' "..\..\dev\packages\google-chrome.xml" ' dev tree
' updateXML strTemplateFilename, _
' "..\..\stable\packages\google-chrome.xml" ' stable tree
Else
MsgBox "Selected file does not exist!"
End If

'Sub updateXML(strTemplateFilename, strPackageFilename)
' Update package definition
' ForReading = 1
' ForWriting = 2
' Set objFile = objFSO.OpenTextFile(strTemplateFilename, ForReading)
' strText = objFile.ReadAll
' objFile.Close
' strNewText = Replace(strText, "__VERSION__", strVersion)
 '
' Set objFile = objFSO.OpenTextFile(strPackageFilename, ForWriting)
' objFile.WriteLine strNewText
' objFile.Close
'End Sub
'-----------------------------------------------------------------------------