#!/bin/bash
cd /home/itender/itender || exit 1

if [ -z "$1" ]; then
  git pull "https://tobiash:!IwedwrimmVeudiweN!@git.dateien.org/tobiash/itender.git" --quiet || exit 1
  ./update.sh true
else
  cd ./server
  yarn install
  yarn run compile
  cd ./arduino/itender/
  arduino-cli compile --fqbn arduino:avr:mega itender.ino || true
  sleep 1
  timeout 30 arduino-cli upload --port /dev/ttyACM0 --fqbn arduino:avr:mega itender.ino
  sleep 1
  sudo sh -c "systemctl restart itender &"
fi
exit 0
