A script to keep Flash Player up to date

May 04, '11 07:30:00AM

Contributed by: phillymjs

Frequent security updates to Flash prompted me to write this script to keep Flash current on Intel Macs that I manage. While more recent versions of Flash can be configured to notify end users of available updates, this script will silently check and upgrade to a newer version if one is available.

It works by checking the installed version of Flash (if any) against the version number available for Mac Safari/Firefox/Opera on Adobe's About Flash page. If the two are different, it downloads the DMG of the latest Flash installer to the same folder where the script resides, silently mounts the DMG, and executes the installer package buried in the 'Install Flash' application. It runs completely silently and will log all of its activities to a file for later review. If Flash is not present, it will be installed on the system. In its current form it will not advise users to quit their browsers, because it was written to be run during off hours on machines sitting at the login window.

To use it, save the script file wherever you like on your system (I make a directory called 'Management' in /Library), and make it executable. Run it manually via Terminal, or via a launchd item for 'set it and forget it' operation. It needs to be run with root privileges, or the installation will fail.

Here's the script:

# Script to download and install Flash Player.
# Only works on Intel systems.


# Are we running on Intel?
if [ '`/usr/bin/uname -p`'="i386" -o '`/usr/bin/uname -p`'="x86_64" ]; then
	# Get the latest version of Flash Player available from Adobe's About Flash page.
	latestver=`/usr/bin/curl -s http://www.adobe.com/software/flash/about/ | /usr/bin/grep -A2 "Macintosh - OS X" | /usr/bin/grep -A1 "Safari" | /usr/bin/sed -e 's/<[^>][^>]*>//g' -e '/^ *$/d' | /usr/bin/tail -n 1 | /usr/bin/awk '{print $1}'`
	# Get the version number of the currently-installed Flash Player, if any.
	if [ -e "/Library/Internet Plug-Ins/Flash Player.plugin" ]; then
		currentinstalledver=`/usr/bin/defaults read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version CFBundleShortVersionString`
	# Compare the two versions, if they are different of Flash is not present then download and install the new version.
	if [ "${currentinstalledver}" != "${latestver}" ]; then
        /bin/echo "`date`: Current Flash version: ${currentinstalledver}" >> ${logfile}
		/bin/echo "`date`: Available Flash version: ${latestver}" >> ${logfile}
		/bin/echo "`date`: Downloading newer version." >> ${logfile}
		/usr/bin/curl -s -o `/usr/bin/dirname $0`/flash.dmg http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_osx_intel.dmg
		/bin/echo "`date`: Mounting installer disk image." >> ${logfile}
		/usr/bin/hdiutil attach `dirname $0`/flash.dmg -nobrowse -quiet
		/bin/echo "`date`: Installing..." >> ${logfile}
		/usr/sbin/installer -pkg /Volumes/Flash\ Player/Install\ Adobe\ Flash\ Player.app/Contents/Resources/Adobe\ Flash\ Player.pkg -target / > /dev/null
		/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 `/usr/bin/dirname $0`/${dmgfile}
		newlyinstalledver=`/usr/bin/defaults read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version CFBundleShortVersionString`
        if [ "${latestver}" = "${newlyinstalledver}" ]; then
            /bin/echo "`date`: SUCCESS: Flash has been updated to version ${newlyinstalledver}" >> ${logfile}
            /bin/echo "`date`: ERROR: Flash update unsuccessful, version remains at {currentinstalledver}." >> ${logfile}
            /bin/echo "--" >> ${logfile}
    # If Flash is up to date already, just log it and exit.       
		/bin/echo "`date`: Flash is already up to date, running ${currentinstalledver}." >> ${logfile}
        /bin/echo "--" >> ${logfile}
	/bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}

[crarko adds: I haven't tested this one. I've mirrored a copy of the script here.]

Comments (9)

Mac OS X Hints