二代云盒混合网

#!/bin/sh
#二代云盒-混合网
device_version=`cat /xdfapp/data/version/device`
ocb_device=`cat /proc/cpuinfo |grep "J3160" |wc -l`
nginx_dir="/xdfapp/backups/server"
tar_nginx_mixed="nginx_maxid_201809141429.tar.gz"
download_url="http://img.fe.okjiaoyu.cn"
info_log="/tmp/update_info.log"
date=`date +%Y%m%d-%H:%M:%S`
mkdir -p /xdfapp/logs/proxy/
function nginx_update {
	if [ `md5sum /xdfapp/scripts/auto_cut_nginx_log.sh  |awk '{print $1}'` != "f34a115ca318eaa54b2ed3b0d8f78724" ];then
		wget -q http://img.fe.okjiaoyu.cn/auto_cut_nginx_log.sh  -O /xdfapp/scripts/auto_cut_nginx_log.sh  && echo "auto_cut_nginx_log ok"
	fi
	wget -q -O /xdfapp/scripts/startup_nginx.sh http://img.fe.okjiaoyu.cn/startup_nginx.sh
	if [ `cat /xdfapp/scripts/startup_nginx.sh |wc -l` != "16" ];then
		echo "nginx_update download startup_nginx.sh error"
		wget -q -O /xdfapp/scripts/startup_nginx.sh http://img.fe.okjiaoyu.cn/startup_nginx.sh
	fi
   [ ! -d $nginx_dir ]&&mkdir -p /xdfapp/backups/server/
	if [  -d $nginx_dir ];then
		cd /xdfapp/backups/server/;wget -q ${download_url}/$tar_nginx_mixed
		if [ $? -eq 0 ];then
			tar xzf $tar_nginx_mixed && rm -rf $tar_nginx_mixed && echo "tar_nginx_mixed ok"
			echo "nginx_update `cat /xdfapp/server/nginx/version` ok"
			nginx_update="ok"
		else
			echo "nginx_update error"
			exit 0
		fi

	fi
	if [ -f /xdfapp/server/ats ];then
		/xdfapp/server/ats/bin/trafficserver stop >>/dev/null
	fi


}
function rc_update {
	rc="/xdfapp/backup/rc.local"
	if [ -f $rc ];then
		cat $rc > /etc/rc.local
		echo "rc.loacl init ok"
	else
		cat > /etc/rc.local << EOF
#!/bin/sh -e
/bin/sh /xdfapp/scripts/clean_log.sh >>/dev/null 2>&1 &
sleep 5
/bin/sh  /xdfapp/scripts/change_route.sh >/dev/null 2>&1 &
/xdfapp/monitor/agent/control restart >>/dev/null 2>&1 &
/bin/bash /xdfapp/apps/gru-absolute/bin/monitor.sh >>/dev/null 2>&1 &
/bin/sh /xdfapp/scripts/startup_nginx.sh >>/dev/null 2>&1 &
/usr/local/bin/supervisord  -c /etc/supervisord.conf >>/dev/null 2>&1 &
/xdfapp/monitor/cswitch/control restart >>/dev/null 2>&1 &
echo "" >/var/log/dnsmasq.log >>/dev/null 2>&1 &
/etc/init.d/dnsmasq restart >>/dev/null 2>&1 &
exit 0
EOF
	echo "rc_update ok"
fi
}
function cron_update {
	mkdir -p /xdfapp/backup/
	cp /var/spool/cron/crontabs/root /xdfapp/backup/crontabs_root
	echo "1 * * * * /usr/sbin/ntpdate -u pool.ntp.org  >/dev/null 2>&1" >/var/spool/cron/crontabs/root
	echo "0 0 * * * /bin/sh /xdfapp/scripts/auto_cut_nginx_log.sh >> /dev/null  2>&1" >>/var/spool/cron/crontabs/root
	echo "0 0 * * * /bin/sh /xdfapp/scripts/clean_log.sh >> /dev/null  2>&1" >>/var/spool/cron/crontabs/root
	if [ `cat /var/spool/cron/crontabs/root |wc -l` = "3" ];then
		echo "cron_update ok"
	else
		echo "cron_update error"
	fi
	if [ ! -f /xdfapp/scripts/clean_log.sh ];then
		echo "#!/bin/bash" >/xdfapp/scripts/clean_log.sh
		echo "#清除长连接1天前的日志" >>/xdfapp/scripts/clean_log.sh
		echo "find /xdfapp/logs/gru-absolute -type f -mtime +0|xargs rm -rf" >>/xdfapp/scripts/clean_log.sh
		echo "cron_update clean_log add ok"
	else
		if [ `md5sum /xdfapp/scripts/clean_log.sh  |awk '{print $1}'` != "ff4b355f6ea3a90815bef2460f424983" ];then
			echo "#!/bin/bash" >/xdfapp/scripts/clean_log.sh
			echo "#清除长连接1天前的日志" >>/xdfapp/scripts/clean_log.sh
			echo "find /xdfapp/logs/gru-absolute -type f -mtime +0|xargs rm -rf" >>/xdfapp/scripts/clean_log.sh
			echo "cron_update clean_log add ok"
		else
			echo "cron_update clean_log ok"
		fi
	fi

}
function dns_update {
cat > /etc/dnsrecord.txt << EOF
172.16.1.253  ap.okjiaoyu.cn
172.16.1.253  cj.okjiaoyu.cn
172.16.1.253  hd.okjiaoyu.cn
172.16.1.253  hm.okjiaoyu.cn
172.16.1.253  mi.okjiaoyu.cn
172.16.1.253  ok.okjiaoyu.cn
172.16.1.253  pp.okjiaoyu.cn
172.16.1.253  pv.okjiaoyu.cn
172.16.1.253  qa.okjiaoyu.cn
172.16.1.253  qd.okjiaoyu.cn
172.16.1.253  qp.okjiaoyu.cn
172.16.1.253  qv.okjiaoyu.cn
172.16.1.253  ra.okjiaoyu.cn
172.16.1.253  rc.okjiaoyu.cn
172.16.1.253  rs.okjiaoyu.cn
172.16.1.253  rv.okjiaoyu.cn
172.16.1.253  rw.okjiaoyu.cn
172.16.1.253  tc.okjiaoyu.cn
172.16.1.253  td.okjiaoyu.cn
172.16.1.253  vc.okjiaoyu.cn
172.16.1.253  pd.okjiaoyu.cn
172.16.1.253  common.okjiaoyu.cn
172.16.1.253  qdimg.okjiaoyu.cn
172.16.1.253  img.okjiaoyu.cn
172.16.1.253  img.fe.okjiaoyu.cn
172.16.1.253  static.fe.okjiaoyu.cn
172.16.1.253  static.okjiaoyu.cn
172.16.1.253  stmonitor.okjiaoyu.cn
172.16.1.253  temp.okjiaoyu.cn
172.16.1.253  fotadown.mayitek.com
172.16.1.253  ocb.okjiaoyu.cn
172.16.1.253  fa.okjiaoyu.cn
172.16.1.253  tn.okjiaoyu.cn
172.16.1.253  static-site.fe.okjiaoyu.cn
172.16.1.253  cr-ticket.okjiaoyu.cn
172.16.1.253  cdn.redstone.net.cn
172.16.1.253  iotdown.mayitek.com
172.16.1.253  cr-spear.okjiaoyu.cn
EOF
a=`cat /etc/dnsmasq.conf |grep listen-address`
b=`cat /etc/dnsmasq.conf |grep "dhcp"`
echo "$a" >/etc/dnsmasq.conf
if [ ! -z "$b" ];then
	echo "$b" >>/etc/dnsmasq.conf
fi
cat >> /etc/dnsmasq.conf << EOF
no-resolv
no-hosts
addn-hosts=/etc/dnsrecord.txt
cache-size=5000
log-facility=/var/log/dnsmasq.log
log-queries

server=/cfg.imtt.qq.com/114.114.114.114
server=/log.tbs.qq.com/114.114.114.114
server=/soft.tbs.imtt.qq.com/114.114.114.114
server=/wup.browser.qq.com/114.114.114.114
server=/monitor.uu.qq.com/114.114.114.114
server=/oth.str.mdt.qq.com/114.114.114.114
server=/oth.eve.mdt.qq.com/114.114.114.114
server=/web.p.qq.com/114.114.114.114
server=/hivoice.cn/114.114.114.114
server=/easemob.com/114.114.114.114
server=/jpush.io/114.114.114.114
server=/jpush.cn/114.114.114.114
server=/umeng.com/114.114.114.114
server=/umengcloud.com/114.114.114.114
server=/okjiaoyu.cn/114.114.114.114
server=/okay.cn/114.114.114.114
server=/xk12.cn/114.114.114.114
server=/okayzhihui.cn/114.114.114.114
server=/qiniu.com/114.114.114.114
server=/redstone.net.cn/114.114.114.114
server=/mayitek.com/114.114.114.114
server=/www.cctv.com/114.114.114.114
server=/ntp1.aliyun.com/114.114.114.114
server=/ntp.aliyun.com/114.114.114.114
server=/ntp2.aliyun.com/114.114.114.114
server=/ntp3.aliyun.com/114.114.114.114
server=/cn.ntp.org.cn/114.114.114.114
server=/mimc.chat.xiaomi.net/114.114.114.114
server=/app.chat.xiaomi.net/114.114.114.114
server=/resolver.msg.xiaomi.net/114.114.114.114
server=/up.qbox.me/114.114.114.114
server=/uc.qbox.me/114.114.114.114
EOF
/etc/init.d/dnsmasq restart >>/dev/null
if [ $? -eq 0 ];then
        echo "restart dns ok"
else
        pgrep dnsmasq >>/dev/null && kill -9 `pgrep dnsmasq` && echo "$date kill dns ok"
        /etc/init.d/dnsmasq restart >>/dev/null && echo "restart dns ok"
fi
}
function route_update {
	wget -q -O /xdfapp/scripts/change_route.sh  http://img.fe.okjiaoyu.cn/okaystation/route/change_route.sh  && echo "change_route.sh ok"
	wget -q http://img.fe.okjiaoyu.cn/okaystation/route/route.conf -O /etc/route/route.conf	&& echo "route.conf ok"
	if [ -f /xdfapp/scripts/change_route.sh ];then
		if [ `md5sum /xdfapp/scripts/change_route.sh|awk '{print $1}'` = "c79d1d5eec1c1278dd8af83964cf82d1" ];then
			echo "route_update ok"
			nginx_update
			if [ "$nginx_update" = "ok" ];then
				a=`ps -ef |grep change_route.sh|grep -v "grep"|awk '{print $2}'`
				if [ ! -z "$a" ];then
					kill -9 $a && echo "kill change_route ok"
					nohup /bin/sh  /xdfapp/scripts/change_route.sh >/dev/null 2>&1 &
					ps -ef |grep change_route.sh|grep -v "grep"
				else
					nohup /bin/sh  /xdfapp/scripts/change_route.sh >/dev/null 2>&1 &
					ps -ef |grep change_route.sh|grep -v "grep"
				fi
			else
				echo "route_update nginx_update error"
			fi

		else
			echo "route_update error"
		fi
	else
		echo "route_update error"
	fi
}

if [ "$ocb_device" = "4" ];then
	route_update
	rc_update
	dns_update
	cron_update
	echo "device_version is $device_version"
	rm -rf  /home/okay/桌面/* && echo "清空桌面"
else
	echo "云盒版本不对,当前版本为`cat /proc/cpuinfo |grep "model name"  |awk '{print $7}'|head -n1`"
fi

  

posted @ 2018-10-11 17:58  lixinliang  阅读(620)  评论(0编辑  收藏  举报