blob: 92b41ac6e017a5332c91ac117e965f94c70bf988 [file] [log] [blame]
James Kuszmaul4cb043c2021-01-17 11:25:51 -08001#!/bin/bash -e
2# $Id$
3#
4# Packaging Scripts
5# Copyright (C) 2014-2017 by Thomas Dreibholz
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20# Contact: dreibh@iem.uni-due.de
21
22
23# ---------------------------------------------------------------------------
24# USAGE:
25# ./make-rpm default => for default distribution (F24, amd64)
26# ./make-rpm fedora-24-x86_64 => F24, amd64
27# ./make-rpm fedora-24-i386 => F24, i386
28# ...
29# ---------------------------------------------------------------------------
30
31
32DISTRIBUTIONS=`\
33( \
34while [ x$1 != "x" ] ; do \
35 echo $1
36 shift
37done \
38) | sort -u`
39if [ "$DISTRIBUTIONS" == "" ] ; then
40 DISTRIBUTIONS="fedora-24-x86_64"
41fi
42
43PACKAGE=`grep "^Name:" rpm/*.spec | head -n1 | sed -e "s/Name://g" -e "s/[ \t]*//g"`
44PACKAGE_VERSION=`grep "^Version:" rpm/*.spec | head -n1 | sed -e "s/Version://g" -e "s/[ \t]*//g"`
45PACKAGE_RELEASE=`grep "^Release:" rpm/*.spec | head -n1 | sed -e "s/Release://g" -e "s/[ \t]*//g"`
46
47echo -e "\x1b[34m###########################################\x1b[0m"
48echo -e "\x1b[34mPACKAGE: $PACKAGE\x1b[0m"
49echo -e "\x1b[34mPACKAGE_VERSION: $PACKAGE_VERSION\x1b[0m"
50echo -e "\x1b[34mPACKAGE_RELEASE: $PACKAGE_RELEASE\x1b[0m"
51echo -e "\x1b[34m###########################################\x1b[0m"
52
53# ====== Check with Debian package's version ================================
54if [ -e debian/changelog ] ; then
55 DEBIAN_CHANGELOG_HEADER="`head -n1 debian/changelog`"
56 # The package name, e.g. MyApplication
57 DEBIAN_PACKAGE=`echo $DEBIAN_CHANGELOG_HEADER | sed -e "s/(.*//" -e "s/ //g"`
58 # The package's version, e.g. 1.2.3-1ubuntu1
59 DEBIAN_PACKAGE_VERSION=`echo $DEBIAN_CHANGELOG_HEADER | sed -e "s/.*(//" -e "s/).*//" -e "s/ //g" -e "s/ //g"`
60 # The package's output version, e.g. 1.2.3-1ubuntu
61 OUTPUT_VERSION=`echo $PACKAGE_VERSION | sed -e "s/\(ubuntu\|ppa\)[0-9]*$/\1/"`
62 # The package's Debian version, e.g. 1.2.3-1
63 DEBIAN_VERSION=`echo $OUTPUT_VERSION | sed -e "s/\(ubuntu\|ppa\)$//1"`
64 # The package's upstream version, e.g. 1.2.3
65 DEBIAN_UPSTREAM_VERSION=`echo $DEBIAN_VERSION | sed -e "s/-[0-9]*$//"`
66
67 if [ "$PACKAGE-$PACKAGE_VERSION" != "$DEBIAN_PACKAGE-$DEBIAN_UPSTREAM_VERSION" ] ; then
68 echo >&2 "ERROR: RPM version and Debian version do not match -> $PACKAGE-$PACKAGE_VERSION vs. $DEBIAN_PACKAGE-$DEBIAN_UPSTREAM_VERSION!"
69 exit 1
70 fi
71 if [ ! -e ./debian.conf ] ; then
72 echo >&2 "ERROR: debian.conf does not exist -> no configuration for the new package!"
73 exit 1
74 fi
75fi
76
77if [ -e rpm.conf ] ; then
78 . ./rpm.conf
79fi
80
81# ====== Create upstream package ============================================
82echo -e ""
83echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating upstream package ======================\x1b[0m"
84echo -e ""
85if [ "$UPSTREAM_PACKAGE" = "" ] ; then
86 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.gz" -printf '%f'`"
87 UPSTREAM_PACKAGE_TYPE="gz"
88 if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
89 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name "$PACKAGE-*.bz2" -printf '%f'`"
90 UPSTREAM_PACKAGE_TYPE="bz2"
91 fi
92 if [ ! -e "$UPSTREAM_PACKAGE" ]; then
93 rm -f $PACKAGE-*.gz $PACKAGE"_"*.gz $PACKAGE-*.bz2 $PACKAGE"_"*.bz2
94 echo -e "\x1b[34m------ Running MAKE_DIST ... ------\x1b[0m"
95 echo "\$ $MAKE_DIST"
96 eval "$MAKE_DIST"
97
98 echo -e "\x1b[34m------ Looking for upstream package ... ------\x1b[0m"
99 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.gz -printf '%f'`"
100 UPSTREAM_PACKAGE_TYPE="gz"
101 if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
102 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.bz2 -printf '%f'`"
103 UPSTREAM_PACKAGE_TYPE="bz2"
104 fi
105 if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
106 UPSTREAM_PACKAGE="`find . -maxdepth 1 -name $PACKAGE-*.xz -printf '%f'`"
107 UPSTREAM_PACKAGE_TYPE="xz"
108 fi
109 fi
110fi
111if [ ! -e "$UPSTREAM_PACKAGE" ] ; then
112 echo -e "\x1b[34mERROR: No upstrem package found!\x1b[0m"
113 exit 1
114fi
115echo -e ""
116echo -e "\x1b[34m==> Upstream package is $UPSTREAM_PACKAGE (type is $UPSTREAM_PACKAGE_TYPE)\x1b[0m"
117echo -e ""
118
119
120# ====== Create RPMs ========================================================
121echo -e ""
122echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating source RPM ============================\x1b[0m"
123echo -e ""
124
125# Remove old files
126rpmdev-setuptree
127find $HOME/rpmbuild/SRPMS -name "$PACKAGE*.rpm" | xargs --no-run-if-empty rm -f
128find $HOME/rpmbuild/RPMS -name "$PACKAGE*.rpm" | xargs --no-run-if-empty rm -f
129# Copy upstream sources
130cp $UPSTREAM_PACKAGE $HOME/rpmbuild/SOURCES/
131# Patches
132if [ -e original ] ; then
133 find original -name "*" -type f | grep -v "~$" | grep -v ".spec$" | xargs -n1 -i§ cp "§" $HOME/rpmbuild/SOURCES/
134fi
135# Further patches
136find rpm -name "*" -type f | grep -v "~$" | grep -v ".spec$" | xargs -n1 -i§ cp "§" $HOME/rpmbuild/SOURCES/
137# The .spec file
138cp rpm/$PACKAGE.spec $HOME/rpmbuild/SPECS/
139
140# Create source RPM
141rpmbuild -bs rpm/$PACKAGE.spec
142PACKAGE_SRPM=`find $HOME/rpmbuild/SRPMS/ -name "$PACKAGE-*$PACKAGE_VERSION*-*.src.rpm"`
143if [ ! -e "$PACKAGE_SRPM" ] ; then
144 echo >&2 "ERROR: Cannot find SRPM $PACKAGE_SRPM!"
145 exit 1
146fi
147
148# Create binary RPMs
149for DISTRIBUTION in $DISTRIBUTIONS ; do
150 echo -e ""
151 echo -e "\x1b[34m`date +%FT%H:%M:%S`: ====== Creating binary RPM for $DISTRIBUTION ==========\x1b[0m"
152 echo -e ""
153
154 # Remove old files
155 find /var/lib/mock/$DISTRIBUTION/result -name "$PACKAGE-*.rpm" | xargs --no-run-if-empty rm -f
156
157 # Build the binary RPM
158 mock -r $DISTRIBUTION --init
159 mock -r $DISTRIBUTION --installdeps $PACKAGE_SRPM
160 mock -r $DISTRIBUTION --install openssl pesign
161 mock -r $DISTRIBUTION --no-clean --rebuild $PACKAGE_SRPM
162
163 # Check whether files are at the right location
164 PACKAGE_RPMS=`find /var/lib/mock/$DISTRIBUTION/result -name "$PACKAGE-*$PACKAGE_VERSION*-*.rpm" | grep -v "$PACKAGE-*$PACKAGE_VERSION*-*.src.rpm" || true`
165 if [ "$PACKAGE_RPMS" == "" ] ; then
166 echo >&2 "ERROR: Cannot find RPMs!"
167 exit 1
168 fi
169done