#!/bin/sh
# file: scripts/erase.sh

# this script erases flash memory only on selected firmware versions;
 
# ====================================================================
# symbols;
# --------------------------------------------------------------------

. /etc/environment
. ${SCRIPTS}/hardware.sh
. ${SCRIPTS}/firmware.sh

# ====================================================================
# query connection;
# --------------------------------------------------------------------

echo -n "Interface [${ETH}]: "; read  
if [ ! -z ${REPLY} ]; then
	ETH=${REPLY}
fi

# ====================================================================
# check connection;
# --------------------------------------------------------------------

int6kwait -xqsi ${ETH}
if [ ${?} != 0 ]; then
	echo "Device is not connected"
	exit 1
fi

# ====================================================================
# read device DAK;
# --------------------------------------------------------------------

DAK=$(int6kid -i ${ETH} -D)

# ====================================================================
# erase NVRAM on local device; only works on some firmware versions;  
# --------------------------------------------------------------------

int6kp -i ${ETH} -D ${DAK} -E
if [ ${?} != 0 ]; then
	exit 1
fi

# ====================================================================
# return success;
# --------------------------------------------------------------------

exit 0