#!/bin/bash
#
# makedeb -- build Debian binary packages for URG library from source
#
# Quick script to run the necessary commands to build the binary .deb
# packages for the URG library given its Debian source package
# components.
#
# By default, the script goes about its work silently and cleans up the
# intermediate files/directories created by the package building
# process. The -v or --verbose option can be used to have the usual
# chatter created by the package building tools printed. The -k or
# --keep option can be used to keep the intermediate files/directories.
#
# NOTE: There is no magic here beyond the magic of the Debian package
# building tools. This script exists simply to obviate the need to
# remember how to build this particular package and to provide a simple
# and convenient interface to the package building process.
#

function build_it()
{
   dpkg-source -x liburg_0.1.0-1.dsc
   cd liburg-0.1.0
   debuild -us -uc
   cd ..
}

function clean_up()
{
   rm -r liburg-0.1.0 liburg_0.1.0-1_*.build liburg_0.1.0-1_*.changes
}

# Restrict executable search path
PATH=/usr/bin:/bin

# Assume user does not want the usual chatter from package building
# tools and that s/he's only interested in the end-result, i.e., the
# liburg .deb files.
QUIET=1
CLEAN=1

# Check command line options to see if user does in fact want the
# chatter and to keep the temporaries (useful, for example, when things
# don't quite work out as expected).
while [ -n "$1" ]
do
   case "$1" in
      "-v"|"--verbose") QUIET=0 ;;
      "-k"|"--keep")    CLEAN=0 ;;
   esac
   shift
done

# Build the .debs
if [ "$QUIET" = "1" ]
then
   build_it > /dev/null
else
   build_it
fi

# Clean-up intermediate files/directories created by the package
# building process.
[ "$CLEAN" = 1 ] && clean_up
