Skip to main content
Question

Microsoft Silverlight update script


Forum|alt.badge.img+11

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

Forum|alt.badge.img+19
  • Valued Contributor
  • 567 replies
  • December 8, 2015

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?


Forum|alt.badge.img+14
  • Contributor
  • 388 replies
  • December 8, 2015

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


Forum|alt.badge.img+11
  • Author
  • Contributor
  • 33 replies
  • December 8, 2015

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.


Forum|alt.badge.img+12
  • Valued Contributor
  • 226 replies
  • December 9, 2015

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


Forum|alt.badge.img+5
  • Contributor
  • 28 replies
  • January 26, 2016

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.


Forum|alt.badge.img+5
  • Contributor
  • 40 replies
  • February 2, 2016

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"

Forum|alt.badge.img+5
  • Contributor
  • 28 replies
  • February 17, 2016

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
Forum|alt.badge.img+21
  • Contributor
  • 279 replies
  • February 17, 2016

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
Forum|alt.badge.img+11
  • Jamf Heroes
  • 67 replies
  • March 18, 2016

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
Forum|alt.badge.img+21
  • Contributor
  • 279 replies
  • March 20, 2016

@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.


Forum|alt.badge.img+6
  • Contributor
  • 49 replies
  • July 8, 2016

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!


Forum|alt.badge.img+6
  • Contributor
  • 24 replies
  • April 7, 2017

@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.


Forum|alt.badge.img+10
  • New Contributor
  • 306 replies
  • April 7, 2017

@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


Forum|alt.badge.img+6
  • Contributor
  • 24 replies
  • April 7, 2017

@millersc Awesome! Thank you :)


Forum|alt.badge.img+11
  • Author
  • Contributor
  • 33 replies
  • April 10, 2017

@millersc Thanks!


Forum|alt.badge.img+6

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


Forum|alt.badge.img+10
  • New Contributor
  • 306 replies
  • January 24, 2018

@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


Forum|alt.badge.img+6

@millersc

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

Thanks for the heads up.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • January 24, 2018

@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.


Forum|alt.badge.img+6

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!


Forum|alt.badge.img+19
  • Valued Contributor
  • 567 replies
  • January 24, 2018

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


Forum|alt.badge.img+6

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


Forum|alt.badge.img+10
  • New Contributor
  • 306 replies
  • January 24, 2018

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

Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • January 24, 2018

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


Forum|alt.badge.img+4
  • New Contributor
  • 8 replies
  • March 23, 2018

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings