#!/bin/bash

home="${HOME}/.libresign"

# all this setup shouldn't do anything if it's been set up before
cd ~
mkdir .libresign
cd .libresign

# this is decidedly bad i think, should have python packages as i 
# had originally planned
git clone https://github.com/rptr/impress-remote-js.git
cd impress-remote-js
git pull
git clone https://github.com/rptr/irpjs-client.git
cd irpjs-client
git pull

cd ~/.libresign

if [ ! -d "presentations" ]; then
    mkdir presentations
fi

if [ ! -d "env" ]; then
    virtualenv --system-site-packages -p python3 env
    source env/bin/activate
    pip3 install Flask python-libxdo gevent-websocket pillow
fi

touch playlist

# run
libo=$1

if [ ${#1} -eq 0 ]; then 
    echo "./run.sh /path/to/libreoffice"
    echo "Trying /usr/lib/libreoffice..."
    libo="/usr/lib/libreoffice"
fi

. env/bin/activate

export PYTHONPATH=$libo
export LD_LIBRARY_PATH=$libo
export UNO_PATH=$libo
export URE_BOOTSTRAP=$libo/fundamentalrc
python3 -c "import libresign.signd; libresign.signd.run_script()" $@ --libresign-home $home

