forked from dreibh/netperfmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-srpm
executable file
·132 lines (116 loc) · 5.51 KB
/
make-srpm
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash -e
#
# Packaging Scripts
# Copyright (C) 2017-2019 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact: [email protected]
# ---------------------------------------------------------------------------
# USAGE:
# ./make-rpm
# ---------------------------------------------------------------------------
# ====== Obtain package and version information =============================
PACKAGE=`grep "^Name:" rpm/*.spec | head -n1 | sed -e "s/Name://g" -e "s/[ \t]*//g"`
PACKAGE_VERSION=`grep "^Version:" rpm/*.spec | head -n1 | sed -e "s/Version://g" -e "s/[ \t]*//g"`
PACKAGE_RELEASE=`grep "^Release:" rpm/*.spec | head -n1 | sed -e "s/Release://g" -e "s/[ \t]*//g"`
echo -e "\x1b[34m###########################################\x1b[0m"
echo -e "\x1b[34mPACKAGE: ${PACKAGE}\x1b[0m"
echo -e "\x1b[34mPACKAGE_VERSION: ${PACKAGE_VERSION}\x1b[0m"
echo -e "\x1b[34mPACKAGE_RELEASE: ${PACKAGE}_RELEASE\x1b[0m"
echo -e "\x1b[34m###########################################\x1b[0m"
# ====== Check with Debian package's version ================================
if [ -e debian/changelog ] ; then
DEBIAN_CHANGELOG_HEADER="`head -n1 debian/changelog`"
# The package name, e.g. MyApplication
DEBIAN_PACKAGE=`echo ${DEBIAN_CHANGELOG_HEADER} | sed -e "s/(.*//" -e "s/ //g"`
# The package distribution, e.g. precise, raring, ...
DEBIAN_PACKAGE_DISTRIBUTION=`echo ${DEBIAN_CHANGELOG_HEADER} | sed -e "s/[^)]*)//" -e "s/;.*//g" -e "s/ //g"`
# The package's version, e.g. 1.2.3-1ubuntu1
DEBIAN_PACKAGE_VERSION=`echo ${DEBIAN_CHANGELOG_HEADER} | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g" -e "s/^[0-9]://g"`
# The package's output version, e.g. 1.2.3-1ubuntu
DEBIAN_OUTPUT_VERSION=`echo ${DEBIAN_PACKAGE_VERSION} | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"`
# The package's Debian version, e.g. 1.2.3-1
DEBIAN_VERSION=`echo ${DEBIAN_OUTPUT_VERSION} | sed -e "s/\(ubuntu\|ppa\)$//1"`
# The package's upstream version, e.g. 1.2.3
DEBIAN_UPSTREAM_VERSION=`echo ${DEBIAN_VERSION} | sed -e "s/-[0-9]*$//"`
if [ "${PACKAGE}-${PACKAGE_VERSION}" != "${DEBIAN_PACKAGE}-${DEBIAN_UPSTREAM_VERSION}" ] ; then
echo >&2 "ERROR: RPM version and Debian version do not match -> ${PACKAGE}-${PACKAGE_VERSION} vs. ${DEBIAN_PACKAGE}-${DEBIAN_UPSTREAM_VERSION}!"
exit 1
fi
if [ ! -e ./debian.conf ] ; then
echo >&2 "ERROR: debian.conf does not exist -> no configuration for the new package!"
exit 1
fi
fi
if [ -e rpm.conf ] ; then
. ./rpm.conf
fi
# ====== Create upstream source package =====================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================================\x1b[0m"
echo -e ""
if [ "${UPSTREAM_PACKAGE}" = "" ] ; then
for UPSTREAM_PACKAGE_TYPE in xz bz2 gz ; do
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "${PACKAGE}-*.${UPSTREAM_PACKAGE_TYPE}" -printf '%f'`"
if [ -e "${UPSTREAM_PACKAGE}" ] ; then
break
fi
done
if [ ! -e "${UPSTREAM_PACKAGE}" ]; then
rm -f ${PACKAGE}-*.gz ${PACKAGE}"_"*.gz ${PACKAGE}-*.bz2 ${PACKAGE}"_"*.bz2
echo -e "\x1b[34m------ Running MAKE_DIST ... ------\x1b[0m"
echo "\$ $MAKE_DIST"
eval "$MAKE_DIST"
echo -e "\x1b[34m------ Looking for upstream package ... ------\x1b[0m"
for UPSTREAM_PACKAGE_TYPE in xz bz2 gz ; do
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "${PACKAGE}-*.${UPSTREAM_PACKAGE_TYPE}" -printf '%f'`"
if [ -e "${UPSTREAM_PACKAGE}" ] ; then
break
fi
done
fi
fi
if [ ! -e "${UPSTREAM_PACKAGE}" ] ; then
echo -e "\x1b[34mERROR: No upstrem package found!\x1b[0m"
exit 1
fi
echo -e ""
echo -e "\x1b[34m==> Upstream package is ${UPSTREAM_PACKAGE} (type is ${UPSTREAM_PACKAGE_TYPE})\x1b[0m"
echo -e ""
# ====== Create source RPM ==================================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating source RPM ============================\x1b[0m"
echo -e ""
# ------ Initialise RPM build directories -----------------------------------
rpmdev-setuptree
find $HOME/rpmbuild/SRPMS -name "${PACKAGE}*.rpm" | xargs --no-run-if-empty rm -f
find $HOME/rpmbuild/RPMS -name "${PACKAGE}*.rpm" | xargs --no-run-if-empty rm -f
# Copy upstream sources
cp ${UPSTREAM_PACKAGE} $HOME/rpmbuild/SOURCES/
# Patches
if [ -e original ] ; then
find original -name "*" -type f | grep -v "~$" | grep -v ".spec$" | xargs -n1 -i§ cp "§" $HOME/rpmbuild/SOURCES/
fi
# Further patches
find rpm -name "*" -type f | grep -v "~$" | grep -v ".spec$" | xargs -n1 -i§ cp "§" $HOME/rpmbuild/SOURCES/
# The .spec file
cp rpm/${PACKAGE}.spec $HOME/rpmbuild/SPECS/
# ------ Create source RPM --------------------------------------------------
rpmbuild -bs rpm/${PACKAGE}.spec
PACKAGE_SRPM=`find $HOME/rpmbuild/SRPMS/ -name "${PACKAGE}-*${PACKAGE_VERSION}*-*.src.rpm"`
if [ ! -e "${PACKAGE_SRPM}" ] ; then
echo >&2 "ERROR: Cannot find SRPM ${PACKAGE_SRPM}!"
exit 1
fi