# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n 2> /dev/null || true

export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_PLUGINDIR=/lib/ts
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal

export LD_LIBRARY_PATH=/lib/qt5lib:/lib/qt5plugins:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib/libV17:$LD_LIBRARY_PATH

export QT_QPA_PLATFORM_PLUGIN_PATH=/lib/qt5plugins/platforms
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
export QT_QPA_FONTDIR=/usr/share/fonts

export QT_QPA_FB_DRM=1
#export QT_QPA_FB_DISABLE_INPUT=1
export QT_QPA_FB_TSLIB=1
export QT_PLUGIN_PATH=/lib/qt5plugins

s3='TSLIB_TSDEVICE=/dev/input/event'
s4='QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event'
sTslib='QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event'

s1=$(cat /proc/bus/input/devices | grep -A4 'TouchController"')

if [ -z ${s1}]
then
	s1=$(cat /proc/bus/input/devices | grep -A4 'PenMount')
fi

if [ -z ${s1}]
then
	s1=$(cat /proc/bus/input/devices | grep -A4 'HID')
fi

if [ -z ${s1}]
then
	index=1
	while [ $index -lt 3 ]
	do
		s1=$(cat /proc/bus/input/devices | grep -m$index -A4 'ILITEK-TP')
		chk=${s1##*event}
		if [[ $chk =~ "js" ]]
		then
			let index++
			continue
		else
			break
		fi
		let index++
	done
fi

s5=${s1##*event}
s5=${s5%%?js*}

s2=`expr ${s5}`

export ${s3}${s2}
export ${s4}${s2}
export ${sTslib}${s2}:rotate=270

cd /root/bin-AOI
chmod -R 777 *

#>>>>>>>>>>>>>>>>>>>>update>>>>>>>>>>>>>>>>>>>>
file_gz="newupdate.tar.gz"
file_rar="newupdate.rar"
file_xz="newupdate.tar.xz"
file_zip="newupdate.zip"
tardir="./newupdate"
cammerdir="cammer*"
fileupdate="./update.sh"

isfindupdate=0
if [ -f $file_gz -o -f $file_rar -o -f $file_xz -o -f $file_zip ];
then
    rm -rf $tardir 
    mkdir $tardir
	isfindupdate=$[$isfindupdate+1]
	
	if [ -f $file_xz ];	#tar.xz
	then
		tar -Jxvf $file_xz -C $tardir
		rm -f $file_xz
	elif [ -f $file_rar ];	#rar
	then
		mv $file_rar $tardir
		cd $tardir
		rar x $file_rar
		rm -f $file_rar
	elif [ -f $file_gz ];	#tar.gz
	then
		tar -zxvf $file_gz -C $tardir
		rm -f $file_gz
	elif [ -f $file_zip ];   #zip
	then
		unzip -o $file_zip -d $tardir
		rm -f $file_zip
	fi
fi

cd /root/bin-AOI
if [ $isfindupdate == 1 ];
then
	chmod -R 777 *
    if ls $tardir/$cammerdir > $tardir/cam 2>&1;then
    rm -rf $cammerdir
    rm -rf $tardir/cam
    fi
    cp -rf $tardir/* ./
    if [ -f $fileupdate ];
    then
        $fileupdate
        cd /root/bin-AOI
        rm -f $fileupdate
    fi
    rm -rf $tardir
fi
#<<<<<<<<<<<<<<<<<<<<update<<<<<<<<<<<<<<<<<<<<

cd /root/bin-AOI
rmmod pinctrl_sunrisepoint
mknod /dev/led c 233 0
insmod led.ko

#>>>>>>>>>>>>>>>>>>>>special_action>>>>>>>>>>>>>>>>>>>>
#执行特殊脚本
cd /root/bin-AOI
framerun="framerun.sh"
if [ -f $framerun ];
then 
    ./$framerun
fi
rm -f $framerun

#更新时间
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#hwclock --hctosys 
#<<<<<<<<<<<<<<<<<<<<special_script<<<<<<<<<<<<<<<<<<<<

cd /root/bin-AOI
mkdir -p /root/bin-AOI/cnt_net/workspace
python3 ./cnt_net/bsymv20_upnetcard.py > /dev/null 2>&1

sleep 16s

#备份标准输出日志
name2=$(date +%Y-%m-%d_%H:%M:%S)
stdoutlog="/root/bin-AOI/cnt_net/workspace/log_stdout"
mkdir -p $stdoutlog
if [ -f $stdoutlog/log.txt ];
then
    mv -f $stdoutlog/log.txt $stdoutlog/log$name2.txt
fi

#内核日志输出级别
echo 1 > /proc/sys/kernel/printk

./application > $stdoutlog/log.txt 2>&1




