#!/bin/sh
#------------------------------------------------------------------------------#
# Product Initialize Script (from USB disc)
#
# Finish Regsister MAC.
#------------------------------------------------------------------------------#
CUR_PATH=`pwd`
CONFIG="../config"
FILE_MAC0_REG_READ="mac0_reg_read"
FILE_MAC1_REG_READ="mac1_reg_read"
SN_PATH="../../sn"
MAC0=`ifconfig | grep eth0 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5}'`
MAC1=`ifconfig | grep eth1 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5}'`
if [ $MAC0 = $MAC1 ]; then
MAC_SETTED=1
echo "mac_setted is $MAC_SETTED"
MAC0=`ifconfig | grep eth0 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
MAC1=`ifconfig | grep eth1 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
else
MAC_SETTED=0
echo "mac_setted is $MAC_SETTED"
ETH0_MAC=`cat $FILE_MAC0_REG_READ`
ETH1_MAC=`cat $FILE_MAC1_REG_READ`
MAC0=`echo $ETH0_MAC | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
MAC1=`echo $ETH1_MAC | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
fi
echo
echo "=========================================================="
echo "==== [`basename $0`]: Regsisting ... ===="
echo "===="
rm /sysconf/etc/interfaces
cd $CUR_PATH
cp ../mainboard/interfaces /sysconf/etc/
echo "[dbg]: interfaces file is OK."
if [ ! -f "/usr/local/rc_hdzx" ]; then
cd $CUR_PATH
cp ../mainboard/rc_hdzx /usr/local/
cd /usr/local/
mv rc_hdzx rc
echo "[dbg]: rc file is OK."
fi
if [ ! -d "/usr/local/hdzx/" ]; then
cd $CUR_PATH
cp ../mainboard/hdzx /usr/local/ -rf
echo "[dbg]: hdzx dir is OK."
else
echo "[dbg]: hdzx dir is already OK."
fi
if [ ! -f "/usr/local/lib/libcanio.so.1.0" ]; then
cd $CUR_PATH
cp ../mainboard/lib/* /usr/local/lib/ -rf
cd /usr/local/lib/
./lnmk
rm lnmk
echo "[dbg]: lib dir is OK."
else
echo "[dbg]: lib dir is already OK."
fi
echo "==== ----------[eth0 MAC] = $MAC0------------"
echo "==== ----------[eth1 MAC] = $MAC1------------"
echo "===="
cd $CUR_PATH
if [ ! -f "$SN_PATH/$MAC0/sn" ]; then
echo "==== [`basename $0`]: Error: SN file is NOT FIND! ===="
echo "==== [`basename $0`]: Regsiter is Failed! ===="
exit 1
else
rm /usr/local/hdzx/sn
cp $SN_PATH/$MAC0/sn /usr/local/hdzx/
echo "==== [`basename $0`]: Regsiter Finshed. ===="
fi
if [ $MAC_SETTED -eq 0 ]; then
echo "==== [`basename $0`]: Checking the Regsister will reboot! ===="
else
echo "==== [`basename $0`]: Checking the Regsister ... ===="
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
cd /usr/local/hdzx/
./bsa300&
echo "Sleep 4 sec for print the Reginfo ..."
sleep 5
PROC_NAME="./bsa300"
ProcNumber=`ps -ef|grep -w $PROC_NAME|grep -v grep|wc -l`
if [ $ProcNumber -le 0 ]; then
echo "==== [`basename $0`]: Error: SN file is WRONG! ===="
echo "==== [`basename $0`]: Regsister is Failed! ===="
exit 1
else
echo "==== [`basename $0`]: Finished the Regsister Check. ===="
fi
fi
echo "=========================================================="
echo
sync
#------------------------------------------------------------------------------#
# End
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Product Initialize Script (from USB disc)
#
# Finish Regsister MAC.
#------------------------------------------------------------------------------#
CUR_PATH=`pwd`
CONFIG="../config"
FILE_MAC0_REG_READ="mac0_reg_read"
FILE_MAC1_REG_READ="mac1_reg_read"
SN_PATH="../../sn"
MAC0=`ifconfig | grep eth0 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5}'`
MAC1=`ifconfig | grep eth1 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5}'`
if [ $MAC0 = $MAC1 ]; then
MAC_SETTED=1
echo "mac_setted is $MAC_SETTED"
MAC0=`ifconfig | grep eth0 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
MAC1=`ifconfig | grep eth1 | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
else
MAC_SETTED=0
echo "mac_setted is $MAC_SETTED"
ETH0_MAC=`cat $FILE_MAC0_REG_READ`
ETH1_MAC=`cat $FILE_MAC1_REG_READ`
MAC0=`echo $ETH0_MAC | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
MAC1=`echo $ETH1_MAC | awk -F: '{print $1 $2 $3 $4 $5 $6}'`
fi
echo
echo "=========================================================="
echo "==== [`basename $0`]: Regsisting ... ===="
echo "===="
rm /sysconf/etc/interfaces
cd $CUR_PATH
cp ../mainboard/interfaces /sysconf/etc/
echo "[dbg]: interfaces file is OK."
if [ ! -f "/usr/local/rc_hdzx" ]; then
cd $CUR_PATH
cp ../mainboard/rc_hdzx /usr/local/
cd /usr/local/
mv rc_hdzx rc
echo "[dbg]: rc file is OK."
fi
if [ ! -d "/usr/local/hdzx/" ]; then
cd $CUR_PATH
cp ../mainboard/hdzx /usr/local/ -rf
echo "[dbg]: hdzx dir is OK."
else
echo "[dbg]: hdzx dir is already OK."
fi
if [ ! -f "/usr/local/lib/libcanio.so.1.0" ]; then
cd $CUR_PATH
cp ../mainboard/lib/* /usr/local/lib/ -rf
cd /usr/local/lib/
./lnmk
rm lnmk
echo "[dbg]: lib dir is OK."
else
echo "[dbg]: lib dir is already OK."
fi
echo "==== ----------[eth0 MAC] = $MAC0------------"
echo "==== ----------[eth1 MAC] = $MAC1------------"
echo "===="
cd $CUR_PATH
if [ ! -f "$SN_PATH/$MAC0/sn" ]; then
echo "==== [`basename $0`]: Error: SN file is NOT FIND! ===="
echo "==== [`basename $0`]: Regsiter is Failed! ===="
exit 1
else
rm /usr/local/hdzx/sn
cp $SN_PATH/$MAC0/sn /usr/local/hdzx/
echo "==== [`basename $0`]: Regsiter Finshed. ===="
fi
if [ $MAC_SETTED -eq 0 ]; then
echo "==== [`basename $0`]: Checking the Regsister will reboot! ===="
else
echo "==== [`basename $0`]: Checking the Regsister ... ===="
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
cd /usr/local/hdzx/
./bsa300&
echo "Sleep 4 sec for print the Reginfo ..."
sleep 5
PROC_NAME="./bsa300"
ProcNumber=`ps -ef|grep -w $PROC_NAME|grep -v grep|wc -l`
if [ $ProcNumber -le 0 ]; then
echo "==== [`basename $0`]: Error: SN file is WRONG! ===="
echo "==== [`basename $0`]: Regsister is Failed! ===="
exit 1
else
echo "==== [`basename $0`]: Finished the Regsister Check. ===="
fi
fi
echo "=========================================================="
echo
sync
#------------------------------------------------------------------------------#
# End
#------------------------------------------------------------------------------#