forked from antonym/xs_patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xs_patcher.sh
executable file
·81 lines (64 loc) · 1.99 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
80
81
#!/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