#!/bin/bash
#set -x
apt-get -y update
apt-get -y install python3-serial xdotool
curl -ks https://kwickpos.com/download/kpCAS.tar > /tmp/kpCAS.tar
if [ -f /tmp/kpCAS.tar ]; then
        tar -xvC / -f /tmp/kpCAS.tar
fi

clear
echo "*======== KwickPOS SCALE SETUP ==================*"
echo "*    1. is this TORREY scale?                    *"
echo "*                      Ctrl-C=exit               *"
echo -n "Yes or No: "
	read mod

echo ""
echo "*    2. is this connection db9-DB9 or db9-USB?   *"
echo "*                      Ctrl-C=exit               *"
echo -n "DB9 or USB: "
	read con

echo ""
echo $mod |grep -qi ^y
if [ $? -eq 0 ]; then
	echo -n "Setting TORREY scale"
else
	echo -n "Setting CAS/BreckNell scale"
	sed -i 's/^torrey = True/#torrey = True/' /usr/bin/kwickos.read.cas.py
fi

echo $con |grep -qi ^d
if [ $? -eq 0 ]; then
	echo " with db9-DB9 connector."
	sed -i '/^activePort=.*USB0/d' /usr/bin/kwickos.read.cas.py
else
	echo " with db9-USB connector."
fi

systemctl restart KwickCAS

echo "Done success"
