• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh -e
2# Copyright 2005 Google Inc.
3# Author: Craig Silverstein
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Run this from the 'packages' directory, just under rootdir
18
19# We can only build rpm packages, if the rpm build tools are installed
20if [ \! -x /usr/bin/rpmbuild ]
21then
22  echo "Cannot find /usr/bin/rpmbuild. Not building an rpm." 1>&2
23  exit 0
24fi
25
26# Check the commandline flags
27PACKAGE="$1"
28VERSION="$2"
29fullname="${PACKAGE}-${VERSION}"
30archive=../$fullname.tar.gz
31
32if [ -z "$1" -o -z "$2" ]
33then
34  echo "Usage: $0 <package name> <package version>" 1>&2
35  exit 0
36fi
37
38# Double-check we're in the packages directory, just under rootdir
39if [ \! -r ../Makefile -a \! -r ../INSTALL ]
40then
41  echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2
42  echo "Also, you must run \"make dist\" before running this script." 1>&2
43  exit 0
44fi
45
46if [ \! -r "$archive" ]
47then
48  echo "Cannot find $archive. Run \"make dist\" first." 1>&2
49  exit 0
50fi
51
52# Create the directory where the input lives, and where the output should live
53RPM_SOURCE_DIR="/tmp/rpmsource-$fullname"
54RPM_BUILD_DIR="/tmp/rpmbuild-$fullname"
55
56trap 'rm -rf $RPM_SOURCE_DIR $RPM_BUILD_DIR; exit $?' EXIT SIGHUP SIGINT SIGTERM
57
58rm -rf "$RPM_SOURCE_DIR" "$RPM_BUILD_DIR"
59mkdir "$RPM_SOURCE_DIR"
60mkdir "$RPM_BUILD_DIR"
61
62cp "$archive" "$RPM_SOURCE_DIR"
63
64rpmbuild -bb rpm/rpm.spec \
65  --define "NAME $PACKAGE" \
66  --define "VERSION $VERSION" \
67  --define "_sourcedir $RPM_SOURCE_DIR" \
68  --define "_builddir $RPM_BUILD_DIR" \
69  --define "_rpmdir $RPM_SOURCE_DIR"
70
71# We put the output in a directory based on what system we've built for
72destdir=rpm-unknown
73if [ -r /etc/issue ]
74then
75   grep "Red Hat.*release 7" /etc/issue >/dev/null 2>&1 && destdir=rh7
76   grep "Red Hat.*release 8" /etc/issue >/dev/null 2>&1 && destdir=rh8
77   grep "Red Hat.*release 9" /etc/issue >/dev/null 2>&1 && destdir=rh9
78   if grep Fedora /etc/issue >/dev/null; then
79	destdir=fc`grep Fedora /etc/issue | cut -d' ' -f 4`;
80   fi
81fi
82
83rm -rf "$destdir"
84mkdir -p "$destdir"
85# We want to get not only the main package but devel etc, hence the middle *
86mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir"
87
88echo
89echo "The rpm package file(s) are located in $PWD/$destdir"
90