#!/bin/sh
#####################################################################
# Script per la creazione del pacchetto python-gammu
# OS Version : Slackware 12.0
# http://www.cihar.com/gammu/python/
#####################################################################
set -x
#---- MODIFICABILI --------------------------------------------------
SOFTWARE="python-gammu"
VERSION="0.25"
ARCH="i486"
BUILD="1ac"
TMP=""
CWD=""

#---- COSTANTI ------------------------------------------------------
ERR_NO_VERSION=1

#---- PROCEDURE -----------------------------------------------------
print_error_and_exit() {
	case $1 in
		$ERR_NO_VERSION) 
			echo "Manca la versione del package"
			;;
		*)
			echo "Errore non specificato"
			;;
	esac
	exit $1
}


#--------------------------------------------------------------------
# Controllo dei parametri specificati settando i valori di default, dove possibile, per quelli non assegnati.

# Verifica e completamento variabili 
[ "$VERSION" == "" ] && print_error_and_exit $ERR_NO_VERSION
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

CWD=${CWD:-`pwd`}
TMP=${TMP:-/tmp}
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
PKG=$TMP/package-tar
rm -rf $PKG
mkdir -p $PKG

# Configurazione e compliazione
cp ${SOFTWARE}-${VERSION}.tar.bz2 $TMP
cd $TMP
rm -rf ${SOFTWARE}-${VERSION}
bunzip2 ${SOFTWARE}-${VERSION}.tar.bz2
tar xvf ${SOFTWARE}-${VERSION}.tar
cd ${SOFTWARE}-${VERSION}
chown -R root:root .

python setup.py build
python setup.py install --prefix=$PKG --install-lib=$PKG/usr/lib/python2.4/site-packages

mkdir -p $PKG/usr/doc/$SOFTWARE-$VERSION
cp -a README AUTHORS COPYING NEWS examples $PKG/usr/doc/$SOFTWARE-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $CWD
cp -a *.SlackBuild $PKG/usr/doc/$SOFTWARE-$VERSION
cp -a slack-desc $PKG/usr/doc/$SOFTWARE-$VERSION
chown -R root:root $PKG/usr/doc/$SOFTWARE-$VERSION

cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg --linkadd y --chown n $CWD/$SOFTWARE-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$SOFTWARE-$VERSION
 rm -rf $PKG
fi
set +x
