#!/bin/bash

HYTEM_API_LOG_FILE="${HYTEM_API_LOG_FILE:-/var/log/hytem-api.log}"
HYTEM_API_PORT="${HYTEM_API_PORT:-8080}"

DEVICES_CONFIG_FILE="${DEVICES_CONFIG_FILE:-/data/config/devices.config}"

if grep -i "use_https.*=.*1" "${DEVICES_CONFIG_FILE}" >/dev/null 2>&1
then
	HYTEM_API_HTTPS="-s"
fi

while true
do
	date +"Starting Hytem external API %X at %x"
	/usr/bin/hytem-api -p  "${HYTEM_API_PORT}" "${HYTEM_API_HTTPS}"
	sleep 5
done > "${HYTEM_API_LOG_FILE}" 2>&1

