#!/bin/sh

isInit=0

/root/NXServer/bin/T507_USB_enable

if [ -d "/root/NXServer" ]; then
    ServerSize=$(du -sk /root/NXServer | awk '{print $1}')
    MinSize=1000
    if [ "$ServerSize" -le "$MinSize" ]; then
        echo "NXServer is incomplete" >> /root/clean.txt
        isInit=1
        rm -r /root/NXServer
    fi
else
    echo "NXServer is emptied" >> /root/clean.txt
    isInit=1
    sync
fi

if [ "$isInit" -eq 0 ]; then
    continue
else 
    if [ -d "/opt/NXServer" ]; then
        cp -r /opt/NXServer /root/
        sync 
        chmod 777 -R /root/NXServer
        sh /root/NXServer/update.sh
    fi
fi