#!/bin/bash

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

ClearEeprom;
ShowStartInstall;
$led -l2 -o0 ;$led -l2 -o0; $led -l3 -o0;
blink &
BLINK_PID=$!;

#Beep 1 1 0;
ClearApp;
RemoveApp;
CopyFactoryFileToEnvironment;

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

DecompressedFile;
CopyEnvironment;
SetEnvironment;
ChmodFile;
#DeleteResidualFile;
Install_openvpn_if_needed;
DeleteFactoryResidualFile;
clear_openvpn_conf;
ResetFirewall;
ClearRestartUnit;
Sync;
SetStaticIP;
SetEeprom "Restore Factory Settings Successfully";
ShowInstallSuccess;
kill $BLINK_PID;
$led -l2 -o1 ;
Beep  2 1 0.5;
$led -l2 -o0 ;
