#!/bin/sh


# This is an example script used by one of the developers to ease
# the workload.  It's not intended to be used by the general
# userbase.  It's included with the Xastir sources so that it
# doesn't get lost if the developer should suddenly drop out of
# sight.


# Run this as root from the xastir source directory (top-level).
# It runs some # of the below commands as "archer", others as "root".
# When the build is complete it copies the RPM files to the Wetnet server.



# Run these commands as "root".
#
echo
echo
echo "***********************************"
echo "***** Cleaning up Directories *****"
echo "***********************************"
rm -rf /usr/src/packages/SOURCES/xastir*
rm -rf /usr/src/packages/RPMS/x86_64/xastir*
rm -rf /usr/src/packages/SRPMS/xastir*



# Run these commands as "archer".
#
echo "Davis..."
su -c " cd Davis; ./bootstrap.sh; ./configure; make clean" archer
echo "LaCrosse..."
su -c " cd LaCrosse; ./bootstrap.sh; ./configure; make clean" archer
# These are just to get the configure and spec files in shape.
# Configure options don't matter yet here.
echo
echo
echo "********************************************"
echo "***** Setting up CONFIG and SPEC files *****"
echo "********************************************"
su -c " cd Davis; ./bootstrap.sh; ./configure; make clean" archer
su -c " cd LaCrosse; ./bootstrap.sh; ./configure; make clean" archer
#
# NOTE:  CPPFLAGS below is for OpenSUSE specifically:  Remove it if building RPMs for other Linux OS'es.
su -c " ./bootstrap.sh; ./configure CPPFLAGS='-I/usr/include/libgeotiff'; make clean; make dist" archer



# Run these commands as "root":
#
cp xastir-*.tar.gz /usr/src/packages/SOURCES/.



# Run these commands as "root":
#
# Build minimum system (only ImageMagick and internal Shapelib
# included), binary package only.  Rename this file so that the
# following rpmbuild doesn't overwrite it.
echo
echo
echo "*******************************************"
echo "***** Creating MINIMUM binary package *****"
echo "*******************************************"
(cd /usr/src/packages/SOURCES; tar xzf xastir-*.tar.gz; rpmbuild -bb --clean xastir-2.0.8/xastir-min.spec)
mv /usr/src/packages/RPMS/x86_64/xastir-2.0.8-1.x86_64.rpm /usr/src/packages/RPMS/x86_64/xastir-2.0.8-min.x86_64.rpm
#
#
# Build maximum system (all optional libraries included), binary and
# source packages.
echo
echo
echo "***************************************************************"
echo "***** Creating MAXIMUM binary package plus source package *****"
echo "***************************************************************"
(cd /usr/src/packages/SOURCES; tar xzf xastir-*.tar.gz; rpmbuild -ba --clean xastir-2.0.8/xastir.spec)
mv /usr/src/packages/RPMS/x86_64/xastir-2.0.8-1.x86_64.rpm /usr/src/packages/RPMS/x86_64/xastir-2.0.8-max.x86_64.rpm



# Run these commands as "root":
#
# Create a local yum repository in the correct format:
mkdir /usr/tmp/repo /usr/tmp/repo/x86_64 /usr/tmp/repo/src
cp /usr/src/packages/RPMS/x86_64/* /usr/tmp/repo/x86_64
cp /usr/src/packages/SRPMS/* /usr/tmp/repo/src
#
# Create repo
(cd /usr/tmp/repo/x86_64; createrepo .)
(cd /usr/tmp/repo/src; createrepo .)
#
# Create a .tgz of the repo
(cd /usr/tmp/repo; tar czvf xastir-repo.tgz *)



# Run these commands as "archer":
#
echo
echo
echo "**************************************************************"
echo "***** Copying packages to Wetnet and setting permissions *****"
echo "**************************************************************"
#su -c " cd /usr/bin; scp /usr/src/packages/RPMS/x86_64/xastir-2.0.5-max.x86_64.rpm we7u@wetnet.net:/home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/x86_64/." archer
#su -c " cd /usr/bin; scp /usr/src/packages/RPMS/x86_64/xastir-2.0.5-min.x86_64.rpm we7u@wetnet.net:/home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/x86_64/." archer
#su -c " cd /usr/bin; scp /usr/src/packages/SRPMS/xastir-2.0.5-1.src.rpm we7u@wetnet.net:/home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/src/." archer
#su -c " cd /usr/bin; ssh -l we7u wetnet.net 'chmod 644 /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/x86_64/*.rpm'" archer
#su -c " cd /usr/bin; ssh -l we7u wetnet.net 'chmod 644 /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/src/*.rpm'" archer
#
# Copy the tgz of the repo up to Wetnet:
su -c " cd /usr/bin; scp /usr/tmp/repo/xastir-repo.tgz we7u@wetnet.net:/home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/." archer
#
# Remove the repodata files so we don't get multiples:
su -c " cd /usr/bin; ssh -l we7u wetnet.net 'rm -rf /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/x86_64/repodata /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/SuSE-12.1/src/repodata'" archer
#
# Untar the repo.  Will merge the files in with our other repo files:
su -c " cd /usr/bin; ssh -l we7u wetnet.net 'cd /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM; tar xzvf xastir-repo.tgz'" archer
#
# Remove tgz file:
su -c " cd /usr/bin; ssh -l we7u wetnet.net 'rm /home/we7u/public_html/Downloads/aprs/xastir/SUSE-RPM/xastir-repo.tgz'" archer



echo
echo
echo "***********************************"
echo "***** Cleaning up build files *****"
echo "***********************************"
rm -rf /usr/src/packages/SOURCES/xastir*
#rm -rf /usr/src/packages/RPMS/x86_64/xastir*
#rm -rf /usr/src/packages/SRPMS/xastir*
#rm -rf /usr/tmp/repo



# NOTE:  Will have to set priority of the new repository to 100 (default is 99) in order to override the OpenSuSE-distributed version of Xastir tends to be older.


