#!/bin/bash
#######################################################################
#                                                                     #
#  Check for new updates  (set on/off in settings.ini)                #
#                                                                     #
#  DO NOT CHANGE IN HERE !!!                                          #
#                                                                     #
#                                                                     #
#######################################################################


if [ -f "../settings.ini" ]; then
  echo -e "\n$(basename $0): \e[31mOnly works when started via conky!\e[m\n" > /dev/stderr
  exit
fi

if [ -f "./settings.ini" ]; then
  source "./settings.ini"
else
  echo -e "\n$(basename $0): \e[31mNo settings.ini found!\e[m\n" > /dev/stderr
  pkill -f forecast.conky
  exit
fi

if [ "$showupdates" = "yes" ]; then
  curl -s "www.cobrasoft.nl/download/conky/flipclock-weather/updates" -o ./json/updates.tmp
  newversion=$(cat ./json/updates.tmp | awk -F'=' '{print $2}')
  if [ $newversion \> $version ]; then
    echo -e "\${font Ubuntu Mono:size=15}\${voffset 130}\${alignc}\${color green}\${blink Update available!}  Version: $newversion\n\${font Ubuntu Mono:size=11}\${voffset 8}\${alignc}\${color yellow}See README.TXT for more info.${color}\${font}"
  fi
fi

rm -f ./json/updates.tmp
