forked from pihhan/rpm-gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec-add-patch
executable file
·102 lines (85 loc) · 2.11 KB
/
spec-add-patch
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
#
# Script to simplify adding new patch file.
PATCHNAME=
SPECFILE="$(basename -- "$(pwd)".spec)"
CHANGELOG_COMMENT=
BACKUP=
PKGTOOL=
BUMPPARAMS=
PATCHLEVEL=1
GITADD=0
PATCHPAD=" "
usage()
{
cat << HELP
${0}: [-p strip] [-c comment] [-b suffix] [-s specfile] [-g] <patch...>
-p strip Use patch strip number for given patch file(s)
-c comment Use comment in changelog
-b suffix Use provided suffix as backup of patch
-g Add modified files to git index
-r Add -r parameter to rpmdev-bumpspec
-P pkgtool Try prep with given tool
-S padding Use padding before patch
HELP
}
while getopts -- "c:p:b:grP:S:h" PARAM "$@"
do
case "${PARAM}" in
p) PATCHLEVEL="$OPTARG" ;;
c) CHANGELOG_COMMENT="$OPTARG" ;;
b) BACKUP=" -b $OPTARG" ;;
s) SPECFILE="$OPTARG" ;;
g) GITADD=1 ;;
P) PKGTOOL="$OPTARG" ;;
S) PATCHPAD="$OPTARG" ;;
r) BUMPPARAMS+="-$PARAM " ;;
h) usage; exit 0;;
\?) echo "Invalid option -$OPTARG" >&2 ;;
esac
# echo "-$PARAM-"
done
if ! [ -f "$SPECFILE" ]
then
echo "Specfile $SPECFILE not found" >&2
exit 1
fi
MAXPATCH=$(spectool -l -P "$SPECFILE" | cut -d: -f1 | cut -c6- | sort -n | tail -1)
set -e
shift $(( OPTIND-1 ))
for PATCHNAME in "$@"
do
PATCHNAME="$1"
shift
if [ ! -f "$PATCHNAME" ]
then
echo "Patch file $PATCHNAME not found!" >&2
exit 1
fi
NEWPATCH_NUMBER=$((MAXPATCH+1))
if spectool -l -P "$SPECFILE" | cut -d: -f2- | grep '^\s*'"$PATCHNAME"'\s*$' > /dev/null
then
echo "Patch file $PATCHNAME is already present." >&2
exit 1
fi
sed -i -f - "$SPECFILE" <<SED
/^[Pp]atch${MAXPATCH}:/ a \
Patch${NEWPATCH_NUMBER}:${PATCHPAD}${PATCHNAME}
/^%[Pp]atch${MAXPATCH}\s/ a \
%patch${NEWPATCH_NUMBER} -p${PATCHLEVEL}${BACKUP}
/^%[Pp]atch${MAXPATCH}$/ a \
%patch${NEWPATCH_NUMBER} -p${PATCHLEVEL}${BACKUP}
SED
[ "$GITADD" = '1' ] && git add "$PATCHNAME"
MAXPATCH=$NEWPATCH_NUMBER
done
if [ -z "$PATCHNAME" ]
then
echo "No patch argument given." >&2
exit 1
fi
if [ -n "$CHANGELOG_COMMENT" ]; then
rpmdev-bumpspec $BUMPPARAMS -c "$CHANGELOG_COMMENT" -- "$SPECFILE"
fi
[ "$GITADD" = '1' ] && git add "$SPECFILE"
[ -n "$PKGTOOL" ] && "$PKGTOOL" prep