#!/bin/sh

# tp setting last update Wed Jun 15 13:43:37 HKT 2022


# WS program for 4840-544 USB Sound
# Remember to edit the outlet code in /pos71x/waiting/ws.xml
if [ $STATION = "99" ]; then
    cd /pos71x/waiting
    ./ws &
    cd ..
fi

if [ $STATION = "03"; then
   insmod /cust/PS3415E.ko
   /pos71x/touch.sh
fi 

# SMS Function
if [ $STATION = "99" ]; then
    log=sms.log
    cd /pos71x/sms
    #export GSM_DEBUG=1
    cp sms_srv sms_srv_$STATION
    date >> $log
    ./sms_srv_$STATION >> $log
    cd ..
fi

# Set Netmos Com Card
if [ $STATION = "99" ]; then
/pos71x/com_card/start
fi

# Hardcode Touch Port to /dev/touch
# Com Port Started from Com1=64,Com2=65,Com3=66,Com4=67,Com5=68.....
case $STATION
in
99)
    /pos71x/com_card/mknod /dev/touch c 4 68
    /pos71x/com_card/setserial /dev/touch port 0x02e0 autoconfig irq 18
    ;;
98)
    /pos71x/com_card/mknod /dev/touch c 4 68
    /pos71x/com_card/setserial /dev/touch port 0x03f8 autoconfig irq 18
    ;;
esac   

# Standalone backup to USB Flash Memory
if [ $STATION = "S9" ]; then					
    /etc/rc.d/rc.backup & >/dev/null 2&>1
fi

# This Machine Load Hasp driver
if [ $STATION = "99" ]; then
    /pos71x/hasp/rc.hasp
fi

# Copy FTP_LOG to FTP
if [ -f /pos71x/ftp*.log ]; then
    cp /pos71x/ftp*.log /cust/log
fi

# touch.sh for USB touch
if [ $STATION = "99" ]; then
    /pos71x/touch.sh
fi

# Log Terminal's Hardware setting 
#    echo This terminal $STATION is using /pos71x/tp                                                              >  /pos71x/log/terminal/station$STATION\_hardware.txt
#    echo -------------------------------------- This is Network Card Setting ----------------------------------- >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    ifconfig                                                                                                     >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    echo -------------------------------------- This is Boot Up Message ---------------------------------------- >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    dmesg                                                                                                        >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    echo -------------------------------------- This is PCI Setting -------------------------------------------- >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    if [ -f /proc/pci ]; then
#    cat /proc/pci                                                                                                >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    fi
#    echo -------------------------------------- This is COM Port Setting  -------------------------------------- >> /pos71x/log/terminal/station$STATION\_hardware.txt
#    cat /proc/tty/driver/serial                                                                                  >> /pos71x/log/terminal/station$STATION\_hardware.txt

# Run Terminal Online
echo "nameserver 1.1.1.1 8.8.8.8" >/etc/resolv.conf
        
# Run Pos710 Front-end Program
echo $OUTLET > /etc/fab_outlet
while [ 0 ]
do

    export OUTLET=`cat /etc/fab_outlet`
    cp pos710 /tmp
    # If station is "BC" , auto enable Barcode function 
    if [ $STATION = "BC" ]; then
    /tmp/pos710 -kconfirm /cust/pos710/shop/ini/default.ini
    else 
    /tmp/pos710 /cust/pos710/shop/ini/default.ini
    status=$?
    fi
    
    if [ $status = 254 ]; then
    	reboot
    fi

    if [ $status = 253 ]; then
    	poweroff
    fi

    if [ $status != 255 ]; then
	break
    fi
done
exec /bin/sh
