Microsoft Silverlight update script

kenergy
Contributor

Thanks to @mm2270 and @rtrouton I have taken Mike's update script and Rich's adobe flash update script and figured out how to make the Microsoft Silverlight script.

#!/bin/sh

# Silverlight Lastest Version URL
###############################
silLightCheckURL="http://www.microsoft.com/getsilverlight/locale/en-us/html/Microsoft%20Silverlight%20Release%20History.htm"
URL="${silLightCheckURL}"

###############################

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


# Current Microsoft Silverlight Version
###############################
curr_Vers=$( curl -sf "${URL}" 2>/dev/null | grep -m1 "Silverlight 5 Build" | awk -F'[>|<]' '{print $2}' | tr ' ' '
' | awk '/Build/{getline; print}' )

# Download URL Microsoft Silverlight Version
###############################
download_url=$( curl  -sfA "$UGENT" "http://go.microsoft.com/fwlink/?LinkID=229322" | awk -F'"' '{print $2}' | sed '/^$/d' )
sl_dmg="silverlight.dmg"


if [[ ${osvers} -lt 6 ]]; then
  echo "Buy a new Mac!"
fi

if [[ ${osvers} -ge 6 ]]; then

    # Download the latest Microsoft Silverlight software disk image

    /usr/bin/curl --output "$sl_dmg" "$download_url"

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

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

    # Mount the latest Silverlight disk image to /tmp/silverlight.XXXX mountpoint

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

    pkg_path="$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *Silverlight*.pkg -o -iname *Silverlight*.mpkg ))"

    # Before installation on Mac OS X 10.7.x and later, the installer's
    # developer certificate is checked to see if it has been signed by
    # Microsoft's developer certificate. Once the certificate check has been
    # passed, the package is then installed.

    if [[ ${pkg_path} != "" ]]; then
       if [[ ${osvers} -ge 7 ]]; then
         signature_check=`/usr/sbin/pkgutil --check-signature "$pkg_path" | awk /'Developer ID Installer/{ print $5 }'`
         if [[ ${signature_check} = "Microsoft" ]]; then
           # Install Microsoft Silverlight from the installer package stored inside the disk image
           /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/"
         fi
       fi

    # On Mac OS X 10.6.x, the developer certificate check is not an
    # available option, so the package is just installed.

       if [[ ${osvers} -eq 6 ]]; then
           # Install Microsoft Silverlight from the installer package stored inside the disk image
           /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/"
       fi
    fi

    # Clean-up

    # Unmount the Microsoft Silverlight disk image from /tmp/silverlight.XXXX

    /usr/bin/hdiutil detach "$TMPMOUNT"

    # Remove the /tmp/silverlight.XXXX mountpoint

    /bin/rm -rf "$TMPMOUNT"

    # Remove the downloaded disk image

    /bin/rm -rf "$SilverlightDMG"
fi


exit 0
25 REPLIES 25

dstranathan
Valued Contributor II

Thanks @kenergy. Worked great for me (just ran it manually for a test).

Just curious: What apps/sites are dependent on MS Silverlight in your environment?

Aziz
Valued Contributor

@dstranathan For us, Outlook Web App 2010. We're moving to Exchange 2013 eventually.

kenergy
Contributor

None, I just add it as part of the default setup so users don't have to wait for it to be packaged and then put in Self Service.

SGill
Contributor III

We use grammar testing software here that needs it: http://www.egumpp.com

csmith122
New Contributor III

Thanks for the script, and i lol'ed at this.

if [[ ${osvers} -lt 6 ]]; then echo "Buy a new Mac!"
fi

I also added an If statement to check to see if the current version is installed already and if it is to do nothing. This way i can set my script to run once a week on all my computers.

JesseNCSD
New Contributor III

Thanks for the script!

Is there a reason I shouldn't just do something like:

download_url="http://go.microsoft.com/fwlink/?LinkID=229322"
sl_dmg="silverlight.dmg"
/usr/bin/curl -sfL --output "$sl_dmg" "$download_url"

which would just let curl follow the redirect and download, rather than

download_url=$( curl  -sfA "$UGENT" "http://go.microsoft.com/fwlink/?LinkID=229322" | awk -F'"' '{print $2}' | sed '/^$/d' )
sl_dmg="silverlight.dmg"
/usr/bin/curl --output "$sl_dmg" "$download_url"

csmith122
New Contributor III

Im getting a curl: (3) malformed error when i look at the log files in casper. It also does not update correctly. It seems to work half the time.

iJake
Valued Contributor

I adapted the script from @kenergy with one we already had for Flash and this is what we use. You'd need to modify the Log and DMG download locations for your own environment. The script will also, if it has updated Silverlight, ensure that it is properly enabled. We've had issues with it getting turned off in Safari.

#!/bin/bash

## HEADER
# Script Title: Microsoft Silverlight Downloader
# Authot: Jacob Davidson <jadavids@cisco.com>

## DEFINITIONS
SoftwareTitle=Silverlight5
SectionTitle=Silverlight5
LogFolder='/PATH/TO/LOG'
LogFile="$LogFolder/$SoftwareTitle.log"
TimeStamp=$(date "+%Y %b %d %T")
ConsoleUser=$(stat -f %Su '/dev/console')
LogSize=$(stat -f%z $LogFile)
MaxSize=1000000
BackupLocation="/Path/TO/PACKAGE/DOWNLOAD"
InstallDMG="silverlight.dmg"
silLightCheckURL="http://www.microsoft.com/getsilverlight/locale/en-us/html/Microsoft%20Silverlight%20Release%20History.htm"
URL="${silLightCheckURL}"
FilerURL="http://go.microsoft.com/fwlink/?LinkID=229322"
WebVersion=$( curl -sf "${URL}" 2>/dev/null | grep -m1 "Silverlight 5 Build" | awk -F'[>|<]' '{print $2}' | tr ' ' '
' | awk '/Build/{getline; print}' )
pluginDisabledCheck=$(defaults read $homeFolder/Library/Preferences/com.apple.Safari.plist DisabledPlugInInfo | grep -c SilverlightPlugin)
pluginDisabledFix=$(/usr/libexec/PlistBuddy -c "Delete :DisabledPlugInInfo:com.microsoft.SilverlightPlugin" $homeFolder/Library/Preferences/com.apple.Safari.plist)


## LOGGING
writeLog(){ echo "[$TimeStamp] [$SoftwareTitle] [$SectionTitle] [$ConsoleUser]: $1" >> $LogFile; }
[[ -d $logFolder ]] || mkdir -p -m 775 "$LogFolder"
[[ $LogSize -ge $MaxSize ]] && rm -rf "$LogFile"

## FUNCTIONS
grabConsoleUserAndHome(){
  currentUser=$(stat -f %Su "/dev/console")
  homeFolder=$(dscl . read "/Users/$currentUser" NFSHomeDirectory | cut -d: -f 2 | sed 's/^ *//'| tr -d '
')
}


## BODY
SectionTitle=Verification
WebVersionInt=$(echo "${WebVersion//.}")
if [[ -e "/Library/Internet Plug-Ins/Silverlight.plugin" ]]; then
  CurrentVersion=$(defaults read "/Library/Internet Plug-Ins/Silverlight.plugin/Contents/Info.plist" CFBundleVersion)
  CurrentVersionInt=$(echo "${CurrentVersion//.}")
  [[ "$WebVersionInt" -le "$CurrentVersionInt" ]] && writeLog "Silverlight up to date at: $CurrentVersion" && exit 0
fi
writeLog "Installation Date: $TimeStamp"
writeLog "Active Console User: $ConsoleUser"
if [[ -e "/Library/Internet Plug-Ins/Silverlight.plugin" ]]; then
  writeLog "Installed Silverlight version: $CurrentVersion"
else
  writeLog "Existing installation of Silverlight not found. Exiting"
  exit
fi
writeLog "Current available version: $WebVersion"
SectionTitle=Download
[[ -d "$BackupLocation" ]] || mkdir -p -m 775 "$BackupLocation"
FilerConnection=$(curl -L -s -o "/dev/null" --silent --head --write-out '%{http_code}' "$FilerURL" --location-trusted -X GET)
writeLog "Connection status: $FilerConnection"
if [[ "$FilerConnection" -eq 200 ]]; then
  /usr/bin/curl -sfL "$FilerURL" -o "$BackupLocation/$InstallDMG" --silent --location-trusted >> "$LogFile"
else
  writeLog "Connection error"
  echo "Unable to download Silverlight from Microsoft"
  exit 1
fi
SectionTitle=Mount
MountPoint=$(/usr/bin/mktemp -d /tmp/Silverlight.XXXX)
if [[ -e "$BackupLocation/$InstallDMG" ]]; then
  hdiutil attach "$BackupLocation/$InstallDMG" -mountpoint "$MountPoint" -nobrowse -noverify -noautoopen
  writeLog "Mounted DMG $BackupLocation/$InstallDMG at $MountPoint"
else
  writeLog "Unable to find DMG at $BackupLocation"
  ls -la "$BackupLocation" >> "$LogFile"
  echo "Install DMG download not successful"
  exit 1
fi
SectionTitle=Install
SilverlightInstaller=$(find "$MountPoint" -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))
if [[ -e "$SilverlightInstaller" ]]; then
  writeLog "Executing package at: $SilverlightInstaller"
  installer -dumplog -pkg "$SilverlightInstaller" -target / >> "$LogFile"
else
  writeLog "Installer package not found"
  echo "Installer package not found on DMG"
  exit 1
fi
SectionTitle=CleanUp
writeLog "Unmounting install DMG"
hdiutil detach "$MountPoint" >> "$LogFile"
[[ -e "$BackupLocation/$InstallDMG" ]] && rm -rfv "$BackupLocation/$InstallDMG" >> "$LogFile"
SectionTitle=Confirmation
CurrentVersion=$(defaults read "/Library/Internet Plug-Ins/Silverlight.plugin/Contents/Info.plist" CFBundleVersion)
CurrentVersionInt=$(echo "${CurrentVersion//.}")
writeLog "Installed Silverlight version: $CurrentVersion"
if [[ "$WebVersionInt" = "$CurrentVersionInt" ]]; then
  SectionTitle=Complete
  writeLog "Update successful"
  writeLog "Verifying Plugin Enabled"
  grabConsoleUserAndHome
  if [[ $pluginDisabledCheck -gt 0 ]]
    then
      writeLog "Enabling plugin"
      $pluginDisabledFix
    else
        writeLog "Verified"
  fi
else
  writeLog "Update failed"
  echo "Silverlight not updated"
  exit 1
fi

## FOOTER
exit 0

peterlbk
Contributor

Hi iJake,

why did you exit if there's no version found? I removed it and now it can always be installed...

Anyway, just to let you know - great script btw!

iJake
Valued Contributor

@peterloobuyck We only wanted to update clients that already had it in our case. Glad you found it useful and were able to modify it.

josaxo
New Contributor

Hi All - Great script and thanks for the help. Has anyone had any luck getting this to work through a proxy? We actually use an automatic configuration script (.pac) file. Appreciate any info.
Thanks!

psd_martinb
New Contributor III

@iJake This script worked well with slight modification. I added the signature check from the initial script.

Unfortunately the script throws failed because the geniuses at Microsoft must have not updated the version name correctly. Downloading the latest currently available reads 5.1.50905.0 but when installed reads 5.1.50901.0, even when installing manually.

millersc
Valued Contributor

@psd_martinb I noticed that MS problem a week ago and modified my script. I changed it to use $4 variable now instead of reading the MS history page. Been working good for a week now.

https://github.com/stevemillermac/MicrosoftSilverlightUpdate

psd_martinb
New Contributor III

@millersc Awesome! Thank you :)

kenergy
Contributor

@millersc Thanks!

cyberspread_71
New Contributor III

Got the updated script from guthub.

And get this error when running locally.

Jan 24, 2018, 8:41:35 AM

~/Documents/Casper Resources/Scripts/silverlight.sh

curl: (3) <url> malformed
hdiutil: attach failed - No such file or directory
hdiutil: detach failed - No such file or directory

millersc
Valued Contributor

@ktermin

This script should be run from the JAMF server and scoped out to the device.

I've been running this version for months without issues and $4 is still running 5.1.50901.0.

Steve

cyberspread_71
New Contributor III

@millersc

Cool. I will test that way. Usually I run the script locally to troubleshoot.

Thanks for the heads up.

mm2270
Legendary Contributor III

@ktermin It can be run locally, but you can't just drop it as is into Terminal. To test it locally first, use the jamf binary. Example:

sudo jamf runScript -script <script_name_including_extension> -path <path_to_script_minus_script_name> -p1 <parameter 4 string>

Just replace the items between the < & > brackets with the correct information.

Incidentally, @millersc should probably update his script to check for a string passed to $4 and fail with a more descriptive error message if one isn't passed. As it is, it's not downloading anything and hdiutil has no DMG to work with, which is why it's throwing that error.

cyberspread_71
New Contributor III

It is installing version 5.1.50901.0.

This is the error it is outputting:

Script result: Microsoft Silverlight is not installed
Downloading the DMG
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

58 14.3M 58 8615k 0 0 9026k 0 0:00:01 --:--:-- 0:00:01 9026k
100 14.3M 100 14.3M 0 0 10.8M 0 0:00:01 0:00:01 --:--:-- 16.0M
Mounting the DMG
Installing Microsoft Silverlight
The mount point is disk2s2
ERROR: Microsoft Silverlight update unsuccessful, version remains at none.

Even though there is an error, it still installs but seems to be the old version. New version being Silverlight 5 Build 5.1.50907.0 Released June 13, 2017.

I read thru the thread and seems there was an issue but was fixed. Is this not the case? Thanks!

dstranathan
Valued Contributor II

I also have 5.1.50901.0 installed which appears to be the most recent according to https://www.microsoft.com/getsilverlight/Get-Started/Install/Default

cyberspread_71
New Contributor III

https://www.microsoft.com/getsilverlight/locale/en-us/html/Microsoft%20Silverlight%20Release%20History.htm#SL_5_1_50907

millersc
Valued Contributor

Microsoft has made updates to the Windows version, not the Mac version. It is still at 5.1.50901.0. I believe that is why your getting an error.

This is the result of the script from yesterday:

Executing Policy Install Silverlight Latest
Running script MicrosoftSilverlightUpdate.sh...
Script exit code: 0
Script result: Microsoft Silverlight is not installed
Downloading the DMG
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
12 14.3M 12 1835k 0 0 634k 0 0:00:23 0:00:02 0:00:21 918k
45 14.3M 45 6762k 0 0 1739k 0 0:00:08 0:00:03 0:00:05 2257k
79 14.3M 79 11.4M 0 0 2405k 0 0:00:06 0:00:04 0:00:02 2943k
100 14.3M 100 14.3M 0 0 2731k 0 0:00:05 0:00:05 --:--:-- 3274k
Mounting the DMG
Installing Microsoft Silverlight
The mount point is disk3s2
SUCCESS: Microsoft Silverlight has been updated to version 5.1.50901.0

amelgares
New Contributor

FYI - Microsoft no longer updates or supports Silverlight for Mac as of 12/31/2016.
Also, the last supported macOS version is 10.11.
https://www.microsoft.com/getsilverlight/locale/en-us/html/installation-win-SL5.html

Berzinji
New Contributor II

Thank you iJake for the script. It worked like a charm.