#!/bin/bash

## Copyright (C) 2012 - 2020 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
## See the file COPYING for copying conditions.

true "$BASH_SOURCE pid: $$"

if [ -f /etc/default/whonixcheckd ]; then
   source /etc/default/whonixcheckd
fi

shopt -s nullglob
for i in /etc/default/whonixcheckd.d/*.conf /rw/config/default/whonixcheckd.d/*.conf /usr/local/etc/default/whonixcheckd.d/*.conf; do
   bash_n_exit_code="0"
   bash_n_output="$(bash -n "$i" 2>&1)" || { bash_n_exit_code="$?" ; true; };
   if [ ! "$bash_n_exit_code" = "0" ]; then
      echo "Invalid config file: $i
bash_n_exit_code: $bash_n_exit_code
bash_n_output:
$bash_n_output" >&2
      exit 1
   fi
   source "$i"
done

if [ "$debugging" = "true" ]; then
   set -x
   /usr/bin/whonixcheck --debug --autostart --gui --cli
else
   /usr/bin/whonixcheck --autostart --gui --cli &>/dev/null
fi

sleep 3600

while true; do

   if [ "$debugging" = "true" ]; then
      /usr/bin/whonixcheck --debug --daemon --gui --cli
   else
      /usr/bin/whonixcheck --daemon --gui --cli &>/dev/null
   fi

   sleep 3600
done
