This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
xs_patcher.sh
executable file
·79 lines (61 loc) · 1.76 KB
/
xs_patcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
## xs_patcher
## detects xenserver version and applies the appropriate patches
## URL to patches: http://updates.xensource.com/XenServer/updates.xml
source /etc/xensource-inventory
TMP_DIR=tmp
CACHE_DIR=cache
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"
;;
"XenServer release 6.5.0" )
DISTRO="creedence"
;;
"XenServer release 7.0.0" )
DISTRO="dundee"
;;
* )
echo "Unable to detect version of XenServer, terminating"
exit 0
;;
esac
}
function apply_patches {
[ -d $TMP_DIR ] || mkdir $TMP_DIR
[ -d $CACHE_DIR ] || mkdir $CACHE_DIR
echo "Looking for missing patches for $DISTRO..."
grep -v '^#' patches/$DISTRO | while IFS='|'; read PATCH_NAME PATCH_UUID PATCH_URL PATCH_KB; do
PATCH_FILE=$(echo $PATCH_URL | awk -F/ '{print $NF}')
if [ -f /var/patch/applied/$PATCH_UUID ]; then
echo "$PATCH_NAME has been applied, moving on..."
else
echo "Found missing patch $PATCH_NAME, checking to see if it exists in cache..."
if [ ! -f $CACHE_DIR/$PATCH_NAME.xsupdate ]; then
echo "Downloading from $PATCH_URL..."
wget -q $PATCH_URL -O $TMP_DIR/$PATCH_FILE
echo "Unpacking..."
unzip -qq $TMP_DIR/$PATCH_FILE -d $CACHE_DIR
fi
echo "Applying $PATCH_NAME... [ Release Notes @ $PATCH_KB ]"
xe patch-upload file-name=$CACHE_DIR/$PATCH_NAME.xsupdate
xe patch-apply uuid=$PATCH_UUID host-uuid=$INSTALLATION_UUID
xe patch-clean uuid=$PATCH_UUID
fi
done
rm -rf tmp/*
echo "Everything has been patched up!"
}
get_xs_version
apply_patches