#! /bin/bash

. ./function.sh
led='/usr/sbin/iTalk/led';

$led -l2 -o0 ;$led -l2 -o0; $led -l3 -o0;

Beep 1 1 0;
#ClearEeprom;
blink &
BLINK_PID=$!;
ShowStartInstall;

Return=$(CheckTarFileName);
if [ $Return -eq -1 ]; then
    ShowCheckTarFileNameError;
    Beep 4 0.25 0.1;
    kill $BLINK_PID;
    $led -l2 -o1 ;
    exit 0;
fi

#Beep 1 1 0;
ClearApp;
RemoveApp;
RemoveFactory;
CreateEnvironment;
CopyInstallFileToEnvironment;

Return=$(ComparisonTarFile);
if [ $Return -eq -1 ]; then
    ShowComparisonTarFileError;
    Beep 4 0.25 0.1;
    kill $BLINK_PID;
    $led -l2 -o1 ;
    exit 0;
fi

DecompressedFile;
CopyEnvironment;
SetEnvironment;
Install_openvpn_if_needed;
ChmodFile;
UpdateService /;
DeleteResidualFile;
MigrateRestartUnit;
Sync;
SetStaticIP
SetEeprom "Successful update and restore by SD";
ShowInstallSuccess;
kill $BLINK_PID;
$led -l2 -o1 ;
Beep  2 1 0.5;
$led -l2 -o0 ;
