#!/bin/sh
set -e

print_help_and_exit() {
	echo "Usage: build-deb
create a deb package for this project."
	exit 1
}

# main()
if [ "$1" = "--help" ]; then
	print_help_and_exit
fi

VERSION=`grep 'version' setup.py |cut -d'"' -f 2`
DEB_PKG_NAME="{{name}}"
DEST_DIR="/opt/$DEB_PKG_NAME"
PYTHON_MODULES="{{python-pkg-name}}"
#PYTHON_MODULES=`echo */__init__.py|cut -d'/' -f1`

if [ ! -d wheelhouse ]; then
	make wheel
fi

# add dependencies on libpq5 if you use psycopg2.
fpm -t deb -s dir -n "$DEB_PKG_NAME" -v "$VERSION" --prefix "$DEST_DIR" -f \
    --depends make \
    -x '*__pycache__' \
    -x '*.pyc' \
    -x '*.pyo' \
    -x '*.deb' \
    --before-install deb-scripts/before-install.sh \
    --after-install deb-scripts/after-install.sh \
    --before-remove deb-scripts/before-remove.sh \
    Makefile README.rst setup.py utils requirements*.txt wheelhouse conf \
    $PYTHON_MODULES
