#!/bin/bash
#Centos7 init install
#V1.1:Update CentOS 7 node version to v20.12.1 time:2024-07-25 15:27:00

chmod +x ./sh/*

ping -c 1 -W 1 www.baidu.com &> /dev/null
if [ $? -ne 0 ];then echo "请检查网络连接!" ; exit 1; fi

if [ `whoami` != "root" ];then
  echo "请登录root用户执行！"
  exit 1;
fi

logFile="/root/init.centos7/init.log"
if [ ! -f "$logFile" ]; then
  touch init.log
fi

date '+时间 : %Y-%m-%d %H:%M:%S' >> /root/init.centos7/init.log
echo "开始部署脚本" >> /root/init.centos7/init.log
echo "###########################################" >> /root/init.centos7/init.log

echo -n "部署环境选择:

==============================
=  1:WCS分拣服务器环境部署   =
=  2:FTP图片服务器环境部署   =
=  3:WCS与FTP同时部署        =
=  4:node升级-2024-07-25     =
=  5:退出                    =
==============================

请输入[1|2|3|4|5]："
read type

if [ $type == 1 ];then
  echo "<<============== START =================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /root/init.centos7/init.log
  echo "部署选择[1:WCS分拣服务器环境部署]" >> /root/init.centos7/init.log
  echo "###########################################" >> /root/init.centos7/init.log
  #工具下载
  source ./sh/tools_install.sh
  if [ $? -ne 0 ];then echo "install tools err!" ; exit 1; fi
  
  #安装mysql数据库
  source ./sh/mysql_install.sh
  if [ $? -ne 0 ];then echo "install mysql err!" ; exit 1; fi

  #安装JDK环境
  source ./sh/jdk_install.sh
  if [ $? -ne 0 ];then echo "install jdk err!" ; exit 1; fi

  #编译升级下载
  source ./sh/node_install.sh
  if [ $? -ne 0 ];then echo "install node err!" ; exit 1; fi
  
  #安装vue运行环境
  source ./sh/monitor_install.sh
  if [ $? -ne 0 ];then echo "install moiiom err!" ; exit 1; fi

elif [ $type == 2 ];then
  echo "<<================START==================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /root/init.centos7/init.log
  echo "部署选择[2:FTP图片服务器环境部署]" >> /root/init.centos7/init.log
  echo "###########################################" >> /root/init.centos7/init.log
  #工具下载
  source ./sh/tools_install.sh
  if [ $? -ne 0 ];then echo "install tools err!" ; exit 1; fi
  #安装FTP服务
  source ./sh/vsftpd_install.sh
  if [ $? -ne 0 ];then echo "install vsftpd err!" ; exit 1; fi
  
elif [ $type == 3 ];then
  echo "<<=============== START =================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /root/init.centos7/init.log
  echo "部署选择[3:WCS与FTP同时部署]" >> /root/init.centos7/init.log
  echo "###########################################" >> /root/init.centos7/init.log
  #工具下载
  source ./sh/tools_install.sh
  if [ $? -ne 0 ];then echo "install tools err!" ; exit 1; fi
  
  #安装mysql数据库
  source ./sh/mysql_install.sh
  if [ $? -ne 0 ];then echo "install mysql err!" ; exit 1; fi

  #安装JDK环境
  source ./sh/jdk_install.sh
  if [ $? -ne 0 ];then echo "install jdk err!" ; exit 1; fi
  
  #编译升级下载
  source ./sh/node_install.sh
  if [ $? -ne 0 ];then echo "install node err!" ; exit 1; fi
  
  #安装vue运行环境
  source ./sh/monitor_install.sh
  if [ $? -ne 0 ];then echo "install moiiom err!" ; exit 1; fi

  #安装FTP服务
  source ./sh/vsftpd_install.sh
  if [ $? -ne 0 ];then echo "install vsftpd err!" ; exit 1; fi

elif [ $type == 4 ];then
  echo "<<================START==================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /root/init.centos7/init.log
  echo "部署选择[4:node升级]" >> /root/init.centos7/init.log
  echo "###########################################" >> /root/init.centos7/init.log

  #编译升级下载
  source ./sh/node_install.sh
  if [ $? -ne 0 ];then echo "install node err!" ; exit 1; fi

elif [ $type == 5 ];then 
  echo "Goodbye!"
  exit 1;
else 
  echo "输入错误！"
  exit 1;
fi

touch /home/simba/reboot.log
echo "#su - simba /home/simba/simba-server/server/autostartup.sh" >> /etc/rc.local
echo "date '+开机时间 : %Y-%m-%d %H:%M:%S' >> /home/simba/reboot.log" >> /etc/rc.local
chmod 777 /etc/rc.d/rc.local
echo "exit 0" >> /etc/rc.local
echo "<<==================================>>"
echo "<<==                              ==>>"
echo "<<==        INSTALL OK!!!         ==>>"
echo "<<==                              ==>>"
echo "<<==================================>>"
echo "<<========= Please reboot ==========>>"
echo "<<============== END ===============>>"

echo "<<==================================>>" >> /root/init.centos7/init.log
echo "<<==                              ==>>" >> /root/init.centos7/init.log
echo "<<==        INSTALL OK!!!         ==>>" >> /root/init.centos7/init.log
echo "<<==                              ==>>" >> /root/init.centos7/init.log
echo "<<==================================>>" >> /root/init.centos7/init.log
echo "<<========= Please reboot ==========>>" >> /root/init.centos7/init.log
echo "<<============== END ===============>>" >> /root/init.centos7/init.log
