#!/bin/bash
#Ubuntu init install
#V1.1:change ubuntu version to 20.04 2023-01-09 15:22:00
#V1.2:change ubuntu version to 20.04 2023-12-12 11:22:00
#V1.3:Ubuntu 20 Upgrade Node to 20.12.1 Time: July 26, 2024 14:30

# 检查是否存在名为"simba"的用户
if ! grep -q -w "simba" /etc/passwd; then
    # 用户不存在，创建用户
    useradd simba
    echo "用户simba已创建"
    echo "用户simba已创建" >> /home/start.log
fi

# 检查"/home/simba/"目录是否存在
if [ ! -d "/home/simba/" ]; then
    # 目录不存在，创建目录
    mkdir /home/simba
    echo "/home/simba/目录已创建"
    echo "/home/simba/目录已创建" >> /home/start.log

    chown simba:simba /home/simba/
fi

#IUSER="simba"
IUSER="simba"
chmod +x ./sh/*

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

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

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

echo -n "部署环境选择:

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

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


if [ $type -eq 1 ];then
  echo "<<======== START ===================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "部署选择[1:WCS分拣服务器环境部署]" >> /home/start.log
  echo "##########" >> /home/start.log

#check ubuntu
  ./sh/check_ubuntu.sh
  if [ $? -ne 0 ];then echo "check ubuntu err!" ; exit 1; fi

  ./sh/install_tools.sh
  if [ $? -ne 0 ];then echo "tools install err!" ; exit 1; fi

  ./sh/install_jdk.sh ${IUSER}
  if [ $? -ne 0 ];then echo "JDK install err!" ; exit 1; fi

  ./sh/add_shell.sh ${IUSER}
  if [ $? -ne 0 ];then echo "add shell err!" ; exit 1; fi

  ./sh/install_mysql.sh
  if [ $? -ne 0 ];then echo "mysql install err!" ; exit 1; fi

#SimbaAutomation
#source ./sh/read_config.sh

elif [ $type -eq 2 ];then
  echo "<<========START===================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "部署选择[2:FTP图片服务器环境部署]" >> /home/start.log
  echo "##########" >> /home/start.log

  ./sh/vsftpd_install.sh ${IUSER}
  if [ $? -ne 0 ];then echo "install vsftp err!" ; exit 1; fi

elif [ $type -eq 3 ];then
  echo "<<======== START ===================>>"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "部署选择[3:WCS与FTP同时部署]" >> /home/start.log
  echo "##########" >> /home/start.log

  ./sh/check_ubuntu.sh
  if [ $? -ne 0 ];then echo "check ubuntu err!" ; exit 1; fi

  ./sh/install_tools.sh
  if [ $? -ne 0 ];then echo "tools install err!" ; exit 1; fi

  ./sh/install_jdk.sh ${IUSER}
  if [ $? -ne 0 ];then echo "JDK install err!" ; exit 1; fi

  ./sh/add_shell.sh ${IUSER}
  if [ $? -ne 0 ];then echo "add shell err!" ; exit 1; fi

  ./sh/install_mysql.sh
  if [ $? -ne 0 ];then echo "mysql install err!" ; exit 1; fi

  ./sh/vsftpd_install.sh ${IUSER}
  if [ $? -ne 0 ];then echo "install vsftp 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 "<<==================================>>"
echo "<<==                              ==>>"
echo "<<==        INSTALL OK!!!         ==>>"
echo "<<==                              ==>>"
echo "<<==================================>>"
echo "<<========= Please reboot ==========>>"
echo "<<============== END ===============>>"

echo "<<==================================>>" >> /home/start.log 
echo "<<==                              ==>>" >> /home/start.log 
echo "<<==        INSTALL OK!!!         ==>>" >> /home/start.log 
echo "<<==                              ==>>" >> /home/start.log 
echo "<<==================================>>" >> /home/start.log 
echo "<<========= Please reboot ==========>>" >> /home/start.log 
echo "<<============== END ===============>>" >> /home/start.log 
echo "[部署已完成]" >> /home/start.log
date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log

