#!/bin/bash

#lock detection
echo "<<======= install tools部署[开始] =======>>"
date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
echo "<<======= install tools部署[开始] =======>>" >> /home/start.log
echo "###########################################" >> /home/start.log

LOCK_NAME="/tmp/winit.lock"
if (set -o noclobber ; echo "" > ${LOCK_NAME} ) 2> /dev/null;then
	echo "init start";
	echo "init start-1" >> /home/start.log
else
	echo "init err"
	echo "init err" >> /home/stop.log
	exit 1;
fi

#start install
apt-get update
apt-get upgrade -y
apt-get install ssh -y
apt-get install vim -y
apt-get install p7zip-full -y
apt-get install lrzsz -y
apt-get install sshpass -y
apt-get install tree -y
apt-get install htop -y
apt-get install curl -y
apt-get install ntpdate -y
apt-get install redis-server -y
apt-get install binutils -y

strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_2.28
if [ $? -eq 0 ] ; then
  echo -e "glibc2.28升级                    \033[32m 完成 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "glbc2.28升级-------------------------[完成]" >> /home/start.log
  echo "###########################################" >> /home/start.log
else
  echo -e "glibc2.28升级                    \033[31m 失败 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "glibc2.28升级------------------------[失败]" >> /home/start.log
  echo "###########################################" >> /home/start.log
  exit 1;
fi

# 下载node-v20.12.1安装包
wget -O /opt/node-v20.12.1-linux-x64.tar.xz http://simba.whhsn.cn:7374/init/doc/init/node-20/node-v20.12.1-linux-x64.tar.xz
tar -xf /opt/node-v20.12.1-linux-x64.tar.xz -C /opt/
echo '#==node==' >> /etc/profile
echo 'export NODE_HOME=/opt/node-v20.12.1-linux-x64' >> /etc/profile
echo 'export PATH=$PATH:${NODE_HOME}/bin' >> /etc/profile
source /etc/profile
node -v
if [ $? -eq 0 ] ; then
  echo -e "nodeV20升级                      \033[32m 完成 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "nodeV20升级--------------------------[完成]" >> /home/start.log
  echo "###########################################" >> /home/start.log
else
  echo -e "nodeV20升级                      \033[31m 失败 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "nodeV20升级--------------------------[失败]" >> /home/start.log
  echo "###########################################" >> /home/start.log
  exit 1;
fi

npm i -g serve@13.0.2 --registry=https://registry.npmmirror.com
if [ $? -eq 0 ];then
  echo -e "指定serve版本安装成功                    \033[32m 完成 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
  echo "指定serve版本安装成功----------------[完成]" >> /home/start.log
  echo "###########################################" >> /home/start.log
else
  echo -e "指定serve版本安装失败                    \033[31m 失败 \033[0m"
  date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/stop.log
  echo "指定serve版本安装失败-----------------[失败]" >> /home/stop.log
  echo "###########################################" >> /home/start.log
  exit 1
fi

echo "instaall tools ok" 
echo "###########################################" >> /home/start.log
echo "############ instaall tools ok ############" >> /home/start.log
echo "###########################################" >> /home/start.log
