Guest User

Firefox Jamf Install - Update Script

a guest
Aug 4th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.52 KB | None | 0 0
  1. #!/bin/sh
  2. #####################################################################################################
  3. #
  4. # ABOUT THIS PROGRAM
  5. #
  6. # NAME
  7. #   FirefoxInstall.sh -- Installs or updates Firefox
  8. #
  9. # SYNOPSIS
  10. #   sudo FirefoxInstall.sh
  11. #
  12. ####################################################################################################
  13. #
  14. # HISTORY
  15. #
  16. #   Version: 1.0
  17. #
  18. #   - Joe Farage, 18.03.2015
  19. #   - Chris Hansen, 14.05.2020 Some square brackets change to double square brackets
  20. #
  21. ####################################################################################################
  22. # Script to download and install Firefox.
  23. # Only works on Intel systems.
  24. #
  25. # choose language (en-US, fr, de)
  26. lang=""
  27. # CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 1 AND, IF SO, ASSIGN TO "lang"
  28. if [[ "$4" != "" ]] && [[ "$lang" == "" ]]; then
  29.     lang=$4
  30. else
  31.     lang="en-US"
  32. fi
  33.  
  34. dmgfile="FF.dmg"
  35. logfile="/Library/Logs/FirefoxInstallScript.log"
  36.  
  37. # Are we running on Intel?
  38. if [ '`/usr/bin/uname -p`'="i386" -o '`/usr/bin/uname -p`'="x86_64" ]; then
  39.     ## Get OS version and adjust for use with the URL string
  40.     OSvers_URL=$( sw_vers -productVersion | sed 's/[.]/_/g' )
  41.  
  42.     ## Set the User Agent string for use with curl
  43.     userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X ${OSvers_URL}) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2"
  44.  
  45.     # Get the latest version of Reader available from Firefox page.
  46.     latestver=`/usr/bin/curl -s -A "$userAgent" https://www.mozilla.org/${lang}/firefox/new/ | grep 'data-latest-firefox' | sed -e 's/.* data-latest-firefox="\(.*\)".*/\1/' -e 's/\"//' | /usr/bin/awk '{print $1}'`
  47.     echo "Latest Version is: $latestver"
  48.  
  49.     # Get the version number of the currently-installed FF, if any.
  50.     if [[ -e "/Applications/Firefox.app" ]]; then
  51.         currentinstalledver=`/usr/bin/defaults read /Applications/Firefox.app/Contents/Info CFBundleShortVersionString`
  52.         echo "Current installed version is: $currentinstalledver"
  53.         if [[ ${latestver} = ${currentinstalledver} ]]; then
  54.             echo "Firefox is current. Exiting"
  55.             exit 0
  56.         fi
  57.     else
  58.         currentinstalledver="none"
  59.         echo "Firefox is not installed"
  60.     fi
  61.  
  62.     url="https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US"
  63.  
  64.     echo "Latest version of the URL is: $url"
  65.     echo "`date`: Download URL: $url" >> ${logfile}
  66.  
  67.     # Compare the two versions, if they are different or Firefox is not present then download and install the new version.
  68.     if [[ "${currentinstalledver}" != "${latestver}" ]]; then
  69.         /bin/echo "`date`: Current Firefox version: ${currentinstalledver}" >> ${logfile}
  70.         /bin/echo "`date`: Available Firefox version: ${latestver}" >> ${logfile}
  71.         /bin/echo "`date`: Downloading newer version." >> ${logfile}
  72.         /usr/bin/curl -s -o /tmp/${dmgfile} ${url}
  73.         /bin/echo "`date`: Mounting installer disk image." >> ${logfile}
  74.         /usr/bin/hdiutil attach /tmp/${dmgfile} -nobrowse -quiet
  75.         /bin/echo "`date`: Installing..." >> ${logfile}
  76.         ditto -rsrc "/Volumes/Firefox/Firefox.app" "/Applications/Firefox.app"
  77.  
  78.         /bin/sleep 10
  79.         /bin/echo "`date`: Unmounting installer disk image." >> ${logfile}
  80.         /usr/bin/hdiutil detach $(/bin/df | /usr/bin/grep Firefox | awk '{print $1}') -quiet
  81.         /bin/sleep 10
  82.         /bin/echo "`date`: Deleting disk image." >> ${logfile}
  83.         /bin/rm /tmp/${dmgfile}
  84.  
  85.         #double check to see if the new version got updated
  86.         newlyinstalledver=`/usr/bin/defaults read /Applications/Firefox.app/Contents/Info CFBundleShortVersionString`
  87.         if [[ "${latestver}" = "${newlyinstalledver}" ]]; then
  88.             /bin/echo "`date`: SUCCESS: Firefox has been updated to version ${newlyinstalledver}" >> ${logfile}
  89.        # /Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -title "Firefox Installed" -description "Firefox has been updated." &
  90.         else
  91.             /bin/echo "`date`: ERROR: Firefox update unsuccessful, version remains at ${currentinstalledver}." >> ${logfile}
  92.             /bin/echo "--" >> ${logfile}
  93.             exit 1
  94.         fi
  95.  
  96.     # If Firefox is up to date already, just log it and exit.      
  97.     else
  98.         /bin/echo "`date`: Firefox is already up to date, running ${currentinstalledver}." >> ${logfile}
  99.         /bin/echo "--" >> ${logfile}
  100.     fi  
  101. else
  102.     /bin/echo "`date`: ERROR: This script is for Intel Macs only." >> ${logfile}
  103. fi
  104.  
  105. exit 0
  106.  
Add Comment
Please, Sign In to add comment