This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
forked from NEAT-project/usrsctp-neat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-rpm
executable file
·169 lines (150 loc) · 6.44 KB
/
make-rpm
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash -e
# $Id$
#
# Packaging Scripts
# Copyright (C) 2014-2017 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: dreibh@iem.uni-due.de
# ---------------------------------------------------------------------------
# USAGE:
# ./make-rpm default => for default distribution (F24, amd64)
# ./make-rpm fedora-24-x86_64 => F24, amd64
# ./make-rpm fedora-24-i386 => F24, i386
# ...
# ---------------------------------------------------------------------------
DISTRIBUTIONS=`\
( \
while [ x$1 != "x" ] ; do \
echo $1
shift
done \
) | sort -u`
if [ "$DISTRIBUTIONS" == "" ] ; then
DISTRIBUTIONS="fedora-24-x86_64"
fi
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'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"`
# The package's output version, e.g. 1.2.3-1ubuntu
OUTPUT_VERSION=`echo $PACKAGE_VERSION | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"`
# The package's Debian version, e.g. 1.2.3-1
DEBIAN_VERSION=`echo $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 package ============================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================\x1b[0m"
echo -e ""
if [ "$UPSTREAM_PACKAGE" = "" ] ; then
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.gz" -printf '%f'`"
UPSTREAM_PACKAGE_TYPE="gz"
if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.bz2" -printf '%f'`"
UPSTREAM_PACKAGE_TYPE="bz2"
fi
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"
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.gz -printf '%f'`"
UPSTREAM_PACKAGE_TYPE="gz"
if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.bz2 -printf '%f'`"
UPSTREAM_PACKAGE_TYPE="bz2"
fi
if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.xz -printf '%f'`"
UPSTREAM_PACKAGE_TYPE="xz"
fi
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 RPMs ========================================================
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating source RPM ============================\x1b[0m"
echo -e ""
# Remove old files
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
# Create binary RPMs
for DISTRIBUTION in $DISTRIBUTIONS ; do
echo -e ""
echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating binary RPM for $DISTRIBUTION ==========\x1b[0m"
echo -e ""
# Remove old files
find /var/lib/mock/$DISTRIBUTION/result -name "$PACKAGE-*.rpm" | xargs --no-run-if-empty rm -f
# Build the binary RPM
mock -r $DISTRIBUTION --init
mock -r $DISTRIBUTION --installdeps $PACKAGE_SRPM
mock -r $DISTRIBUTION --install openssl pesign
mock -r $DISTRIBUTION --no-clean --rebuild $PACKAGE_SRPM
# Check whether files are at the right location
PACKAGE_RPMS=`find /var/lib/mock/$DISTRIBUTION/result -name "$PACKAGE-*$PACKAGE_VERSION*-*.rpm" | grep -v "$PACKAGE-*$PACKAGE_VERSION*-*.src.rpm" || true`
if [ "$PACKAGE_RPMS" == "" ] ; then
echo >&2 "ERROR: Cannot find RPMs!"
exit 1
fi
done