#!/bin/bash

path=`dirname $0`
source $path/meteo.cfg
source $path/choicet

for p in `ps aux | grep [c]onkyrc_meteo_english_gen |awk '{ print $2}'`; do kill -9 $p;done;
for q in `ps aux | grep [c]onkyrc_meteo_english_cc |awk '{ print $2}'`; do kill -9 $q;done;
for r in `ps aux | grep [c]onkyrc_meteo_english_5j |awk '{ print $2}'`; do kill -9 $r;done;
for s in `ps aux | grep [c]onkyrc_meteo_english_lu |awk '{ print $2}'`; do kill -9 $s;done;
for i in `ps aux | grep [m]eteofived |awk '{ print $2}'`; do kill -9 $i;done;
for i in `ps aux | grep [m]eteocurrent |awk '{ print $2}'`; do kill -9 $i;done;
for i in `ps aux | grep [m]eteoall |awk '{ print $2}'`; do kill -9 $i;done;

conky -c ${DirShell}/.conkyrc_loading&

############# Current Conditions - curr_cond file ####################

${DirShell}/current.sh

###################### On n days - detailsn file #####################

${DirShell}/five_days.sh

###################### now - noww file ###############################

${DirShell}/noww.sh

############### Icons wind - direction and force #####################

${DirShell}/wind_icons.sh

################### Messages Day1 - mess2 file ##################################

cp ${DirShell}/mess ${DirShell}/mess2
#sed -n 2p ${DirShell}/mess | fmt -s -w 108 | sed -e ':boucle;s/^.\{1,108\}$/ & /; t boucle' >> ${DirShell}/mess2
#sed -n 3p ${DirShell}/mess | fmt -s -w 108 | sed -e ':boucle;s/^.\{1,108\}$/ & /; t boucle' >> ${DirShell}/mess2

############# Cutting and centering messages - messages file#####################

${DirShell}/messages.sh

############# Cutting Messages meteodetails - messagesdetails file#####################

${DirShell}/messagesdetails.sh

############# Lunar Calendar - moon_phase_lunaire file ###############

${DirShell}/moon_calendar.sh

#################### List of days - listj file #######################

${DirShell}/listj.sh

################### days in complete centering listj2 ################

${DirShell}/listj2.sh

############ Current day in vertical text converted to png ###########

text=$(sed -n '1p'  ${DirShell}/listj2)
convert -font CorporateMonoExtraBold -pointsize 19 -gravity center \
            -size 18x125 xc:none -fill "#3BFB00" -annotate 90x90+0+0 $text \
            ${DirShell}/icones/base/daycc_v.png

### Centering wind, temperature (°F or °C), date, location and hour data in the centering file

${DirShell}/centering.sh

######################################################################

for i in `ps aux | grep [c]onkyrc_loading |awk '{ print $2}'`; do kill -9 $i;done;
rm ${DirShell}/loading
echo "OK" > ${DirShell}/finish

### File monitoring data updates Accuweather limited to 40 lines #####

no=$(wc -l ${DirShell}/suivi | cut -c-2)
if [ $no -eq 40 ]
	then
	sed -i -e '1d' ${DirShell}/suivi
fi
${DirShell}/suivi_maj.sh

################### Redisplay panel after update #####################

if [[ -n $p ]]
	then
  meteogene.sh &
#	conky -c ~/.conkyrc_meteo_english_gen &
	if [[ -n $attente ]]
		then
		~/conky/meteo_english/attente_cc.sh $attente
	fi
fi

if [[ -n $q ]]
	then
  meteocce.sh &
#	conky -c ~/.conkyrc_meteo_english_cc &
	if [[ -n $attente ]]
		then
		~/conky/meteo_english/attente_cc.sh $attente
	fi
fi

if [[ -n $r ]]
	then
  meteo5je.sh &
#	conky -c ~/.conkyrc_meteo_english_5j &
	if [[ -n $attente ]]
		then
		~/conky/meteo_english/attente_5j.sh $attente
	fi
fi

if [[ -n $s ]]
	then
  meteolue.sh
#	conky -c ~/.conkyrc_meteo_english_lu &
	if [[ -n $attente ]]
		then
		~/conky/meteo_english/attente_lu.sh $attente
	fi
fi

rm ${DirShell}/finish

exit 0
