rpm: Fix rpm build script version issues (#9808)
When creating a package using this script, it's not straighforward that the version is fetched at the "configure" stage, by "git describe" which generates a 'lasttag-ncommits-lastcommit' format description. RPM doesn't allow - in version, so the rpmbuild stage fails. Add hints of actions to perform to get this script working Use package standard functions for the message to be seen easily
Adrien Mahieux committed
Sep 1, 2020 at 07:04 UTC
f2e4a9ac510df53289922b4ed1fca0c352c51791
1 file changed
+23
-14
contrib/rhel/build-netdata-rpm.sh
+23
-14
@@ -13,24 +13,33 @@ run autoreconf -ivf
13
run ./configure --enable-maintainer-mode
14
run make dist
15
16
-version=$(grep PACKAGE_VERSION < config.h | cut -d '"' -f 2)
17
-if [ -z "${version}" ]
18
-then
19
- echo >&2 "Cannot find netdata version."
20
- exit 1
16
+typeset version="$(grep PACKAGE_VERSION < config.h | cut -d '"' -f 2)"
17
+if [[ -z "${version}" ]]; then
18
+ run_failed "Cannot find netdata version."
19
+ exit 1
20
fi
21
23
-tgz="netdata-${version}.tar.gz"
24
-if [ ! -f "${tgz}" ]
25
-then
26
- echo >&2 "Cannot find the generated tar.gz file '${tgz}'"
22
+if [[ "${version//-/}" != "$version" ]]; then
23
+ # Remove all -* and _* suffixes to be as close as netdata release
24
+ typeset versionfix="${version%%-*}"; versionfix="${versionfix%%_*}"
25
+ # Append the current datetime fox a 'unique' build
26
+ versionfix+="_$(date '+%m%d%H%M%S')"
27
+ # And issue hints & details on why this failed, and how to fix it
28
+ run_failed "Current version contains '-' which is fobidden by rpm. You must create a git annotated tag and rerun this script. Exemple:"
29
+ run_failed " git tag -a $versionfix -m 'Release by $(id -nu) on $(uname -n)' && $0"
30
+ exit 1
31
+fi
32
+
33
+
34
+typeset tgz="netdata-${version}.tar.gz"
35
+if [[ ! -f "${tgz}" ]]; then
36
+ run_failed "Cannot find the generated tar.gz file '${tgz}'"
37
exit 1
38
fi
39
30
-srpm=$(run rpmbuild -ts "${tgz}" | cut -d ' ' -f 2)
31
-if [ -z "${srpm}" ] || [ ! -f "${srpm}" ]
32
-then
33
- echo >&2 "Cannot find the generated SRPM file '${srpm}'"
40
+typeset srpm="$(run rpmbuild -ts "${tgz}" | cut -d ' ' -f 2)"
41
+if [[ -z "${srpm}" ]] || ! [[ -f "${srpm}" ]]; then
42
+ run_failed "Cannot find the generated SRPM file '${srpm}'"
43
exit 1
44
fi
45
@@ -44,4 +53,4 @@ fi
53
54
run rpmbuild --rebuild "${srpm}"
55
47
-echo >&2 "All done!"
56
+run_ok "All done! Packages created in '$(rpm -E '%_rpmdir/%_arch')'"