#!/bin/bash

name="${1:-cohere}"
git_url="${2:-https://github.com/advancedPhotonSource/cohere}"

# the dependencies for the python package
# sudo apt-get install python3-tifffile python3-sklearn
# sudo apt-get -f install

# the dependencies for py2dsp
apt-get install -f pristine-tar pypi2deb 

py2dsp --profile dpt --distribution unstable --revision 1 --github "${git_url}"

# if the build fails with 'unrecognized build system: pybuild' add 
# export PYBUILD_SYSTEM=distutils 
# to the debian/rules file. 



pushd ./result/"${name}-"* || exit
	cat <<-EOF | sudo tee "debian/rules" || exit
	#! /usr/bin/make -f

	#export DH_VERBOSE=1
	export PYBUILD_SYSTEM=distutils
	export PYBUILD_NAME=${name}
	%:
		dh $@ --with python3 --buildsystem=pybuild
		
	EOF
	dpkg-buildpackage -us -uc -b
popd || return

dpkg -i result/*.deb

apt-get -f install
