-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange_spec_patch_indexes.sh
More file actions
executable file
·58 lines (52 loc) · 1.37 KB
/
change_spec_patch_indexes.sh
File metadata and controls
executable file
·58 lines (52 loc) · 1.37 KB
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
#! /bin/bash -eu
#
# This script can be used to add/remove a specific offset from all PatchXXX
# directive in a spec file, which can help when merging back changes from
# XenServers where they add new patches in the middle of their patch-queue.
#
# For example if they've added 5 patches starting at patch index 100, then
# the previous Patch100 is now Patch105, Patch101 is now Patch106, etc.
# This script takes care of the rewriting, give it a spec file, an index to
# start and an offset.
#
# Usage: ./change_spec_patch_indexes.sh spec_file start_index offset
function usage() {
echo Usage: "$0" SPEC_FILE START_INDEX OFFSET
}
if [[ $# -ne 3 ]]; then
usage
exit 1
fi
spec_file="$1"
start_index="$2"
offset="$3"
if [[ ! -e "${spec_file}" ]]; then
echo "'${spec_file}' does not exist"
usage
exit 1
fi
awk -i inplace -v start="$start_index" -v off="$offset" '
BEGIN {
xcp_patches = 0
}
/^# XCP-ng patches/{
xcp_patches = 1
}
xcp_patches == 0 && /^#?[ ]*Patch[0-9]+/ {
if (match($0, /^(#[ ]*)?Patch([0-9]+)(.*)/, patch_line)) {
comment = patch_line[1]
patchnum = int(patch_line[2])
patch = patch_line[3]
if (patchnum >= start) {
patchnum = patchnum + off
printf "%sPatch%d%s\n", comment, patchnum, patch
} else {
print
}
} else {
print
}
next
}
{ print }
' "$spec_file"