#!/bin/bash
#######################################
#                                     #
#  Calculates rotation of radar       #
#                                     #
#  PLEASE DO NOT EDIT THIS SCRIPT !   #
#                                     #
#######################################

if [ "$1" = "" ]; then
  echo -e "\n\e[31m  Can only be started from within conky!\e[m\n"
  exit
fi


# Create Number
create_nr() {
      shuf -i 10-99 -n 1 -o "./tempfiles/radar_nr"
}


# if not exist then make file with random nr between 0-100
if [ ! -f "./tempfiles/radar_nr" ]; then
  create_nr
fi


# Get number from file, add 1 and echo number
if [ "$1" = "number" ]; then
  number=$(cat "./tempfiles/radar_nr")
  if [ "$number" != "" ]; then
     if [ "$number" -lt "360" ]; then
       number=$((number+1))
     elif [ "$number" = "360" ]; then
       number="0"
     elif [ "$number" -gt "360" ]; then
       number="0"
     fi
  else
    create_nr
  fi
  echo "$number" | tee "./tempfiles/radar_nr"
fi
