#!/bin/bash

# DEST=${1:-/etc/skel}
DEST=${HOME}


COHERE_API_KEY="yEum5b7vNJ9mOjxUp7NJS1fiyWJFlSvUeFiBeljv"

# PLugins that Use COHERE_API_KEYs get called early so so we need to put them 
# in .zshrc.pre-plugins.d so they can be loaded before the plugins are loaded.
cat <<-EOF | sudo tee "${DEST}"/.zshrc.pre-plugins.d/009_cohere.zsh
	export COHERE_API_KEY="${COHERE_API_KEY}"
EOF


git_url="${1:-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/cohere-* || exit
	dpkg-buildpackage -us -uc -b
popd || return

dpkg -i result/python3-cohere_*.deb

apt-get -f install
