#!/bin/bash -e

source $(dirname $0)/shelly.conf

run=$(curl -s "${SHELLY_RPC}/Script.GetStatus?id=${SCRIPT_ID}" | jq .running)
test "$run" = true && exit

echo "restart script"
curl -s "${SHELLY_RPC}/Script.Start?id=${SCRIPT_ID}"

run=$(curl -s "${SHELLY_RPC}/Script.GetStatus?id=${SCRIPT_ID}" | jq .running)
if [ $run = true ]; then
    echo "OK"
else
    echo "ERROR"
fi

echo
curl -s "${SHELLY_RPC}/Sys.GetStatus" | jq .