-
Notifications
You must be signed in to change notification settings - Fork 19
/
build-rpm
executable file
·96 lines (79 loc) · 3.41 KB
/
build-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
#!/usr/bin/env bash
#
# Packaging Scripts
# Copyright (C) 2017-2024 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]
# Bash options:
set -e
# ---------------------------------------------------------------------------
# USAGE:
# ./make-rpm => Use current distribution and architecture
# ./make-rpm fedora-30-x86_64 => F30, amd64
# ./make-rpm fedora-rawhide-i386 => F30, i386
# ...
# ---------------------------------------------------------------------------
DISTRIBUTIONS=`\
( \
while [ x$1 != "x" ] ; do \
echo $1
shift
done \
) | sort -u`
if [ "${DISTRIBUTIONS}" == "" ] ; then
release=`cat /etc/fedora-release | sed -e "s/^\(.*\) release \([0-9]*\) (\(.*\))$/\2/g"`
arch=`uname -m`
DISTRIBUTIONS="fedora-${release}-${arch}"
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"`
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[34m###########################################\x1b[0m"
# ====== Create source RPM ==================================================
./make-srpm
PACKAGE_SRPM=`find $HOME/rpmbuild/SRPMS/ -name "${PACKAGE}-*-*.src.rpm"`
if [ ! -e "${PACKAGE_SRPM}" ] ; then
echo >&2 "ERROR: Cannot find SRPM ${PACKAGE}-*-*.src.rpm in $HOME/rpmbuild/SRPMS!"
exit 1
fi
# ====== Build binary RPMs ==================================================
# 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 ""
# NOTE: DISTRIBUTION may point to another directory (e.g. "rawhide" instead of "30")!
if [ ! -e "/etc/mock/${DISTRIBUTION}.cfg" ] ; then
echo >&2 "ERROR: Cannot find /etc/mock/${DISTRIBUTION}.cfg!"
exit 1
fi
# Remove old files
find /var/lib/mock/${DISTRIBUTION}/result -name "${PACKAGE}-*.rpm" | xargs --no-run-if-empty rm -f
# Build the binary RPM
# NOTE: using old chroot instead of container, to allow running it inside a container!
mock -r ${DISTRIBUTION} --isolation=simple --init
mock -r ${DISTRIBUTION} --isolation=simple --installdeps ${PACKAGE_SRPM}
mock -r ${DISTRIBUTION} --isolation=simple --install openssl pesign
mock -r ${DISTRIBUTION} --isolation=simple --no-clean --rebuild ${PACKAGE_SRPM}
# Check whether files are at the right location
PACKAGE_RPMS=`find /var/lib/mock/${DISTRIBUTION}/result -name "${PACKAGE}-*-*.rpm" | grep -v "${PACKAGE}-*-*.src.rpm" || true`
if [ "${PACKAGE_RPMS}" == "" ] ; then
echo >&2 "ERROR: Cannot find RPMs!"
exit 1
fi
done