#!/bin/sh

#gestion du bouton poussoir

N=0
TEST=0
T=0
#boucle infinie 
while :; do

sleep 2

gpio get 82 > /dev/null 

TEST=$?
if [ $TEST = 0 ];then
N=`expr $N + 1`

let "a = N"
let "b = a % 2"

echo "Valeur a: $a Valeur b:$b"

if [ $b = 0 ];then

gpio set 80

else
gpio clear 80

fi


#le button est relaché ou pas appuye choix de validation des actions
else  


if [ $T = 2 ];then
echo "PRISE EN MAIN DISTANCE"
T=0
elif [ $N -gt 5 ];then
echo "REINITIALISATION!!!!"
#sed '/export ADRESSE_IP/export IP_MODE/d'  /etc/ip_config > /etc/ip_config_backup
sed '/export ADRESSE_IP/d;/export IP_MODE/d'  /etc/ip_config > /etc/ip_config_backup
echo 'export ADRESSE_IP="192.168.0.158"'  >> /etc/ip_config_backup

#sed '/export IP_MODE/d' /etc/ip_config > /etc/ip_config_backup
echo 'export IP_MODE="DHCP"'  >> /etc/ip_config_backup

cp /etc/ip_config_backup /etc/ip_config
chmod 777 /etc/ip_config
source /etc/ip_config
sleep 2
reboot


elif [ $N -gt 2 ];then                                                 
echo "REBOOT" 
sleep 2
reboot



fi
N=0
fi

echo $N
#echo $TEST
#echo $T

done
