echo $1

script_version="1.0"

DeviceMode=""

if [ -f "./DeviceModel.ini" ]; then
    DeviceMode=$(cat ./DeviceModel.ini | head -n 1)
    if [ -z "$DeviceMode" ]; then
        exit
    fi
else
    if [ -f "/etc/init.d/rcS" ]; then
        DeviceMode="NX"
        echo "If the installation conditions are not met, please contact technical support."
        exit 0
    else
        if [ ! -d "/etc/device" ] || [ ! -f "/etc/device/sys.config" ]; then
            DeviceMode="PX_588"
        else
            DeviceMode=$(cat /etc/device/sys.config)
            if [ -z "$DeviceMode" ]; then
                DeviceMode="PX_588"
            fi
        fi
    fi

    if [ "$DeviceMode" = "PX_588" ]; then
        if [ ! -d "/home/rpdzkj" ]; then
            echo "If the installation conditions are not met, please contact technical support."
            exit 0
        fi
    fi
fi

echo "$DeviceMode"
local=${pwd}

PASSWD=""

run_with_sudo() {
   echo "${PASSWD}" | sudo -S "$@" 
}


if [ "$DeviceMode" = "NX" ]; then
    PASSWD="root"
elif [ "$DeviceMode" = "PX_588" ] || [ "$DeviceMode" = "PXR_588" ] ; then
    PASSWD="rpdzkj"
else
    PASSWD="htra"
fi

run_with_sudo_stdin() {
    echo "${PASSWD}" | sudo -S -p '' "$@"
}

Updater_Name="HTRA_Updater_Linux-0.55.63.5"

run_with_sudo LinkFiles.sh
run_with_sudo chmod 777 $Updater_Name
sudo ./$Updater_Name

exit
