#!/bin/bash
#Rhel init install
#2024-05-15
#version 1.0
#author:pretend


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="./init.log"
if [ ! -f "$logFile" ]; then
  touch init.log
fi

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

echo -n "部署环境选择:

==============================
=  1:WCS分拣服务器环境部署   =
=  2:FTP图片服务器环境部署   =
=  3:WCS与FTP同时部署        =
=  4:退出                    =
==============================

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

if [ $type == 1 ];then
  echo "<<======== START ===================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> ./init.log
  echo "部署选择[1:WCS分拣服务器环境部署]" >> ./init.log
  echo "##########" >> ./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
  
  #安装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' >> ./init.log
  echo "部署选择[2:FTP图片服务器环境部署]" >> ./init.log
  echo "##########" >> ./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' >> ./init.log
  echo "部署选择[3:WCS与FTP同时部署]" >> ./init.log
  echo "##########" >> ./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
  
  #安装FTP服务
  source ./sh/vsftpd_install.sh
  if [ $? -ne 0 ];then echo "install vsftpd err!" ; exit 1; fi
  
  #安装vue运行环境
  source ./sh/monitor_install.sh
  if [ $? -ne 0 ];then echo "install moiiom err!" ; exit 1; fi
  
elif [ $type == 4 ];then 
  echo "Goodbye!"
  exit 1;
else 
  echo "输入错误！"
  exit 1;
fi

touch /home/simba/reboot.log

echo "date '+开机时间 : %Y-%m-%d %H:%M:%S' >> /home/simba/reboot.log" >> /etc/rc.local

echo "#su - simba /home/simba/simba-server/server/autostartup.sh" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
chmod 777 /etc/rc.d/rc.local
echo "<<==================================>>"
echo "<<==                              ==>>"
echo "<<==        INSTALL OK!!!         ==>>"
echo "<<==                              ==>>"
echo "<<==================================>>"
echo "<<========= Please reboot ==========>>"
echo "<<============== END ===============>>"

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