#!/bin/bash

# I call this script (_not_ as root) from within this directory
# to build the FreeGuide RPM and SRPM.  It builds the rpms in /home/andy/.rpm

RPM_TOPDIR=/home/andy/.rpm

mkdir --parents $RPM_TOPDIR/RPMS/noarch
mkdir --parents $RPM_TOPDIR/SRPMS
mkdir --parents $RPM_TOPDIR/SOURCES
mkdir --parents $RPM_TOPDIR/BUILD
mkdir --parents $RPM_TOPDIR/tmp

# Clean and build the source package of FreeGuide
cd ../../../
ant clean
ant FreeGuide-Source

# Clean up any old RPMs
rm -f installer/FreeGuide-*.rpm

rm -f $RPM_TOPDIR/RPMS/noarch/FreeGuide-*.rpm
rm -f $RPM_TOPDIR/SRPMS/FreeGuide-*.rpm
rm -f $RPM_TOPDIR/SOURCES/FreeGuide-*.tar.gz
rm -rf $RPM_TOPDIR/BUILD/FreeGuide-*
rm -rf $RPM_TOPDIR/tmp/*

# Copy in the newly-built source package
cd src/install/linux
cp -f ../../../dist/FreeGuide-*.tar.gz $RPM_TOPDIR/SOURCES/

# Build the RPM
rpmbuild --define='_topdir /home/andy/.rpm' --define='_tmppath /home/andy/.rpm/tmp' -ba freeguide.spec

# Copy the RPMs into my "installer" directory ready for upload
cp $RPM_TOPDIR/RPMS/noarch/FreeGuide-*.rpm ../../../installer/
cp $RPM_TOPDIR/SRPMS/FreeGuide-*.rpm ../../../installer/

