Extension Attributes - Gathering Versions

stevewood
Honored Contributor II
Honored Contributor II

One of the attributes that I wrote last year was to gather the version of
Flash. Recently I noticed that it stopped working, and realized it was
because I made assumptions about Flash that were not good. I re-wrote the
attribute and realized I could use it for anything I wanted to grab version
information on. So, I tweaked the one line command for Firefox,
Silverlight, and Growl. Here is the full Flash script:

--- code ---

#!/bin/bash

# get the current version of the flash player plug in

flashVersion=`/bin/cat /Library/Internet Plug-Ins/Flash
Player.plugin/Contents/Info.plist | grep -A 1 -m 1
CFBundleShortVersionString | grep string | sed 's/[/]//' | sed
's/<string>//g'`

echo "<result>$flashVersion</result>"

exit 0

--- /code ---

So, taking that one line you can edit it out for whatever app you want:

Firefox: ffVersion=`/bin/cat /Applications/Firefox.app/Contents/Info.plist
| grep -A 1 -m 1 CFBundleShortVersionString | grep string | sed 's/[/]//' |
sed 's/<string>//g'`

Silverlight: silverlightVersion=`cat /Library/Internet
Plug-Ins/Silverlight.plugin/Contents/Info.plist | grep -m 1 3. | sed
's/[/]//' | sed 's/<string>//g' | awk '{ print $1 }'`

Growl: growlVersion=`/bin/cat
/Library/PreferencePanes/Growl.prefPane/Contents/Info.plist | grep -A 1 -m 1
CFBundleShortVersionString | grep string | sed 's/[/]//' | sed
's/<string>//g'`

(Notice on the Silverlight one I had to use the awk command. I was getting
a strange error if I didn't)

Anyway, I wanted to share this with everyone in case someone else could use
it.

Happy Caspering!

Steve Wood
Director of IT
swood at integer.com

The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475

8 REPLIES 8

nessts
Valued Contributor II

or
$ffVersion=defaults read /Applications/Firefox.app/Contents/Info CFBundleShortVersionString

returns just the version.
--
Todd Ness
Technology Consultant/Non-Windows Services
Americas Regional Delivery Engineering
HP Enterprise Services

rockpapergoat
Contributor III

if it's a plist, you can get just the key you need without chopping up strings, like so:

defaults read /Library/Internet Plug-Ins/Flash Player.plugin/Contents/Info CFBundleShortVersionString

here's an example of doing so for all apps, etc.

https://github.com/rockpapergoat/scripts/blob/master/misc/get_app_version.rb

bentoms
Release Candidate Programs Tester

or http://wp.me/p12A66-1W for silverlight.. not as universal though

#!/bin/sh
if [ -e /Library/Internet Plug-Ins/Silverlight.plugin ]; then
result="$(defaults read /Library/Internet Plug-Ins/Silverlight.plugin/Contents/Info SilverlightVersion)"
echo "$result"
else
echo "Not installed"
fi

stevewood
Honored Contributor II
Honored Contributor II

But it's so much more fun to play with *NIX commands…. :-)
On Thu, Sep 8, 2011 at 10:57 AM, Nate St. Germain <nate at techsuperpowers.com>wrote:

Clearly I was not thinking straight, and not reading the archives of the
list closely enough, because now i remember that we had a discussion a while
ago about using "defaults read" to do this.

Oh well, it was a fun exercise in bash. :-)

Steve Wood
Director of IT
swood at integer.com

The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475

Not applicable

Speaking of Flash, I found this script a while ago...unfortunately I can't remember where. I think it was MacOSXHints. While I haven't implemented it yet, I've been using it successfully on my own machine.

It has some fun uses of awk, grep, sed, tail AND defaults. With capser, the script could be adapted fairly easily to notify users that flash is being updated. If a browser is running, it works, but does not take effect until a browser restart.

Makes keeping up with flash much more attractive.

-------------------

#!/bin/sh
# Script to download and install Flash Player.
# Only works on Intel systems.

dmgfile="flash.dmg"
volname="Flash"
logfile="/Library/Logs/FlashUpdateScript.log"
workingdir="/private/tmp" # This might need to be used in order to prevent everything being written to a non-writable directory on the casper server. Replace /usr/bin/dirname with $workingdir "

# 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 to `usr/bin/dirname $0`" >> ${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

rob_potvin
Contributor III
Contributor III

Thanks this rocks, updated it to work with Promethean ActivInpsire

#!/bin/bash

# get the current version of the flash player plug in

aiverion=/bin/cat /Applications/Promethean/Activsoftware Inspire/Inspire.app/Contents/Info.plist | grep -A 1 -m 1 CFBundleGetInfoString | grep string | sed 's/[/]//' | sed 's/<string>//g'

echo "<result>$aiverion</result>"

exit 0

Thanks

It rocks

Apfelpom
New Contributor III

Adobe updated the download Path syntax. Actually the latest Flash-Player version is founded at:

http://fpdownload.macromedia.com/get/flashplayer/pdc/11.1.102.62/install_flash_player_osx.dmg

I've tried to put the latestver variable into the path but it forget the rest of the path:

/bin/echo "http://fpdownload.macromedia.com/get/flashplayer/pdc/${latestver}/install_flash_player_osx.dmg"

/install_flash_player_osx.dmgcom/get/flashplayer/pdc/11.1.102.62

But it works when latestver is a string.

Any Ideas?

Code to test:

#!/bin/bash

# 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}'`

echo $latestver

# echo URL
/bin/echo "http://fpdownload.macromedia.com/get/flashplayer/pdc/${latestver}/install_flash_player_osx.dmg"

# Set latestver as a string
latestver="11.1.102.62"

echo $latestver

# echo URL
/bin/echo "http://fpdownload.macromedia.com/get/flashplayer/pdc/${latestver}/install_flash_player_osx.dmg"

The output on my machine:

bash-3.2# ./test-echo.sh 
11.1.102.62
/install_flash_player_osx.dmgcom/get/flashplayer/pdc/11.1.102.62
11.1.102.62
http://fpdownload.macromedia.com/get/flashplayer/pdc/11.1.102.62/install_flash_player_osx.dmg

Thanks! Yann

rmanly
Contributor III

If you (or a script you find and plan to use) are ever doing that many pipes with grep, sed, awk, cut, or tr you need to get catonmat's e-books. http://www.catonmat.net/books/

I will work on the script as a whole at the end of the day but I had to fix this right now. XD

$ curl -s http://www.adobe.com/software/flash/about/ | sed -n '/Safari/{n;s/[[:blank:]]*<td>//;s#</td>##;p;}'
11.1.102.62
$ latestver=$(curl -s http://www.adobe.com/software/flash/about/ | sed -n '/Safari/{n;s/[[:blank:]]*<td>//;s#</td>##;p;}')
$ echo ${latestver} 
11.1.102.62

As far as what sed is doing.

-n tells it not to print by default
/Safari/ searches for Safari
n effectively gets the next line
s/[[:blank:]]*<td>// subs blank anything through <td> with nothing
s#</td>## subs trailing </td> with nothing uses # as delimiter so we don't have to escape / in </td>
p now print

And thanks to geirha in #bash, if you happen to have lynx installed it can be as easy as:

$ lynx -dump http://www.adobe.com/software/flash/about/ | awk '/Safari/{print $NF}'
11.1.102.62

Which made me /facepalm. Ha :D

EDIT: this bit is ok and can be used for the subs it just isn't as easy to read IMO. It would be more portable if they change the tags though.

-e 's/<[^>][^>]*>//g' -e '/^ *$/d'