Add languagestandard variable
[MPC.git] / rpm / buildrpm.sh
blob182ab11b3059bd1cadc4a202bc286578622ed996
1 #!/bin/sh
3 # ******************************************************************
4 # Author: Chad Elliott
5 # Date: 8/13/2009
6 # Description: Create an MPC rpm based on the current version number.
7 # ******************************************************************
9 ## First find out where this script is located
10 if [ "$0" != "`basename $0`" ]; then
11 if [ "`echo $0 | cut -c1`" = "/" ]; then
12 loc="`dirname $0`"
13 else
14 loc="`pwd`/`dirname $0`"
16 else
17 ## Do my own 'which' here
18 loc="."
19 for i in `echo $PATH | tr ':' '\012'`; do
20 if [ -x "$i/$0" -a ! -d "$i/$0" ]; then
21 loc="$i"
22 break
24 done
27 ## Now, get back to where the main MPC script is located
28 while [ ! -x $loc/mpc.pl ]; do
29 loc=`dirname $loc`
30 done
32 ## Build up the packager name and email address
33 if [ -z "$REPLYTO" ]; then
34 DOMAIN=`hostname | sed 's/[^\.][^\.]*\.//'`
35 FULLDOMAIN=`echo $DOMAIN | grep '\.'`
36 if [ -z "$DOMAIN" -o -z "$FULLDOMAIN" ]; then
37 RESOLVDOMAIN=`grep '^search' /etc/resolv.conf | sed 's/.*\s//'`
38 FULLDOMAIN=`echo $RESOLVDOMAIN | grep '\.'`
39 if [ -z "$DOMAIN" -o -n "$FULLDOMAIN" ]; then
40 DOMAIN=$RESOLVDOMAIN
43 REPLYTO="$LOGNAME@$DOMAIN"
45 PACKAGER=`getent passwd $LOGNAME | cut -d: -f5`
46 if [ -z "$PACKAGER" ]; then
47 PACKAGER=$CL_USERNAME
49 if [ -z "$PACKAGER" ]; then
50 PACKAGER="<$REPLYTO>"
51 else
52 PACKAGER="$PACKAGER <$REPLYTO>"
55 ## Save the MPC version
56 VERSION=`$loc/mpc.pl --version | sed 's/.*v//'`
58 ## This is where we'll create the spec file and do the work
59 WDIR=/tmp/mpc.$$
61 ## This is the directory name that RPM expects
62 MDIR=MPC-$VERSION
64 ## This corresponds to BuildRoot in MPC.spec
65 BDIR=/tmp/mpc
67 ## This is the final install directory and corresponds to the %files section
68 ## of MPC.spec
69 FDIR=/usr/lib/MPC
71 ##Check if build and work directory already exist
72 if [ -d "$BDIR" -o -f "$BDIR" ]; then
73 echo "Necessary directory $BDIR already exists."
74 echo "Exiting."
75 exit
78 if [ -d "$WDIR" -o -f "$WDIR" ]; then
79 echo "Necessary directory $WDIR already exists."
80 echo "Exiting."
81 exit
84 ## Create our working directory
85 mkdir -p $WDIR
87 ## The directory where RPM will place the resulting file
88 if [ -x /usr/src/redhat -a -w /usr/src/redhat ]; then
89 RPMLOC=/usr/src/redhat
90 elif [ -x /usr/src/packages -a -w /usr/src/packages ]; then
91 RPMLOC=/usr/src/packages
92 else
93 RPMLOC=$WDIR/rpmbuild
94 mkdir -p $RPMLOC
95 mkdir -p $RPMLOC/BUILD
96 mkdir -p $RPMLOC/RPMS
97 mkdir -p $RPMLOC/SOURCES
100 ## Make the spec file
101 cd $WDIR
102 sed "s/VERSION/$VERSION/; s/PACKAGER/$PACKAGER/; s!FINALDIR!$FDIR!" $loc/rpm/MPC.templ > MPC.spec
104 ## Make a copy of the original MPC source to the new directory
105 mkdir -p $MDIR/$FDIR
106 cd $loc
107 tar --exclude=.git\* -cf - . | (cd $WDIR/$MDIR/$FDIR; tar -xf -)
109 ## Create the build source tar.bz2
110 cd $WDIR
111 tar --owner root --group root -cf $RPMLOC/SOURCES/$MDIR.tar $MDIR
112 bzip2 -9f $RPMLOC/SOURCES/$MDIR.tar
114 ## Perform the RPM creation step
115 rm -rf $BDIR
116 mkdir -p $BDIR
117 rpmbuild --define "_topdir $RPMLOC" --define "_buildrootdir $BDIR" --define "buildroot $BDIR" --define "__arch_install_post %{nil}" -bb MPC.spec
119 if [ "$RPMLOC" = "$WDIR/rpmbuild" ]; then
120 echo "Copying rpm to $loc/rpm"
121 cp $RPMLOC/RPMS/*/*.rpm $loc/rpm
124 ## Clean everything up
125 cd ..
126 rm -rf $WDIR $BDIR