-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-rpm.sh
executable file
·61 lines (50 loc) · 1.16 KB
/
patch-rpm.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
#!/bin/bash
set -euo pipefail
if [ -z "${1+x}" ] || [ -z "${2+x}" ]; then
echo "usage: $0 [TARGET PACKAGE] [APPEND TO SUMMARY] [PATCH FILES]..."
exit 1
fi
TARGET=$1
APPEND=$2
shift 2
install_deps() {
sudo dnf install -y make rpm-build dnf-plugins-core
}
install_srpm() {
dnf download --source "$TARGET" --destdir /tmp
rpm -ivh "/tmp/$TARGET*"
}
cp_patches() {
for PATCH in "$@"; do
cp "$PATCH" "$HOME/rpmbuild/SOURCES/"
done
}
fix_spec() {
SPECFILE="$HOME/rpmbuild/SPECS/$TARGET.spec"
LATEST_PATCH=$(grep -o 'Patch[0-9]\+:' "$SPECFILE" | tail -n1 || true)
if [ -z "$LATEST_PATCH" ]; then
PATCHNUMBER=0
else
PATCHNUMBER=$(($(echo "$LATEST_PATCH" | grep -o '[0-9]\+') + 1))
fi
for PATCH in "$@"; do
FULLPATCH="Patch$PATCHNUMBER: $PATCH"
if [ -z "$LATEST_PATCH" ]; then
sed -i "/^Source0:.*/a $FULLPATCH" "$SPECFILE"
else
sed -i "/^$LATEST_PATCH.*/a $FULLPATCH" "$SPECFILE"
fi
PATCHNUMBER=$((PATCHNUMBER + 1))
LATEST_PATCH=$FULLPATCH
done
sed -i "/Summary:/ s/$/ $APPEND/" "$SPECFILE"
}
build() {
sudo dnf builddep "$TARGET" -y
rpmbuild -ba "$HOME/rpmbuild/SPECS/$TARGET.spec"
}
install_deps
install_srpm
cp_patches "$@"
fix_spec "$@"
build