Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to keep Flash Player up to date Install
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:
#!/bin/sh
# Script to download and install Flash Player.
# Only works on Intel systems.

dmgfile="flash.dmg"
volname="Flash"
logfile="/Library/Logs/FlashUpdateScript.log"

# 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`
	else
		currentinstalledver="none"
	fi
	# 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}
        else
            /bin/echo "`date`: ERROR: Flash update unsuccessful, version remains at {currentinstalledver}." >> ${logfile}
            /bin/echo "--" >> ${logfile}
		fi
    # If Flash is up to date already, just log it and exit.       
	else
		/bin/echo "`date`: Flash is already up to date, running ${currentinstalledver}." >> ${logfile}
        /bin/echo "--" >> ${logfile}
	fi	
else
	/bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}
fi

[crarko adds: I haven't tested this one. I've mirrored a copy of the script here.]
    •    
  • Currently 3.18 / 5
  You rated: 1 / 5 (11 votes cast)
 
[11,360 views]  

A script to keep Flash Player up to date | 9 comments | Create New Account
Click here to return to the 'A script to keep Flash Player up to date' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to keep Flash Player up to date
Authored by: chabig on May 04, '11 08:39:55AM

I solved the problem a different way. I deleted Flash completely. If I absolutely must view a flash website I use Chrome, which has Flash built-in.



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: dfbills on May 04, '11 09:52:51AM

Funny.

---
-d



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: leamanc on May 05, '11 12:57:28PM

Maybe, but it is effective, and he's not the first person I've seen do it. I think it's going to become a pretty popular solution for those who are tech-inclined enough to know how to uninstall or disable plugins.



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: maelcum on May 04, '11 10:34:41AM
nice!!

you could shorten the extraction of the current version on adobes site to:
	latestver=`/usr/bin/curl -s http://www.adobe.com/software/flash/about/ | sed -n '/Safari/,/<\/tr/s/[^>]*>\([0-9].*\)<.*/\1/p'`
though thats just fine tuning.

thanks!

[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: Drizzt on May 04, '11 11:28:03AM

It works, for now at least!
I just tested it on a outdated iMac I had.



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: fud on May 04, '11 11:43:07AM

Now in beta, Flash 10.3 has a System Preference panel that provides a more user friendly interface, including Update checking. Something Adobe should have done long ago.

Of course ClickToFlash works great in Safari to avoid Flash, except when absolutely necessary. I wouldn't auto update any software.

http://labs.adobe.com/technologies/flashplatformruntimes/flashplayer10-3/



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: kaidoh on May 04, '11 02:18:22PM

You can call me a chicken, but there are people out there who consider it no good advise at all to give a silent install script root privileges allowing it to install stuff around their machines without users even realizing it (especially when that stuff comes from a company infamous for their installation abominations). This is the fast lane to a completely messed up system.
I can't believe this got published without any warning words, so I'll add them here: do this if you must, but only do it, if you fully understand what you are doing and what the consequences might be. Better yet: don't do it.



[ Reply to This | # ]
A script to keep Flash Player up to date
Authored by: metiure on May 05, '11 01:34:23AM

"I can't believe this got published without any warning words, so I'll add them here: do this if you must, but only do it, if you fully understand what you are doing and what the consequences might be. Better yet: don't do it."

Yep! Can't believe it too.



[ Reply to This | # ]
Some small changes and corrections
Authored by: juanfal on May 13, '11 05:48:41AM
Only made some corrections (added a control for sudo using, and a $ before a variable in an echo command) and added also a more verbose interface, explaining the current user what is going on:
#!/bin/sh
# Script to download and install Flash Player.
# Only works on Intel systems.
# 

if [[ "$USER" != "root" ]]; then
  echo "You must run this script as root."
  exit 1
fi

dmgfile="flash.dmg"
volname="Flash"
logfile="/Library/Logs/FlashUpdateScript.log"
echo "Updating Flash player…"
# 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/ | sed -n '/Safari/,/<&#92;/tr/s/[^>]*>\([0-9].*\)<.*/&#92;1/p'`
	# 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&#92; Plug-Ins/Flash&#92; Player.plugin/Contents/version CFBundleShortVersionString`
	else
		currentinstalledver="none"
	fi
	echo "Installed version:                 &#36;currentinstalledver"
	echo "Currently last version to install: &#36;latestver"
	# Compare the two versions, if they are different of Flash is not present then download and install the new version.
	if [ "&#36;{currentinstalledver}" != "&#36;{latestver}" ]; then
		echo "UPDATING…"
    /bin/echo "`date`: Current Flash version: &#36;{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}
            echo "SUCCESS: Flash has been updated to version ${newlyinstalledver}"
        else
            /bin/echo "`date`: ERROR: Flash update unsuccessful, version remains at ${currentinstalledver}." >> ${logfile}
            /bin/echo "--" >> ${logfile}
            echo "ERROR: Flash update unsuccessful, version remains at ${currentinstalledver}."
		fi
    # If Flash is up to date already, just log it and exit.       
	else
		/bin/echo "`date`: Flash is already up to date, running ${currentinstalledver}." >> ${logfile}
    /bin/echo "--" >> ${logfile}
		echo "Flash is already up to date, running ${currentinstalledver}."
	fi	
else
	/bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}
	echo "ERROR: This script is for Intel Macs only."
fi


[ Reply to This | # ]