1. #!/bin/bash
    2. # EMS Installer
    3. # QiGang
    4. # 2018/01/24
    5. # PakageName(Exp:EMS.zip)
    6. PakageName="EMS.zip"
    7. # InstallPath(Exp:/opt/goldwind/)
    8. InstallPath="/opt/goldwind"
    9. # Install RPMs
    10. #查看内核 是否包含ky3.kb3.x86_64,包含就安装以下包
    11. #-i 安装软件包
    12. #-v 可视化提供更多的详细信息的输出
    13. #-h 显示安装进度 
    14. if [[ `uname -r | grep -c 'ky3.kb3.x86_64'` != '0' ]];then
    15. rpm -ivh unzip-6.0-16.ky3.1.kb2.x86_64.rpm
    16. rpm -ivh zip-3.0-11.ky3.1.kb2.x86_64.rpm
    17. rpm -ivh tcpdump-4.5.1-3.ky3.1.kb2.x86_64.rpm
    18. fi
    19. #Remove & Creat InstallPath/EMS
    20. #删除旧的EMS文件夹下的内容,并在InstallPath目录下创建三个文件夹
    21. rm -rf $InstallPath/EMS
    22. mkdir $InstallPath
    23. mkdir $InstallPath/EMS
    24. mkdir $InstallPath/EMS/CommData
    25. # Install Report Path
    26. #安装报告的路径
    27. ReportPath=$InstallPath/EMS/InstallLog.txt
    28. #打印一行*并换行 输入进 安装报告中
    29. echo -e "**********************************************************************\n" > $ReportPath
    30. #获取版本号
    31. #判断 是否存在/usr/bin/lsb_release文件,并且是一个普通文件,是就为真
    32. if [[ -f /usr/bin/lsb_release ]]; then
    33. #获取含有/usr/bin/lsb_release的系统的版本号,kylin系统是 UniKylin Linux release 3(Core)
    34. OS=$(/usr/bin/lsb_release -a |grep Description |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
    35. else
    36. #如果lsb_release不存在,打印含有issue的文件中的指定的第一行赋值为变量OS
    37. #centos系统是CentOS release 6.9 (Final)
    38. OS=$(cat /etc/issue |sed -n '1p')
    39. fi
    40. #打印一行*并换行 追加输入进安装报告中
    41. #echo -e "Linux OS Info: "$OS >> $ReportPath
    42. echo -e "**********************************************************************\n" >> $ReportPath
    43. #echo -e "$(date +%Y"."%m"."%d" "%k":"%M":"%S)\n" >> $ReportPath
    44. # Install EMS
    45. #cp -f:覆盖已经存在的目标文件而不给出提示。这个就是为了复制文件不提示,因为前面已经删除过旧的文件夹并生成了新的文件夹了
    46. cp -f $PakageName $InstallPath/EMS/
    47. cd $InstallPath/EMS
    48. unzip $PakageName
    49. chmod 777 *
    50. rm -f $PakageName
    51. #如果上一个命令的结果是非0的值,也就是出错了。
    52. if [ $? -ne 0 ]; then
    53. #打印安装失败追加进安装报告中并换行,再打印一行横线并退出程序
    54. echo -e "Install fail! \n" >> $ReportPath
    55. echo "---------------Install fails---------------" >> $ReportPath
    56. exit 1
    57. fi
    58. # Set Power on Auto Run 增加权限开机自动运行
    59. chmod 755 /etc/rc.d/rc.local
    60. # Kill GW Agent & Disable GW Agent Auto Run
    61. sed -i 's@^java1.8 -jar /usr/local/sbin/Agent.jar@#&@' /etc/rc.d/rc.local
    62. #找出 agent.jar的进程号并杀死
    63. kill -9 `ps -ef |grep "Agent.jar"|grep "java"| awk '{print $2}'`
    64. # Set Power on Auto Run
    65. if [ -z $1 ];then
    66. if [[ `grep -c ''$InstallPath'/EMS/Run.sh' /etc/rc.d/rc.local` == '0' ]];then
    67. echo -e "bash $InstallPath/EMS/Run.sh $InstallPath" >> /etc/rc.d/rc.local
    68. echo -e "Setting self-starting successs! \n" >> $ReportPath
    69. fi
    70. if [[ `grep -c 'exit 0' /etc/rc.d/rc.local` != '0' ]];then
    71. sed -i '/exit 0/d' /etc/rc.d/rc.local
    72. echo "exit 0" | cat >> /etc/rc.d/rc.local
    73. else
    74. if [[ `grep -c 'exit 0' /etc/rc.d/rc.local` == '0' ]];then
    75. echo "exit 0" | cat >> /etc/rc.d/rc.local
    76. fi
    77. fi
    78. else
    79. echo "No Setting self-starting"
    80. fi
    81. echo -e "Install success!\n"
    82. echo -e "Time to install finished :$(date +%Y"."%m"."%d" "%k":"%M":"%S)\n" >> $ReportPath
    83. # rm -rf $InstallPath/EMS/Log/Startup
    84. $InstallPath/EMS/Run.sh $InstallPath
    85. echo -e "Wait 10 seconds Start EMS..."
    86. for (( i=10; i>0; i-- ))
    87. do
    88. echo "$i"
    89. sleep 1s
    90. done
    91. #Output EMS Init Info
    92. files=$(ls ''$InstallPath'/EMS/Log/Startup')
    93. for filename in $files
    94. do
    95. cat "$InstallPath/EMS/Log/Startup/$filename"
    96. done