#!/usr/bin/env bash
NEW=$(curl -s https://simplepos.mysolution.apps.lu/AppOrderPrinter/version.txt)
if [ "$?" = "0" ]; then
  CURRENT=$(sha256sum /opt/AppOrderPrinter.jar)
  if [ "$NEW" != "$CURRENT" ]; then
    echo "Downloading new version"
    wget https://simplepos.mysolution.apps.lu/AppOrderPrinter/AppOrderPrinter.jar -O /opt/AppOrderPrinter-new.jar || rm /opt/AppOrderPrinter-new.jar
    [ $? -eq 0 ] && mv -f /opt/AppOrderPrinter-new.jar /opt/AppOrderPrinter.jar
  fi
else
  echo "non-zero exit code: $?"
fi
java -jar /opt/AppOrderPrinter.jar
