Script to download the latest Citrix Receiver for Mac:
1#!/bin/bash23#####################################################################################################4#5# ABOUT THIS PROGRAM6#7# NAME8# CitrixReceiverUpdate.sh -- Updates Citrix Receiver9#10# SYNOPSIS11# sudo CitrixReceiverUpdate.sh12#13# LICENSE14# Distributed under the MIT License15#16# EXIT CODES17# 0 - Citrix Receiver is current18# 1 - Citrix Receiver installed successfully19# 2 - Citrix Receiver NOT installed20# 3 - Citrix Receiver update unsuccessful21# 4 - Citrix Receiver is running or was attempted to be installed manually and user deferred install22# 5 - Not an Intel-based Mac23# 6 - ERROR: Wireless connected to a known bad WiFi network that won't allow downloading of the installer24#25####################################################################################################26#27# HISTORY28#29# Version: 1.030#31# - v.1.0 Luis Lugo, 09.05.2016 : Updates Citrix Receiver32#33####################################################################################################34# Script to download and install Citrix Receiver.3536# Setting variables37receiverProcRunning=03839# Echo function40echoFunc () {41 # Date and Time function for the log file42 fDateTime () { echo $(date +"%a %b %d %T"); }4344 # Title for beginning of line in log file45 Title="InstallLatestCitrixReceiver:"4647 # Header string function48 fHeader () { echo $(fDateTime) $(hostname) $Title; }4950 # Check for the log file51 if [ -e "/Library/Logs/CitrixReceiverUpdateScript.log" ]; then52 echo $(fHeader) "$1" >> "/Library/Logs/CitrixReceiverUpdateScript.log"53 else54 cat > "/Library/Logs/CitrixReceiverUpdateScript.log"55 if [ -e "/Library/Logs/CitrixReceiverUpdateScript.log" ]; then56 echo $(fHeader) "$1" >> "/Library/Logs/CitrixReceiverUpdateScript.log"57 else58 echo "Failed to create log file, writing to JAMF log"59 echo $(fHeader) "$1" >> "/var/log/jamf.log"60 fi61 fi6263 # Echo out64 echo $(fDateTime) ": $1"65}6667# Exit function68exitFunc () {69 case $1 in70 0) exitCode="0 - Citrix Receiver is current! Version: $2";;71 1) exitCode="1 - SUCCESS: Citrix Receiver has been updated to version $2";;72 2) exitCode="2 - ERROR: Citrix Receiver NOT installed!";;73 3) exitCode="3 - ERROR: Citrix Receiver update unsuccessful, version remains at $2!";;74 4) exitCode="4 - ERROR: Citrix Receiver is running or was attempted to be installed manually and user deferred install.";;75 5) exitCode="5 - ERROR: Not an Intel-based Mac.";;76 6) exitCode="6 - ERROR: Wireless connected to a known bad WiFi network that won't allow downloading of the installer! SSID: $2";;77 *) exitCode="$1";;78 esac79 echoFunc "Exit code: $exitCode"80 echoFunc "======================== Script Complete ========================"81 exit $182}8384# Check to see if Citrix Receiver is running85receiverRunningCheck () {86 processNum=$(ps aux | grep "Citrix Receiver" | wc -l)87 if [ $processNum -gt 1 ]88 then89 # Receiver is running, prompt the user to close it or defer the upgrade90 receiverRunning91 fi92}9394# If Citrix Receiver is running, prompt the user to close it95receiverRunning () {96 echoFunc "Citrix Receiver appears to be running!"97 hudTitle="Citrix Receiver Update"98 hudDescription="Citrix Receiver needs to be updated. Please save your work and close the application to proceed. You can defer if needed.99100If you have any questions, please call the help desk."101102 jamfHelperPrompt=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -lockHUD -title "$hudTitle" -description "$hudDescription" -button1 "Proceed" -button2 "Defer" -defaultButton 1`103104 case $jamfHelperPrompt in105 0)106 echoFunc "Proceed selected"107 receiverProcRunning=1108 receiverRunningCheck109 ;;110 2)111 echoFunc "Deferment Selected"112 exitFunc 4113 ;;114 *)115 echoFunc "Selection: $?"116 #receiverProcRunning=1117 #receiverRunningCheck118 exitFunc 3 "Unknown"119 ;;120 esac121}122123# If Citrix Receiver is running, prompt the user to close it124receiverUpdateMan () {125 echoFunc "Citrix Receiver appears to be running!"126 hudTitle="Citrix Receiver Update"127 hudDescription="Citrix Receiver needs to be updated. You will see a program downloading the installer. You can defer if needed.128129If you have any questions, please call the help desk."130131 jamfHelperPrompt=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -lockHUD -title "$hudTitle" -description "$hudDescription" -button1 "Defer" -button2 "Proceed" -defaultButton 1 -timeout 60 -countdown`132133 case $jamfHelperPrompt in134 0)135 echoFunc "Deferment Selected"136 exitFunc 4137 ;;138 2)139 echoFunc "Proceed selected"140 receiverRunningCheck141 ;;142 *)143 echoFunc "Selection: $?"144 exitFunc 3 "Unknown"145 ;;146 esac147}148149echoFunc ""150echoFunc "======================== Starting Script ========================"151152# Are we on a bad wireless network?153if [[ "$4" != "" ]]154then155 wifiSSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'`156 echoFunc "Current Wireless SSID: $wifiSSID"157158 badSSIDs=( $4 )159 for (( i = 0; i < "${#badSSIDs[@]}"; i++ ))160 do161 if [[ "$wifiSSID" == "${badSSIDs[i]}" ]]162 then163 echoFunc "Connected to a WiFi network that blocks downloads!"164 exitFunc 6 "${badSSIDs[i]}"165 fi166 done167fi168169# Are we running on Intel?170if [ '`/usr/bin/uname -p`'="i386" -o '`/usr/bin/uname -p`'="x86_64" ]; then171 ## Get OS version and adjust for use with the URL string172 OSvers_URL=$( sw_vers -productVersion | sed 's/[.]/_/g' )173174 ## Set the User Agent string for use with curl175 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"176177 # Get the latest version of Receiver available from Citrix's Receiver page.178 latestver=``179 while [ -z "$latestver" ]180 do181 latestver=`curl -s -L https://www.citrix.com/downloads/citrix-receiver/mac/receiver-for-mac-latest.html | grep "<h1>Receiver " | awk '{print $2}'`182 done183184 echoFunc "Latest Citrix Receiver Version is: $latestver"185 latestvernorm=`echo ${latestver}`186 # Get the version number of the currently-installed Citrix Receiver, if any.187 if [ -e "/Applications/Citrix Receiver.app" ]; then188 currentinstalledapp="Citrix Receiver"189 currentinstalledver=`/usr/bin/defaults read /Applications/Citrix Receiver.app/Contents/Info CFBundleShortVersionString`190 echoFunc "Current Receiver installed version is: $currentinstalledver"191 if [ ${latestvernorm} = ${currentinstalledver} ]; then192 exitFunc 0 "${currentinstalledapp} ${currentinstalledver}"193 else194 # Not running the latest version, check if Receiver is running195 receiverRunningCheck196 fi197 else198 currentinstalledapp="None"199 currentinstalledver="N/A"200 exitFunc 2201 fi202203 # Build URL and dmg file name204 CRCurrVersNormalized=$( echo $latestver | sed -e 's/[.]//g' )205 echoFunc "CRCurrVersNormalized: $CRCurrVersNormalized"206 url1="https:"207 url2=`curl -s -L https://www.citrix.com/downloads/citrix-receiver/mac/receiver-for-mac-latest.html | grep "ctx-dl-link ie10-download-hide promptDw"" | awk '{print $8}' | cut -c 6-112`208 url=`echo "${url1}${url2}"`209 echoFunc "Latest version of the URL is: $url"210 dmgfile="Citrix_Rec_${CRCurrVersNormalized}.dmg"211212 # Compare the two versions, if they are different or Citrix Receiver is not present then download and install the new version.213 if [ "${currentinstalledver}" != "${latestvernorm}" ]; then214 echoFunc "Current Receiver version: ${currentinstalledapp} ${currentinstalledver}"215 echoFunc "Available Receiver version: ${latestver} => ${CRCurrVersNormalized}"216 echoFunc "Downloading newer version."217 curl -s -o /tmp/${dmgfile} ${url}218 case $? in219 0)220 echoFunc "Checking if the file exists after downloading."221 if [ -e "/tmp/${dmgfile}" ]; then222 receiverFileSize=$(du -k "/tmp/${dmgfile}" | cut -f 1)223 echoFunc "Downloaded File Size: $receiverFileSize kb"224 else225 echoFunc "File NOT downloaded!"226 exitFunc 3 "${currentinstalledapp} ${currentinstalledver}"227 fi228 echoFunc "Checking if Receiver is running one last time before we install"229 receiverRunningCheck230 echoFunc "Mounting installer disk image."231 hdiutil attach /tmp/${dmgfile} -nobrowse -quiet232 echoFunc "Installing..."233 installer -pkg /Volumes/Citrix Receiver/Install Citrix Receiver.pkg -target / > /dev/null234235 sleep 10236 echoFunc "Unmounting installer disk image."237 umount "/Volumes/Citrix Receiver"238 sleep 10239 echoFunc "Deleting disk image."240 rm /tmp/${dmgfile}241242 #double check to see if the new version got update243 if [ -e "/Applications/Citrix Receiver.app" ]; then244 newlyinstalledver=`/usr/bin/defaults read /Applications/Citrix Receiver.app/Contents/Info CFBundleShortVersionString`245 if [ "${latestvernorm}" = "${newlyinstalledver}" ]; then246 echoFunc "SUCCESS: Citrix Receiver has been updated to version ${newlyinstalledver}, issuing JAMF recon command"247 jamf recon248 if [ $receiverProcRunning -eq 1 ];249 then250 /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -lockHUD -title "Citrix Receiver Updated" -description "Citrix Receiver has been updated to version ${newlyinstalledver}." -button1 "OK" -defaultButton 1251 fi252 exitFunc 1 "${newlyinstalledver}"253 else254 exitFunc 3 "${currentinstalledapp} ${currentinstalledver}"255 fi256 else257 exitFunc 3 "${currentinstalledapp} ${currentinstalledver}"258 fi259 ;;260 *)261 echoFunc "Curl function failed on download! Error: $?. Review error codes here: https://curl.haxx.se/libcurl/c/libcurl-errors.html"262 ;;263 esac264 else265 # If Citrix Receiver is up to date already, just log it and exit.266 exitFunc 0 "${currentinstalledapp} ${currentinstalledver}"267 fi268else269 # This script is for Intel Macs only.270 exitFunc 5271fi
