#! /bin/bash
# This script work for generating rpms without Root rights
# When you create rmp's with Root rights and you have as example 
# the follow command rm -rf / in your script you are in trouble :-)
#
# Change the path names for ANONCVSDIR and RHBASE to you needs.
# 
# When you would create daily rpm's with update from CVS include
# delete the # sign at the start from the follow lines
# 
# cd $ANONCVSDIR
# cvs update -Pd
# This scipt create auotmaticly signed rpm's
# When you don't want signed rpm's change the follow line from
#
# rpmbuild -bb --sign phpgroupware-rh.spec             >> $LOGFILE 2>&1
# 
# to
# rpmbuild -bb phpgroupware-rh.spec                    >> $LOGFILE 2>&1
#  
# in the sript
# How to create GPG keys to sign your rpm's you will found in a seperate
# Document
#
# Script changed 2003 Jul 06 Reiner Jung
# Script changed 2003 Oct 16 Chris Weiss
#
# NOTES:
# to build as a user you need to have done something like the following:
# mkdir -p redhat/BUILD redhat/SOURCES redhat/SPECS redhat/SRPMS redhat/RPMS redhat/RPMS/i386
# echo "%_topdir $HOME/redhat" >> $HOME/.rpmmacros
#
# for Mandrake 9.0 and newer, you will need to edit /usr/share/spec-helper/spec-helper
# to disable the clean_files or this will make errors.

HOMEBUILDDIR=`whoami`
ANONCVSDIR=/home/$HOMEBUILDDIR/cvs/phpgroupware
RHBASE=/home/$HOMEBUILDDIR/redhat
SRCDIR=$RHBASE/SOURCES
SPECDIR=$RHBASE/SPECS
SPECFILE=phpgroupware-rh-allapp0914.spec
VERSION=`grep "%define version" $ANONCVSDIR/doc/rpm-build/phpgroupware-rh-allapp0914.spec | cut -f3 -d' '`
LOGFILE=$SPECDIR/build-$VERSION.log
MD5SUM=$SRCDIR/md5sum-$VERSION.txt

echo "Start Build Process of - $VERSION"                     > $LOGFILE
echo "---------------------------------------"              >> $LOGFILE 2>&1
date                                                        >> $LOGFILE 2>&1
cd $ANONCVSDIR
cvs update -dP                                              >> $LOGFILE 2>&1
cd $ANONCVSDIR/..
tar czvf $SRCDIR/phpgroupware-$VERSION.tar.gz phpgroupware  >> $LOGFILE 2>&1
tar cjvf $SRCDIR/phpgroupware-$VERSION.tar.bz2 phpgroupware >> $LOGFILE 2>&1
zip -r -9 $SRCDIR/phpgroupware-$VERSION.zip phpgroupware    >> $LOGFILE 2>&1
echo "End Build Process of tar.gz, tar.bz, zip"		    >> $LOGFILE 2>&1	
echo "---------------------------------------"              >> $LOGFILE 2>&1
echo "Create the md5sum file for tar.gz, tar.bz, zip"	    >> $LOGFILE 2>&1	
echo "md5sum from file phpgroupware-$VERSION.tar.gz is:"     > $MD5SUM  
md5sum $SRCDIR/phpgroupware-$VERSION.tar.gz | cut -f1 -d' ' #>> $MD5SUM  2>&1
echo "---------------------------------------"              >> $MD5SUM  2>&1
echo " "						    >> $MD5SUM  2>&1
echo "md5sum from file phpgroupware-$VERSION.tar.bz2 is:"   >> $MD5SUM  2>&1
md5sum $SRCDIR/phpgroupware-$VERSION.tar.bz2 | cut -f1 -d' '#>> $MD5SUM  2>&1
echo "---------------------------------------"              >> $MD5SUM  2>&1
echo " "						    >> $MD5SUM  2>&1
echo "md5sum from file phpgroupware-$VERSION.zip is:"       >> $MD5SUM  2>&1
md5sum $SRCDIR/phpgroupware-$VERSION.zip | cut -f1 -d' '    #>> $MD5SUM  2>&1
echo "End Build md5sum of tar.gz, tar.bz, zip"              >> $LOGFILE 2>&1
echo "---------------------------------------"              >> $LOGFILE 2>&1
echo "Build signed source files"			    >> $LOGFILE 2>&1
gpg -s $SRCDIR/phpgroupware-$VERSION.tar.gz		    #>> $LOGFILE 2>&1
gpg -s $SRCDIR/phpgroupware-$VERSION.tar.bz2		    #>> $LOGFILE 2>&1 
gpg -s $SRCDIR/phpgroupware-$VERSION.zip		    #>> $LOGFILE 2>&1
echo "End build of signed of tar.gz, tar.bz, zip"           >> $LOGFILE 2>&1
echo "---------------------------------------"              >> $LOGFILE 2>&1
cd $SPECDIR
cp -af $ANONCVSDIR/doc/rpm-build/phpgroupware-rh-allapp0914.spec ./
rpmbuild -ba --sign $SPECFILE             >> $LOGFILE 2>&1
echo "End Build Process of - $VERSION all applications"     >> $LOGFILE 2>&1
echo "---------------------------------------"              >> $LOGFILE 2>&1

