#!/bin/bash
# EMS Installer
# QiGang
# 2018/01/24
# PakageName(Exp:EMS.zip)
PakageName="EMS.zip"
# InstallPath(Exp:/opt/goldwind/)
InstallPath="/opt/goldwind"
# Install RPMs
#查看内核 是否包含ky3.kb3.x86_64,包含就安装以下包
#-i 安装软件包
#-v 可视化提供更多的详细信息的输出
#-h 显示安装进度
if [[ `uname -r | grep -c 'ky3.kb3.x86_64'` != '0' ]];then
rpm -ivh unzip-6.0-16.ky3.1.kb2.x86_64.rpm
rpm -ivh zip-3.0-11.ky3.1.kb2.x86_64.rpm
rpm -ivh tcpdump-4.5.1-3.ky3.1.kb2.x86_64.rpm
fi
#Remove & Creat InstallPath/EMS
#删除旧的EMS文件夹下的内容,并在InstallPath目录下创建三个文件夹
rm -rf $InstallPath/EMS
mkdir $InstallPath
mkdir $InstallPath/EMS
mkdir $InstallPath/EMS/CommData
# Install Report Path
#安装报告的路径
ReportPath=$InstallPath/EMS/InstallLog.txt
#打印一行*并换行 输入进 安装报告中
echo -e "**********************************************************************\n" > $ReportPath
#获取版本号
#判断 是否存在/usr/bin/lsb_release文件,并且是一个普通文件,是就为真
if [[ -f /usr/bin/lsb_release ]]; then
#获取含有/usr/bin/lsb_release的系统的版本号,kylin系统是 UniKylin Linux release 3(Core)
OS=$(/usr/bin/lsb_release -a |grep Description |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
else
#如果lsb_release不存在,打印含有issue的文件中的指定的第一行赋值为变量OS
#centos系统是CentOS release 6.9 (Final)
OS=$(cat /etc/issue |sed -n '1p')
fi
#打印一行*并换行 追加输入进安装报告中
#echo -e "Linux OS Info: "$OS >> $ReportPath
echo -e "**********************************************************************\n" >> $ReportPath
#echo -e "$(date +%Y"."%m"."%d" "%k":"%M":"%S)\n" >> $ReportPath
# Install EMS
#cp -f:覆盖已经存在的目标文件而不给出提示。这个就是为了复制文件不提示,因为前面已经删除过旧的文件夹并生成了新的文件夹了
cp -f $PakageName $InstallPath/EMS/
cd $InstallPath/EMS
unzip $PakageName
chmod 777 *
rm -f $PakageName
#如果上一个命令的结果是非0的值,也就是出错了。
if [ $? -ne 0 ]; then
#打印安装失败追加进安装报告中并换行,再打印一行横线并退出程序
echo -e "Install fail! \n" >> $ReportPath
echo "---------------Install fails---------------" >> $ReportPath
exit 1
fi
# Set Power on Auto Run 增加权限开机自动运行
chmod 755 /etc/rc.d/rc.local
# Kill GW Agent & Disable GW Agent Auto Run
sed -i 's@^java1.8 -jar /usr/local/sbin/Agent.jar@#&@' /etc/rc.d/rc.local
#找出 agent.jar的进程号并杀死
kill -9 `ps -ef |grep "Agent.jar"|grep "java"| awk '{print $2}'`
# Set Power on Auto Run
if [ -z $1 ];then
if [[ `grep -c ''$InstallPath'/EMS/Run.sh' /etc/rc.d/rc.local` == '0' ]];then
echo -e "bash $InstallPath/EMS/Run.sh $InstallPath" >> /etc/rc.d/rc.local
echo -e "Setting self-starting successs! \n" >> $ReportPath
fi
if [[ `grep -c 'exit 0' /etc/rc.d/rc.local` != '0' ]];then
sed -i '/exit 0/d' /etc/rc.d/rc.local
echo "exit 0" | cat >> /etc/rc.d/rc.local
else
if [[ `grep -c 'exit 0' /etc/rc.d/rc.local` == '0' ]];then
echo "exit 0" | cat >> /etc/rc.d/rc.local
fi
fi
else
echo "No Setting self-starting"
fi
echo -e "Install success!\n"
echo -e "Time to install finished :$(date +%Y"."%m"."%d" "%k":"%M":"%S)\n" >> $ReportPath
# rm -rf $InstallPath/EMS/Log/Startup
$InstallPath/EMS/Run.sh $InstallPath
echo -e "Wait 10 seconds Start EMS..."
for (( i=10; i>0; i-- ))
do
echo "$i"
sleep 1s
done
#Output EMS Init Info
files=$(ls ''$InstallPath'/EMS/Log/Startup')
for filename in $files
do
cat "$InstallPath/EMS/Log/Startup/$filename"
done