#!/bin/bash

BASEDIR=$(dirname $0)

# Set the virtual environment path. You may need to update this if you're using a different virtual environment
VIRTUAL_ENV="$HOME/.virtualenvs/pimoroni/bin"

ID=$(id -u)

# Avoid using sudo if we're already root
SUDO=sudo
if [ $ID -eq 0 ]
then
   SUDO=""
fi

if [ -d $VIRTUAL_ENV ]
then
   sudo -E env PATH="$VIRTUAL_ENV:$PATH" python3 -u $BASEDIR/automationhatlink.py $@
else
   sudo python3 -u $BASEDIR/automationhatlink.py $@
fi

# For debugging issues with the python library, comment out the above line and uncomment the following line
# This will log all output to /tmp/hat.log
# sudo python3 -u $BASEDIR/automationhatlink.py $@ --verbose 2>&1 | tee -a /tmp/hat.log