forked from B5r1oJ0A9G/zabbix-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-zabbix.sh
executable file
·88 lines (75 loc) · 2.46 KB
/
patch-zabbix.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
82
83
84
85
86
87
88
#!/bin/bash
# shows patch selection, applies the selected patches
# no error checking at all
# no conflict/dependency concept
command -v dialog > /dev/null 2>&1 || { echo >&2 "This script requires 'dialog'. Please install it!"; exit 1; }
[[ "$@" ]] || {
echo "Usage:
$0 zabbix_version <target_directory>
default target_directory is /usr/share/zabbix
Example:
$0 3.2 /path/to/frontend"
exit
}
zabbix_major_version=$1
if [ -z "$2" ]; then
target_dir="/usr/share/zabbix"
else
target_dir=$2
fi
[[ -d ${target_dir} ]] || {
echo "target directory \"$target_dir\" does not exist"
exit 1
}
[[ ${target_dir} =~ /$ ]] || target_dir=${target_dir}/
while IFS='|' read patch_id type details; do
[[ ${type} = name ]] && {
patch_name["$patch_id"]=${details}
continue
}
[[ ${type} = f ]] && {
patch_frontend_only["$patch_id"]=${details}
continue
}
[[ ${type} = desc ]] && {
patch_desc["$patch_id"]=${details}
continue
}
# patch directory levels to remove
[[ ${type} = ltr ]] && {
patch_ltr["$patch_id"]=${details}
continue
}
[[ ${type} = extra ]] && {
patch_extra["$patch_id"]="${patch_extra[$patch_id]#$'\n'}"$'\n'"$details"
continue
}
done < <(tail -n +2 zabbix-${zabbix_major_version}/patches.def)
for ((patch_id=1; patch_id<${#patch_name[@]}+1; patch_id++)); do
patch_list+=(${patch_id} "${patch_name[$patch_id]#zabbix-$zabbix_major_version-} ${patch_desc[$patch_id]}" off)
done
patches=$(dialog --stdout --checklist "Choose the patches to apply" 0 0 0 "${patch_list[@]}")
[[ ${patches} ]] || {
echo
echo "No patches selected"
exit
}
pushd zabbix-${zabbix_major_version} > /dev/null
for patch in ${patches}; do
echo "Applying ${patch_name[$patch]}"
if [ -d ${target_dir}${patch_frontend_only["$patch"]:+frontends/php/} ]; then
working_directory=${target_dir}${patch_frontend_only["$patch"]:+frontends/php/}
else
working_directory=${target_dir}
fi
cp ${patch_name[$patch]}/${patch_name[$patch]}.patch ${working_directory}
pushd ${working_directory} > /dev/null
patch -p ${patch_ltr["$patch"]:-0} -i ${patch_name[$patch]}.patch
rm ${patch_name[$patch]}.patch
popd > /dev/null
while read extra; do
echo "copying file: $extra"
cp -r ${extra}
done < <(echo "${patch_extra[$patch]}" | sed -e "s| | $working_directory|" -e "s|^|${patch_name[$patch]}/|") 2> /dev/null
done
popd > /dev/null