XenServer Automated Patcher (Bash)

Posted on January 23, 2014 at 8:40 pm

This script will retrieve and apply all of the latest hotfixes for Citrix XenServer:

xs_patcher – XenServer Automated Patcher

I am copying the content of the script (xs_patcher.sh) here:

#!/bin/bash
## xs_patcher
## detects xenserver version and applies the appropriate patches
 
HOSTID=`xe host-list --minimal`
HOSTNAME=`hostname`
 
function get_xs_version {
        get_version=`cat /etc/redhat-release | awk -F'-' {'print $1'}`
        case "${get_version}" in
                "XenServer release 6.0.0" )
                DISTRO="boston"
                ;;
 
                "XenServer release 6.0.2" )
                DISTRO="sanibel"
                ;;
 
                "XenServer release 6.1.0" )
                DISTRO="tampa"
                ;;
 
                "XenServer release 6.2.0" )
                DISTRO="clearwater"
                ;;
 
                * )
                echo "Unable to detect version of XenServer, terminating"
                exit 0
                ;;
 
        esac
}
 
function apply_patches {
        if [ ! -d tmp ]
        then
                mkdir -p tmp
        fi
 
echo "Looking for missing patches on $HOSTNAME for $DISTRO..."
 
        for PATCH in `cat patches/$DISTRO`
        do
         PATCH_NAME=`echo $PATCH | awk -F'|' {'print $1'}`
                PATCH_UUID=`echo $PATCH | awk -F'|' {'print $2'}`
                PATCH_URL=`echo $PATCH | awk -F'|' {'print $3'}`
                PATCH_KB=`echo $PATCH | awk -F'|' {'print $4'}`
 
                if [ -f /var/patch/applied/$PATCH_UUID ]
                then
                        echo "$PATCH_NAME has been applied, moving on..."
                fi
 
                if [ ! -f /var/patch/applied/$PATCH_UUID ]
                then
                        echo "Found missing patch $PATCH_NAME, checking to see if it exists in cache..."
 
                        if [ ! -f cache/$PATCH_NAME.xsupdate ]
                        then
                                echo "Downloading from $PATCH_URL..."
                                cd tmp
                                wget -q $PATCH_URL
                                unzip -qq $PATCH_NAME.zip                                
                                mv $PATCH_NAME.xsupdate ../cache
                                cd ..
                        fi        
 
                        echo "Applying $PATCH_NAME... [ Release Notes @ $PATCH_KB ]"
                             xe patch-upload file-name=cache/$PATCH_NAME.xsupdate
                 xe patch-apply uuid=$PATCH_UUID host-uuid=$HOSTID
         fi
 
done
 
        rm -rf tmp
        echo "Everything has been patched up!"
}
 
get_xs_version
apply_patches

The hotfixes are stored in individual files per distro in the patches directory.

To add new hotfixes, just add a line in the following format:

patch name|uuid of patch|url of download|url of kb article

This is the content of the file located at patches\clearwater:

XS62E001|dedcc0dd-d8f3-4f76-90ca-92697c7a44f0|support.citrix.com/servlet/KbServlet/download/34977-102-704231/XS62E001.zip|support.citrix.com/article/CTX138186
XS62E002|59128f15-92cd-4dd9-8fbe-a0115d1b07a2|support.citrix.com/servlet/KbServlet/download/35140-102-705624/XS62E002.zip|support.citrix.com/article/CTX138349

All the patches for XenServer 6.2.0 can be found here:

Public Hotfixes for XenServer 6.2.0 – Citrix Knowledge Center

References:

XenServer Auto Patcher

Updated on November 19, 2016 at 12:06 pm

Receive updates via email

Other Posts

Updated Posts