Help updating Flash update script

nadams
New Contributor III

I'm trying to get my Flash update script to work again, after Adobe changed some things around early this year and it broke. I have pulled some updated information from other posts, and now have the script downloading the updated file correctly. Where I run into trouble is the actual mounting of the temporary DMG and running the install. It simply doesn't do anything... Below is the script that I'm using:

#!/bin/sh
# This script downloads and installs the latest Flash player for compatible Macs
# Determine OS version

osvers=$(sw_vers -productVersion | awk -F. '{print $2}')

# Determine current major version of Adobe Flash for use
# with the fileURL variable

flash_major_version=`/usr/bin/curl --connect-timeout 8 --max-time 8 -sf "http://fpdownload2.macromedia.com/get/flashplayer/update/current/xml/version_en_mac_pl.xml" 2>/dev/null | xmllint --format - 2>/dev/null | awk -F'"' '/<update version/{print $2}' | sed 's/,/./g'`

# Specify the complete address of the Adobe Flash Player
# disk image

 fileURL="https://fpdownload.adobe.com/get/flashplayer/pdc/"$flash_major_version"/install_flash_player_osx.dmg"

# Specify name of downloaded disk image

flash_dmg="/tmp/flash.dmg"

# Download the latest Adobe Flash Player software disk image

/usr/bin/curl --output "$flash_dmg" "$fileURL"

# Specify a /tmp/flashplayer.XXXX mountpoint for the disk image

 TMPMOUNT=`/usr/bin/mktemp -d /tmp/flashplayer.XXXX`

# Mount the latest Flash Player disk image to /tmp/flashplayer.XXXX mountpoint

hdiutil attach "$flash_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen

# Install Adobe Flash Player from the installer package stored inside the disk image

/usr/sbin/installer -pkg /Volumes/Flash Player/Install Adobe Flash Player.app/Contents/Resources/Adobe Flash Player.pkg -target / > /dev/null


# Clean-up
# Unmount the Flash Player disk image from /tmp/flashplayer.XXXX
/usr/bin/hdiutil detach "$TMPMOUNT"

 # Remove the /tmp/flashplayer.XXXX mountpoint

/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$flash_dmg"

fi
exit 0

I am not very well versed in scripting, so I'm doing this by trial and error. The command that isn't doing anything is the /user/sbin/installer line. Am I pointing it at the wrong location? If I look in disk management, I do see a Flash Player volume mounted from /private/tmp/flashplayer.VpVO, and if I "Show in Finder", I see the "Install Adobe Flash Player.app"... but when it runs, I just get... nothing.

2 REPLIES 2

c0n0r
Contributor

I'm sorry if this comes off a little cold, but here are the issues I see...
- The script has a she-bang line indicating sh, but I think you really intend to run it in bash
- Line 48 has a "fi" statement, but there is no corresponding "if" statement
- A number of the variable definitions have leading white space (lines 15 & 27)
- There is no hardening, you should check that the version of Flash was actually installed/updated prior to exit

In general, one of the best ways to see where your script is breaking is to run it in Terminal using the "-x" flag. In this case, the line 48 syntax error was caught immediately by me:
- copying the entire script into a file, and saving it on my desktop as "flashTest.sh"
- in terminal, using the command: "sudo sh -x ~/Desktop/flashTest.sh"

Hopefully that helps.

stevevalle
Contributor III

This is the script I use and works well. I found it on this JAMF forum thread

#!/bin/sh

dmgfile="flash.dmg"
volname="Flash"
logfile="/var/log/jamf.log"

latestver=`/usr/bin/curl --connect-timeout 8 --max-time 8 -sf "http://fpdownload2.macromedia.com/get/flashplayer/update/current/xml/version_en_mac_pl.xml" 2>/dev/null | xmllint --format - 2>/dev/null | awk -F'"' '/<update version/{print $2}' | sed 's/,/./g'`

# Get the version number of the currently-installed Flash Player, if any.
shortver=${latestver:0:2}
url="https://fpdownload.adobe.com/get/flashplayer/pdc/${latestver}/install_flash_player_osx.dmg"

# Determine if the installed version is older than the current version of Flash
flashPlayer="/Library/Internet Plug-Ins/Flash Player.plugin"

if [ ! -e "$flashPlayer" ]
    then
        currentinstalledver="0"
        echo "Flash Player is not installed"
    else
        currentinstalledver=`/usr/bin/defaults read "${flashPlayer}/Contents/version" CFBundleShortVersionString`
        echo "Flash Player v${currentinstalledver} is installed!"
fi

# Compare the two versions, if they are different then download and install the new version.
if [ "${currentinstalledver}" != "${latestver}" ]; then

    echo "Current Flash version: v${currentinstalledver}" >> ${logfile}
    echo "Available Flash version:  v${latestver}" >> ${logfile}

    echo "Downloading Flash Player v${latestver}." >> ${logfile}
    /usr/bin/curl -s -o `/usr/bin/dirname $0`/flash.dmg $url

    echo "Mounting installer disk image." >> ${logfile}
    /usr/bin/hdiutil attach `dirname $0`/flash.dmg -nobrowse -quiet

    echo "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

    echo "Unmounting installer disk image." >> ${logfile}
    /usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep ${volname} | awk '{print $1}') -quiet
    /bin/sleep 10

    echo "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
        echo "SUCCESS: Flash has been updated to version ${newlyinstalledver}" >> ${logfile}
    else
        echo "ERROR: Flash update unsuccessful, version remains at ${currentinstalledver}." >> ${logfile}
        echo "--" >> ${logfile}
    fi

# If Flash is already up to date, exit.    
else
    echo "Flash is already up to date, running ${currentinstalledver}." >> ${logfile}
fi

exit 0