#! /bin/bash

. ./function.sh

ClearEeprom;
ShowStartInstall;

Return=$(SetStaticIP);
if [ $Return -eq -1 ]; then
    ShowNetworkConnectionError;
    Beep 4 0.001 0.5;
    exit 0;
fi

Return=$(CheckTarFileName);
if [ $Return -eq -1 ]; then
    ShowCheckTarFileNameError;
    Beep 4 0.001 0.5;
    exit 0;
fi

Beep 1 1 0.001;
ClearApp;
RemoveApp;
RemoveFactory;
CreateEnvironment;
CopyInstallFileToEnvironment;

Return=$(ComparisonTarFile);
if [ $Return -eq -1 ]; then
    ShowComparisonTarFileError;
    Beep 4 0.001 0.5;
    exit 0;
fi

DecompressedFile;
CopyEnvironment;
SetEnvironment;

Install_openvpn_if_needed;

ChmodFile;
DeleteResidualFile;
Sync;
SetEeprom "Successful update and restore by SD";
UpdateComPortSetting;
sync;
ShowInstallSuccess;
Beep 1 1 0.5;
Beep 1 1 0.001;
