forked from B5r1oJ0A9G/zabbix-patches
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpatch-zabbix.sh
executable file
·83 lines (70 loc) · 2.39 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
#!/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
Example:
$0 3.2 /path/to/frontend"
exit
}
zabbix_major_version=$1
target_dir=$2
[[ -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 ((patchid=1; patchid<${#patch_name[@]}+1; patchid++)); do
patchlist+=($patchid "${patch_name[$patchid]#zabbix-$zabbix_major_version-} ${patch_desc[$patchid]}" off)
done
patches=$(dialog --stdout --checklist "Choose the patches to apply" 0 0 0 "${patchlist[@]}")
[[ $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
#TODO: Why are we cp-ing? Is it to keep track of what was done?
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
popd > /dev/null
#TODO: The input to this loop is broken for patches that have no extra files
while read extra; do
cp $extra
done < <(echo "${patch_extra[$patch]}" | sed -e "s| | $working_directory|" -e "s|^|${patch_name[$patch]}/${patch_name[$patch]}-|") 2> /dev/null
done
popd > /dev/null