Google install script and version checking

ithin6
New Contributor

Need a bit of help. found a script here that installs google that works great and downloads the current version. We have a problem where some systems have legacy data from older version of Google, (this legacy data has them showing up in a vulnerability report by security) so i have updated the script it now removes everything Google related then it downloads the update and converts it to a pkg so it gets a receipt and also saves the user profile and restores it after the install. but I want it to compare the dmg version it downloads to the version installed. This way I can have the script set to run once a week and it will look at the downloaded version and see if the version matches whats installed if so it ends the script if the versions are different it will run the process of installing the update. Now i have seen in like the Firefox script a comparison is done, I am new to scripting in the Mac computers so any help would be great and save me hours if not days of research at this point.

4 REPLIES 4

BOBW
Contributor II

Hi @ithin6 I am currently using this script to look at the mounted DMG of google chrome and what version is inside it, It will then determine if it has to install and create a PKG file ready for upload to the JSS.

You could hash out the line which creates the package I guess and it should be fine to go (line 50 - 51) - creates a log file in Library/Logs

If anyone else has any ideas on how to do this better please feel free to edit

#!/bin/bash
## Created by David Coupe June 2018
## 
## set variables
dmgfile="googlechrome.dmg"
volname="Google Chrome"
logfile="/Library/Logs/GoogleChromeInstallScript.log"
url='https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )

# Set Log file
/bin/echo "--" >> ${logfile}

echo $(date) >> ${logfile}

## Read current version from applications folder
if [ -e /Applications/Google Chrome.app/Contents/Info.plist ]; then
    currentvers=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
    echo "current version $currentvers" >> ${logfile}
fi

#Download latest version from Web
echo "Downloading from web" >> ${logfile}
/usr/bin/curl -s -o /tmp/${dmgfile} ${url}

#mount Disk image
echo "Mount DMG" >> ${logfile}
/usr/bin/hdiutil attach /tmp/${dmgfile} -nobrowse -quiet

## Read latest version from mounted DMG
echo "get latest version" >> ${logfile}
latestver=$(defaults read "/Volumes/Google Chrome/Google Chrome.app/Contents/Info.plist" CFBundleShortVersionString)
echo "latest version $latestver" >> ${logfile}

## Determine if the application needs updating
echo "determine difference" >> ${logfile}
if [ "${currentvers}" != "${latestver}" ]; then
    echo "versions are different, creating pkg" >> ${logfile}

## Copy download to Applications folder, unmount and delete DMG
    ditto -rsrc "/Volumes/Google Chrome/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 Google | awk '{print $1}') -quiet
        /bin/sleep 10
        /bin/echo "`date`: Deleting disk image." >> ${logfile}
        /bin/rm /tmp/${dmgfile}

## Build PKG to Desktop
    echo "create pkg" >> ${logfile}
    sudo pkgbuild --install-location /Applications --component "/Applications/Google Chrome.app" "/Users/$loggedInUser/Desktop/Google Chrome" ${latestver}".pkg"

else 

## if latest version is equal then just unmount the DMG and delete
echo "Same Version, closing and unmounting DMG" >> ${logfile}
       /bin/sleep 10
        /bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
        /usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep Google | awk '{print $1}') -quiet
        /bin/sleep 10
        /bin/echo "`date`: Deleting disk image." >> ${logfile}
        /bin/rm /tmp/${dmgfile}

fi

exit 0
exit 1

mm2270
Legendary Contributor III

Google maintains a page that lists the versions of Google Chrome for various platforms going back quite a ways. I forget now who first posted about this here, or I would give them the credit for mentioning it. The URL is "https://omahaproxy.appspot.com/history"

Here's code you can use to check for the latest stable Mac Google Chrome release from that page. This should match the version that is on the disk image that gets downloaded. I don't think I've seen a case yet where they don't match up, but that's always a possibility.

curl -s "https://omahaproxy.appspot.com/history" | awk -F',' '/mac,stable/{print $3; exit}'

The above prints back

68.0.3440.106

BOBW
Contributor II

updating script now to do this instead of the long way I was doing it.....

BOBW
Contributor II

OK, try this one, instead of downloading the DMG each time it references the url from @mm2270 (thanks) and will only download and create the pkg if it is different

#!/bin/bash

## set variables
dmgfile="googlechrome.dmg"
volname="Google Chrome"
logfile="/Library/Logs/GoogleChromeInstallScript.log"
url='https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg'
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
webvers=$(curl -s "https://omahaproxy.appspot.com/history" | awk -F',' '/mac,stable/{print $3; exit}')

# Set Log file
/bin/echo "--" >> ${logfile}

echo $(date) >> ${logfile}

## Read current version from applications folder
if [ -e /Applications/Google Chrome.app/Contents/Info.plist ]; then
    currentvers=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
    echo "current version $currentvers" >> ${logfile}
else
        echo "Chrome not installed downloading from web" >> ${logfile}
fi

echo "determine difference" >> ${logfile}
echo "current version $currentvers web version $webvers" >> ${logfile}
if [ "${currentvers}" != "${webvers}" ]; then
    echo "versions are different, creating pkg" >> ${logfile}

#Download latest version from Web
echo "Downloading from web" >> ${logfile}
/usr/bin/curl -s -o /tmp/${dmgfile} ${url}

mount Disk image
echo "Mount DMG" >> ${logfile}
/usr/bin/hdiutil attach /tmp/${dmgfile} -nobrowse -quiet

## Copy download to Applications folder, unmount and delete DMG
    echo "copying app to applications folder" >> ${logfile}
    ditto -rsrc "/Volumes/Google Chrome/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 Google | awk '{print $1}') -quiet
        /bin/sleep 10
        /bin/echo "`date`: Deleting disk image." >> ${logfile}
        /bin/rm /tmp/${dmgfile}
        sleep 5

## Build PKG to Desktop
    echo "create pkg" >> ${logfile}
    sudo pkgbuild --install-location "/Applications" --component "/Applications/Google Chrome.app" "/Users/${loggedInUser}/Desktop/Google Chrome ${webvers}.pkg"

else 

    echo "No Change Required" >> ${logfile}

fi

exit 0