#! /bin/sh

. ./function.sh
#2020/04/20
mkdir /tmp/Project/;
cp -rf /app/Web/public/File /tmp/Project/;
rm /tmp/Project/File/Version.txt;
rm /tmp/Project/File/Factory/Version.txt;
cp -rf /app/Web/cgi-bin /tmp/Project/;
cp -rf /app/Certificates /tmp/Project/;
cp -rf /app/DDNS /tmp/Project/;
cp -rf /app/MQTT /tmp/Project/;
cp -rf /app/runtime/project /tmp/Project/;
cp -rf /app/Wireless /tmp/Project/;
# 2020/04/20
Return=$(CheckTarFileName);
if [ $Return -eq -1 ]; then
    ShowCheckTarFileNameError;
    Beep 4 0.001 0.5;
    exit 0;
fi

ClearEeprom;
ShowStartInstall;
Beep 1 1 0.001;
ClearApp;
RemoveApp;
CreateEnvironment;
CopyInstallFileToEnvironment;

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

#RemoveFactory;
DecompressedFile;
UsbCopyEnvironment;
UsbSetEnvironment;
ChmodFile;
DeleteResidualFile;
Sync;
SetEeprom "UsbUpdate";
/Init/Device_Driver/Multi_ComPort_driver.sh;
#2020/04/20
cp -rf /tmp/Project/File /app/Web/public/;
cp -rf /tmp/Project/cgi-bin /app/Web/;
cp -rf /tmp/Project/Certificates /app/;
cp -rf /tmp/Project/DDNS /app/;
cp -rf /tmp/Project/MQTT /app/;
cp -rf /tmp/Project/project /app/runtime/;
cp -rf /tmp/Project/Wireless /app/;
rm -rf /tmp/Project/;
Sync;
# 2020/04/20
ShowInstallSuccess;
Beep 1 1 0.5;
Beep 1 1 0.001;
