Home | History | Annotate | Download | only in packages
      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
     20 if [ \! -x /usr/bin/rpmbuild ]
     21 then
     22   echo "Cannot find /usr/bin/rpmbuild. Not building an rpm." 1>&2
     23   exit 0
     24 fi
     25 
     26 # Check the commandline flags
     27 PACKAGE="$1"
     28 VERSION="$2"
     29 fullname="${PACKAGE}-${VERSION}"
     30 archive=../$fullname.tar.gz
     31 
     32 if [ -z "$1" -o -z "$2" ]
     33 then
     34   echo "Usage: $0 <package name> <package version>" 1>&2
     35   exit 0
     36 fi
     37 
     38 # Double-check we're in the packages directory, just under rootdir
     39 if [ \! -r ../Makefile -a \! -r ../INSTALL ]
     40 then
     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
     44 fi
     45 
     46 if [ \! -r "$archive" ]
     47 then
     48   echo "Cannot find $archive. Run \"make dist\" first." 1>&2
     49   exit 0
     50 fi
     51 
     52 # Create the directory where the input lives, and where the output should live
     53 RPM_SOURCE_DIR="/tmp/rpmsource-$fullname"
     54 RPM_BUILD_DIR="/tmp/rpmbuild-$fullname"
     55 
     56 trap 'rm -rf $RPM_SOURCE_DIR $RPM_BUILD_DIR; exit $?' EXIT SIGHUP SIGINT SIGTERM
     57 
     58 rm -rf "$RPM_SOURCE_DIR" "$RPM_BUILD_DIR"
     59 mkdir "$RPM_SOURCE_DIR"
     60 mkdir "$RPM_BUILD_DIR"
     61 
     62 cp "$archive" "$RPM_SOURCE_DIR"
     63 
     64 rpmbuild -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
     72 destdir=rpm-unknown
     73 if [ -r /etc/issue ]
     74 then
     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
     81 fi
     82 
     83 rm -rf "$destdir"
     84 mkdir -p "$destdir"
     85 # We want to get not only the main package but devel etc, hence the middle *
     86 mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir"
     87 
     88 echo
     89 echo "The rpm package file(s) are located in $PWD/$destdir"
     90