本文共 5686 字,大约阅读时间需要 18 分钟。
#!/bin/bash #brief:to solve match correct event node when EAVCapture starts. #date:September 17,2015. #author:zhangshaoyan,shell.albert@gmail.com #This script is used to execute autoupdate task for EAVCapture Project. #Ftp server should be setup correctly before running. #BabyFTPServer is recommended,only anonymous user is supported. # #Compress all project related files with tar.bz2 and generate md5 file with md5sum command. #Put these two files in ftp root directory as follows: # # EAVCapture_Remote.tar.bz2 # EAVCapture_Remote.md5 # #The content of md5 file is as follows: #d404401c8c6495b206fc35c95e55a6d5 EAVCapture_Remote.tar.bz2 #(You can generate it easily with command 'md5sum EAVCapture_Remote.tar.bz2 >> EAVCapture_Remote.md5'). # # #author:zhangshaoyan #date:January 14,2016. ####user defined parameters######################## #NIC=wlp8s0 #NIC=enp7s0 NIC=wlan0 ################################################### AppName=EAVCapture FTPUSER=root FTPPASS=root FTPPort=2222 EAVUpate=/dev/tcp/127.0.0.1/7777 #################################################### EAVHOME=/home/bioequ/EAVCapture export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$EAVHOME/lib export PATH=$PATH:$EAVHOME/bin #################################################### function sendMsg { echo "msg:" $1 > $EAVUpate usleep 200000 } function sendErr { echo "err:" $1 > $EAVUpate usleep 200000 } function startEAVCaptureAndExit { if [ ! -f EAVCapture.bin ];then sendErr "找不到主程序文件EAVCapture.bin!" exit -1 fi echo "shu:Shutdown" > $EAVUpate usleep 500000 #qt's start command line parameters. mouseplug= kbdplug= allplug="-platform linuxfb" #scan /dev/input directory to get valid event that supports EV_REL. ./evtest.bin 0 > mouse_event.log mouse_event_cnt=$? #scan /dev/input diretory to get valid event that supports EV_KEY. ./evtest.bin 1 > kbd_event.log kbd_event_cnt=$? #generate the final one-line start parameter. if [ $mouse_event_cnt -gt 0 ];then while read line do mouseplug="$mouseplug -plugin evdevmouse:$line" done < mouse_event.log fi if [ $kbd_event_cnt -gt 0 ];then while read line do kbdplug="$kbdplug -plugin evdevkeyboard:$line" done < kbd_event.log fi allplug="$allplug $mouseplug $kbdplug" echo $allplug #start main app. ./EAVCapture.bin $allplug & exit 0 } #start EAVUpdate app. mkdir -p /home/bioequ/tmpfs mount -t tmpfs tmpfs /home/bioequ/tmpfs pwd if [ ! -f EAVUpate.bin ];then echo "can't find EAVUpate.bin!" exit -1 fi ./EAVUpdate.bin -platform linuxfb & sleep 1 #disable printk output. sendMsg "禁止内核调试信息" echo "1 4 1 7" > /proc/sys/kernel/printk #change root password. #echo -e "bjbioequ\nbjbioequ\n" | passwd root #install driver module. cd driver sendMsg "正在加载按键驱动..." insmod imx6_key_drv.ko usleep 500000 sendMsg "正在加载无线网卡驱动..." insmod rtl8188.ko sleep 1 cd .. sleep 2 #start dropbear ssh service. if [ ! -f "/etc/dropbear/dropbear_rsa_host_key" ];then sendMsg "正在生成SSH密钥..." dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key fi sendMsg "正在启动SSH服务..." dropbear -r /etc/dropbear/dropbear_rsa_host_key & #start wifi-daemon. sendMsg "正在启动WiFi管理器..." wpa_supplicant -i ${NIC} -c /etc/wpa_supplicant/wpa_supplicant.conf -B sleep 1 sendMsg "正在获取IP地址..." udhcpc -i ${NIC} -t 3 -n if [ $? -ne 0 ];then sendMsg "获取IP地址失败" fi ######################################################## #execute update task. LocalAppFile=${AppName}_Local.tar.bz2 LocalMD5File=${AppName}_Local.md5 #remote file. RemoteAppFile=${AppName}_Remote.tar.bz2 RemoteMD5File=${AppName}_Remote.md5 #check local md5 file. if [ ! -f $LocalMD5File ];then sendErr "找不到本地MD5文件!" startEAVCaptureAndExit fi #get local network interface broadcast address. sendMsg "正在计算广播地址" Broadcast=$(/sbin/ifconfig ${NIC} | awk -F : '/Bcast/{print $3}' | awk '{print $1}') if [ "$Broadcast" = "" ];then sendErr "找不到广播地址!" startEAVCaptureAndExit fi sendMsg "广播地址:${Broadcast}" #try to detect server. sendMsg "正在搜索升级服务器..." ServerIP=$(./zserverfind.bin -i ${Broadcast} -p 6688 -t 10) if [ $? -ne 0 ];then sendErr "找不到升级服务器!" startEAVCaptureAndExit fi sendMsg "搜索到服务器:$ServerIP" #download md5 file from server. sendMsg "正在下载MD5文件..." ftp -n <<EOF open $ServerIP $FTPPort user $FTPUSER $FTPPASS binary get $RemoteMD5File close bye EOF #check download success or not. if [ ! -f $RemoteMD5File ];then sendErr "下载 $RemoteMD5File 失败!" startEAVCaptureAndExit fi #extract two md5 values. LocalMD5Value=$(cat $LocalMD5File | awk '{print $1}') RemoteMD5Value=$(cat $RemoteMD5File | awk '{print $1}') echo "LocalMD5:" $LocalMD5Value echo "RemoteMD5:" $RemoteMD5Value #compare two md5 values. if [ ${LocalMD5Value} = ${RemoteMD5Value} ];then sendErr "当前已是最新版本!" startEAVCaptureAndExit fi #download new version from ftp server. sendMsg "正在下载新版本文件" ftp -n <<EOF open $ServerIP $FTPPort user $FTPUSER $FTPPASS binary get $RemoteAppFile close bye EOF #check download success or not. if [ ! -f $RemoteAppFile ];then sendErr "下载 $RemoteAppFile 失败!" startEAVCaptureAndExit fi #re-generate remote app file md5 value. NewRemoteMD5Value=$(md5sum $RemoteAppFile | awk '{print $1}') if [ $NewRemoteMD5Value != ${RemoteMD5Value} ];then echo "Get md5 value is ${RemoteMD5Value}" echo "Generate md5 value is ${NewRemoteMD5Value}" sendErr "验证MD5失败:$RemoteAppFile!" startEAVCaptureAndExit fi #backup current version. sendMsg "正在备份当前版本文件" if [ ! -d ../Backup ];then mkdir ../Backup fi tar cvfj ../Backup/EAVCaptureBackup.tar.bz2 * #remove old files,keep new version. sendMsg "正在删除旧版本文件..." rm `ls | egrep -v 'EAVCapture_Remote.tar.bz2|EAVCapture_Remote.md5'` #fix its name. mv $RemoteAppFile $LocalAppFile mv $RemoteMD5File $LocalMD5File tar jxvf $LocalAppFile sendMsg "升级成功!" startEAVCaptureAndExit #######################################################################转载地址:http://eczji.baihongyu.com/