#!/bin/bash

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

############# Fermer les Conky Meteo ouverts ######################### 

for p in `ps aux | grep [c]onkyrc_meteo_lune_gen |awk '{ print $2}'`; do kill -9 $p;done;
for q in `ps aux | grep [c]onkyrc_meteo_lune_cc |awk '{ print $2}'`; do kill -9 $q;done;
for r in `ps aux | grep [c]onkyrc_meteo_lune_5j |awk '{ print $2}'`; do kill -9 $r;done;
for s in `ps aux | grep [c]onkyrc_meteo_lune_lu |awk '{ print $2}'`; do kill -9 $s;done;
for i in `ps aux | grep [m]eteocinqj |awk '{ print $2}'`; do kill -9 $i;done;
for i in `ps aux | grep [m]eteocourante |awk '{ print $2}'`; do kill -9 $i;done;
for i in `ps aux | grep [m]eteogenerale |awk '{ print $2}'`; do kill -9 $i;done;

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

conky -c ${DirShell}/.conkyrc_chargement&

############# Current Conditions - cond_curr file ####################

${DirShell}/courante.sh

################### Sur n Jours - detailsn file ######################

${DirShell}/cinq_jours.sh

################### Maintenant - maintenant file #####################

${DirShell}/maintenant.sh

############### Icones Vent - direction et force #####################

${DirShell}/vent_icone.sh

################### Messages Jour1 - 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

############# Découpage et Centrage Messages - messagesfr file########

${DirShell}/messagesfr.sh

####### Découpage Messages meteodetails - messagesfrdetails file #####

${DirShell}/messagesfrdetails.sh

############### Calendrier Lunaire - phases file #####################

${DirShell}/lune_calendrier.sh

################### Liste des Jours - listj file #####################
## jours complets et sur 3 lettres dans listj

${DirShell}/listj.sh

############### centrage jours complets dans listj2 ##################

${DirShell}/listj2.sh


########## Jour actuel en texte vertical converti en 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/jourcc_v.png

### centrage données vent, températures, dates et heures dans le fichier centrage

${DirShell}/centrage.sh

###################### Datas meteosat et vigilance ###################

${DirShell}/datas_satvigi.sh

echo "OK" > ${DirShell}/finish

### Fichier de suivi des mises à jours des données Accuweather limité à 40 lignes

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

############ Réaffichage panneaux après mise à jour ##################

if [[ -n $p ]]
	then
  meteogen.sh &
	#conky -c ~/.conkyrc_meteo_lune_gen &
	if [[ -n $attente ]]
		then
		~/conky/meteo+lune4/attente_cc.sh $attente
	fi
fi

if [[ -n $q ]]
	then
  meteocc.sh &
	#conky -c ~/.conkyrc_meteo_lune_cc &
	if [[ -n $attente ]]
		then
		~/conky/meteo+lune4/attente_cc.sh $attente
	fi
fi

if [[ -n $r ]]
	then
  meteo5j.sh &
	#conky -c ~/.conkyrc_meteo_lune_5j &
	if [[ -n $attente ]]
		then
		~/conky/meteo+lune4/attente_5j.sh $attente
	fi
fi

if [[ -n $s ]]
	then
  meteolu.sh
	#conky -c ~/.conkyrc_meteo_lune_lu &
	if [[ -n $attente ]]
		then
		~/conky/meteo+lune4/attente_lu.sh $attente
	fi
fi

rm ${DirShell}/finish

exit 0
