#!/bin/bash -
#########################################################################################
#install
#安装程序,安装eGW,设置系统环境
#version:2.1
#dongfeng@baicells.com 20170425
#########################################################################################
#停止eGW服务
monitor_run=`systemctl status monitor.service |grep running`
if [ -n "$monitor_run" ];then
echo "start to stop monitor.service"
systemctl stop monitor.service
sleep 2
fi
#安装eGW
echo "start to install eGW"
DIR=/home/baicells/eGW
if [ ! -d "$DIR" ];then
echo "eGW is not exist"
echo "mkdir $DIR"
mkdir $DIR #如果主目录不存在,则创建目录
echo "tar -zxvf eGW.tar.gz"
echo "********************"
tar -zxvf eGW.tar.gz -C $DIR #解压安装文件
echo "********************"
echo "create config.txt and networkcfg.conf"
echo "#config file" > ${DIR}/config.txt #初始化网关配置文件
echo "#networkcfg file" > ${DIR}/networkcfg.conf #初始化网络配置文件
else
date=`date +%Y%m%d%H%M`
DIR_bak=${DIR}_bak
DIR_date=${DIR}_$date
echo "eGW is already exist"
echo "mv $DIR $DIR_bak"
mv $DIR $DIR_bak #如果目录存在,备份目录
echo "mkdir $DIR"
mkdir $DIR #然后创建目录
echo "********************"
tar -zxvf eGW.tar.gz -C $DIR #解压安装文件
echo "********************"
if [ -f "${DIR_bak}/config.txt" ];then
echo "cp ${DIR_bak}/config.txt $DIR"
cp ${DIR_bak}/config.txt $DIR #替换网关配置文件
else
echo "config.txt is not exist"
fi
if [ -f "${DIR_bak}/networkcfg.conf" ];then
echo "cp ${DIR_bak}/networkcfg.conf $DIR"
cp ${DIR_bak}/networkcfg.conf $DIR #替换网络配置文件
else
echo "networkcfg.conf is not exist"
fi
cd $DIR_bak
folder_CDR=CDR
if [ -d "$folder_CDR" ];then
echo "cp -rf ${DIR_bak}/$folder_CDR $DIR"
cp -rf ${DIR_bak}/$folder_CDR $DIR #保留话单到新版本
# else
# cd ${DIR}
# mkdir -p $folder_CDR/$folder_cdrDat
fi
folder_Dailystatic=Dailystatic
if [ -d "$folder_Dailystatic" ];then
echo "cp -rf ${DIR_bak}/$folder_Dailystatic $DIR"
cp -rf ${DIR_bak}/$folder_Dailystatic $DIR #保留流量统计到新版本
fi
folder_Userstatic=Userstatic
if [ -d "$folder_Userstatic" ];then
echo "cp -rf ${DIR_bak}/$folder_Userstatic $DIR"
cp -rf ${DIR_bak}/$folder_Userstatic $DIR #保留用户数统计到新版本
fi
mv $DIR_bak $DIR_date
fi
#修改文件执行权限
cd $DIR
echo "chmod +x"
chmod +x startAll.sh #修改执行权限
chmod +x monitor #修改执行权限
chmod +x ltegwd #修改执行权限
chmod +x ltegw.sh #修改执行权限
chmod +x lccmd #修改执行权限
chmod +x watchdog.sh #修改执行权限
chmod +x dailystatic.py #修改执行权限
chmod +x vtysh #修改执行权限
chmod +x emailontime.py #修改执行权限
chmod +x checkMD5.py #修改执行权限
echo "cp monitor.service /usr/lib/systemd/system/ "
cp monitor.service /usr/lib/systemd/system/ #复制脚本到服务目录
echo "mv libzebra.so.0 /usr/local/lib"
mv libzebra.so.0 /usr/local/lib #复制库文件到指定目录
echo "systemctl daemon-reload"
systemctl daemon-reload #更新服务目录
echo "systemctl enable monitor.service"
systemctl enable monitor.service #设置服务开机自启动
#设置系统环境
echo "start to set system"
#配置ipsec写入自启动
ipsec_autostart=`find /etc/rc.d -name "rc.local" |xargs grep "^ipsec start"`
if [ ! -n "$ipsec_autostart" ];then
echo "set ipsec start"
echo "ipsec start" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
echo "systemctl stop firewalld.service"
systemctl stop firewalld.service #为了防止系统防火墙屏蔽接口,先关闭防火墙
echo "systemctl disable firewalld.service"
systemctl disable firewalld.service #关闭开机启动
#ulimit -c unlimited #不限制用户资源
echo "set SELINUX closed"
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config #关闭selinux
#sed -i "s/Defaults requiretty/#Defaults requiretty/g" /etc/sudoers #修改root权限
echo "mkdir lc and mo"
if [ ! -d "/var/opc/lc" ];then
mkdir -p /var/opt/lc
fi
if [ ! -d "/var/opc/mo" ];then
mkdir -p /var/opt/mo
fi
ip_forward=`find /etc -name "sysctl.conf" |xargs grep "net.ipv4.ip_forward"`
if [ ! -n "$ip_forward" ];then
echo "set net.ipv4.ip_forward=1"
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
else
echo "set net.ipv4.ip_forward=1"
sed -i "s/net.ipv4.ip_forward=0/net.ipv4.ip_forward=1/g" /etc/sysctl.conf
fi
#设置coredump
cd /home/baicells
folder_coredump=coredump
echo "set coredump"
if [ ! -d "$folder_coredump" ];then
mkdir $folder_coredump
chmod 0773 $folder_coredump
fi
echo "kernel.core_pattern = /home/baicells/coredump/core-%e-sig%s-user%u-group%g-pid%p-time%t" > /etc/sysctl.d/core.conf
echo "kernel.core_uses_pid = 1" >> /etc/sysctl.d/core.conf
echo "fs.suid_dumpable = 2" >> /etc/sysctl.d/core.conf
echo "* hard core unlimited" > /etc/security/limits.d/core.conf
echo "* soft core unlimited" >> /etc/security/limits.d/core.conf
default_limit_core=`find /etc/systemd -name "system.conf" |xargs grep "DefaultLimitCORE=infinity"`
if [ ! -n "$default_limit_core" ];then
echo "DefaultLimitCORE=infinity" >> /etc/systemd/system.conf
fi
systemctl daemon-reload
systemctl daemon-reexec
sysctl -p /etc/sysctl.d/core.conf
sysctl -p
#启动eGW服务
echo "start to start monitor.service"
systemctl start monitor.service