#!/bin/bash
#Network test
echo "<<=========== 数据源更新[开始] ==========>>"
date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
echo "<<=========== 数据源更新[开始] ==========>>" >> /home/start.log
echo "##########" >> /home/start.log

echo "Network test"
IUSER=$1

ping -c 1 -W 1 baidu.com &>/dev/null
if [ $? -ne 0 ];then echo "Network err!" ; exit 1; fi
#User testing
if [ `whoami` != "root" ];then  
	echo "Is not the root user !"
	echo "Please switch the root user !"
	exit 1;
fi

#Version testing
echo "SYS_version test"
sysVer="`cat /etc/issue.net`"
nowVer="Ubuntu 22.04.2"
if [[  ${sysVer} =~ ${nowVer} ]];then
        echo "SYS_version ok"
else
        echo "SYS_version err"
	exit 1;
fi

if [ ! -f ./sh/rar/jdk.7z ] ;then
	echo "download jdk" 
	wget -P ./sh/rar/ http://simba.whhsn.cn:7374/init/doc/jdk.7z
fi

if [ ! -f ./sh/rar/mysql-5.7.zip ] ;then
	echo "download mysql" 
	wget -P ./sh/rar/ http://simba.whhsn.cn:7374/init/doc/mysql-5.7.zip
fi

#File detection
if [ ! -f ./sh/rar/jdk.7z -o ! -f ./sh/doc/javahome -o ! -f ./sh/doc/whhsn.x -o ! -f ./sh/doc/whhsn.y ] ;then
		
		if [ ! -f ./sh/rar/jdk.7z ];then
			FA=" sh/rar/jdk \n"
		fi
		if [ ! -f ./sh/doc/javahome ];then
			FB=" sh/doc/javahome \n"
		fi		
		if [ ! -f ./sh/doc/whhsn.x ] ;then
			FC=" sh/doc/whhsn.x \n"
		fi
		if [ ! -f ./sh/doc/whhsn.y ] ;then
			FD=" sh/doc/whhsn.y \n"
		fi
		echo -e "file not found :\n${FA}${FB}${FC}${FD}"
		echo 'check_ubuntu install ok' >>/home/start.log
		exit 1;
fi
