linux: egw-new.spec

[root@eGW SPECS]# cat egw-new.spec 
Name:           WCG
Version :   1.4.4        
Release:        6%{?dist}
Summary:        WCG rpm package

License:        GPL
Packager:   dongfeng
#URL:            
Source0:        WCG-1.4.4.tar.gz

#BuildRequires:  
Requires:   nginx,redis,hiredis,hiredis-devel,fcgi,fcgi-devel,spawn-fcgi,gsoap,curl,lksctp-tools,vconfig,wireshark-gnome,xinetd,tftp,tftp-server,keepalived      

%description
The rpm package for WCG install!


%prep
%setup -q


%build


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/root/eGW
cp -rf *  $RPM_BUILD_ROOT/root/eGW

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc
/root/eGW

%changelog

##########################################################################################
%pre

#Description: This script is used to check system before install WCG

#检查内核版本号
function check_kernel() {
    kernel_ver=$(uname -r)
    #echo $kernel_ver
    if [[ $kernel_ver != "3.10.0-514.el7.centos.x86_64" ]];then
        echo "system kernel must be 3.10.0-514.el7.centos.x86_64, please check!"
        exit 1
    fi
}

#升级前,检查备份原版本
function bak_wcg() {
    DIR=/root/eGW
    DIR_WCG=${DIR}.wcg
    ltegwd_file=${DIR}/ltegwd
    if [ -f "$ltegwd_file" ];then
        #date=`date +%Y%m%d%H%M`
        if [ -d "$DIR_WCG" ];then    #如果备份文件存在,则删除
            rm -rf $DIR_WCG
        fi
        echo "eGW folder is exist,automove it to eGW.wcg"
        mv $DIR $DIR_WCG    #如果目录存在,备份目录
    else
        rm -rf $DIR
    fi      
}

#关闭NetworkManager服务
function stop_networkmanager() {
    systemctl stop NetworkManager.service
    systemctl disable NetworkManager.service
}       

function pre_install_wcg() {
    check_kernel
    bak_wcg
    stop_networkmanager
}
pre_install_wcg

###########################################################################################
%post

DIR=/root/eGW
DIR_WCG=${DIR}.wcg

function del_py() {
    rm -rf /root/eGW/dailystatic.pyc
    rm -rf /root/eGW/dailystatic.pyo
}

#recover网关licence文件
function recover_wcg_licence() {
    if [ -d "${DIR_WCG}" ];then
        if [ -f "${DIR_WCG}/Licence/licence.bin" ];then
            echo "cp ${DIR_WCG}/Licence/licence.bin $DIR/Licence/licence.bin"
                cp -rf ${DIR_WCG}/Licence/licence.bin $DIR/Licence/licence.bin 
            else
                echo "licence.bin is not exist"
            fi
        if [ -f "${DIR_WCG}/Licence/licence.auth" ];then
            echo "cp ${DIR_WCG}/Licence/licence.auth $DIR/Licence/licence.auth"
            cp -rf ${DIR_WCG}/Licence/licence.auth $DIR/Licence/licence.auth
            else
                    echo "licence.auth is not exist"
            fi
    fi
}

#recover网关config文件
function recover_wcg_config() {
    if [ -d "${DIR_WCG}" ];then
        if [ -f "${DIR_WCG}/config.txt" ];then
                echo "cp ${DIR_WCG}/config.txt $DIR"
                cp -rf ${DIR_WCG}/config.txt $DIR    
            else
                echo "config.txt is not exist"
            fi
    fi
}

#recover网关networkcfg文件
function recover_wcg_networkcfg() {
    if [ -d "${DIR_WCG}" ];then
        if [ -f "${DIR_WCG}/networkcfg.conf" ];then
            echo "cp ${DIR_WCG}/networkcfg.conf $DIR"
                    cp -rf ${DIR_WCG}/networkcfg.conf $DIR  
            else
                echo "networkcfg.conf is not exist"
            fi
    fi
}

#recover网关eGW_Cfg_Info文件
function recover_wcg_omc() {
    if [ -d "${DIR_WCG}" ];then
        if [ -f "${DIR_WCG}/OMC/eGW_Cfg_Info.xml" ];then
                echo "cp ${DIR_WCG}/OMC/eGW_Cfg_Info.xml ${DIR}/OMC"
                cp -rf ${DIR_WCG}/OMC/eGW_Cfg_Info.xml ${DIR}/OMC  
            else
                echo "eGW_Cfg_Info.xml is not exist"
            fi
    fi
}

#recover网关cdr文件
function recover_wcg_cdr() {
    if [ -d "${DIR_WCG}" ];then
        if [ -d "${DIR_WCG}/CDR" ];then
                    echo "cp -rf ${DIR_WCG}/CDR $DIR"
                    cp -rf ${DIR_WCG}/CDR $DIR
            fi
    fi
}

#recover网关static文件
function recover_wcg_static() {
    if [ -d "${DIR_WCG}" ];then
        if [ -d "${DIR_WCG}/static" ];then
                    echo "cp -rf ${DIR_WCG}/static $DIR"
                    cp -rf ${DIR_WCG}/static $DIR
            fi
    fi
}

#recover网关log文件
function recover_wcg_log() {
        if [ -d "${DIR_WCG}" ];then
                if [ -d "${DIR_WCG}/Logs" ];then
                    echo "cp -rf ${DIR_WCG}/Logs $DIR"
                    cp -rf ${DIR_WCG}/Logs $DIR
            fi
        fi
}


function recover_wcg_configure() {
    recover_wcg_licence
    recover_wcg_config
    recover_wcg_networkcfg
    recover_wcg_omc
    recover_wcg_cdr
    recover_wcg_static
    recover_wcg_log
}

#增加执行权限
function addx() {
    cd $DIR
    chmod +x startAll.sh
    chmod +x ltegwd
    chmod +x lccmd
    chmod +x vtysh
    chmod +x dailystatic.py
    chmod +x vman
    chmod +x Static

    cd ${DIR}/config.sh
    chmod +x *

    cd ${DIR}/OMC
    chmod +x egw_manage
    chmod +x egw_report

    cd $DIR/Licence
    chmod +x register
}

#注册wcg
function register_wcg() {
    /root/eGW/Licence/register
}

#配置other
function other() {
    cd $DIR
    mv -f monitor.service /usr/lib/systemd/system/
    mv -f libzebra.so.0 /usr/local/lib 
    mv -f lccmd /usr/sbin/
    systemctl daemon-reload
    systemctl enable monitor.service
}

#配置nginx
function config_nginx() {
    if [ ! -d "/usr/share/nginx/logs" ];then
        mkdir -p /usr/share/nginx/logs
    fi
    grep 'server_name eGW_omc' /etc/nginx/nginx.conf 2>&1>/dev/null
    if [ $? -eq 1 ];then
        sed -i '/include \/etc\/nginx\/conf.d\/\*.conf;/r nginx_add.txt' /etc/nginx/nginx.conf
    fi
    rm -rf nginx_add.txt
    systemctl enable nginx.service
    systemctl restart nginx.service
}
#配置redis
function config_redis() {
    systemctl enable redis.service
    systemctl restart redis.service
}

#设置系统环境
function set_system_env() {
    systemctl stop firewalld.service #为了防止系统防火墙屏蔽接口,先关闭防火墙
    systemctl disable firewalld.service #关闭开机启动
    #ulimit -c unlimited  #不限制用户资源
    setenforce 0
    sed -i "s/SELINUX=enforcing/SELINUX=disabled/g"  /etc/selinux/config #关闭selinux
    if [ ! -d "/var/opc/lc" ];then
        mkdir -p /var/opt/lc
    fi
    if [ ! -d "/var/opc/mo" ];then
        mkdir -p /var/opt/mo
    fi
}

function ip_forward() {
    ip_forward=`grep "net.ipv4.ip_forward" /etc/sysctl.conf`
    if [ ! -n "$ip_forward" ];then
        echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
    else    
        sed -i "s/\(net.ipv4.ip_forward.*\)/net.ipv4.ip_forward = 1/g"  /etc/sysctl.conf
    fi
}

function neigh_default_gc_thresh() {
    neigh_default_gc_thresh1=`grep "net.ipv4.neigh.default.gc_thresh1" /etc/sysctl.conf`
    neigh_default_gc_thresh2=`grep "net.ipv4.neigh.default.gc_thresh2" /etc/sysctl.conf`
    neigh_default_gc_thresh3=`grep "net.ipv4.neigh.default.gc_thresh3" /etc/sysctl.conf`
    if [ ! -n "$neigh_default_gc_thresh1" ];then
        echo "net.ipv4.neigh.default.gc_thresh1 = 25000" >> /etc/sysctl.conf
    else    
        sed -i "s/\(net.ipv4.neigh.default.gc_thresh1.*\)/net.ipv4.neigh.default.gc_thresh1 = 25000/g"  /etc/sysctl.conf
    fi
    if [ ! -n "$neigh_default_gc_thresh2" ];then
        echo "net.ipv4.neigh.default.gc_thresh2 = 30000" >> /etc/sysctl.conf
    else    
        sed -i "s/\(net.ipv4.neigh.default.gc_thresh2.*\)/net.ipv4.neigh.default.gc_thresh2 = 30000/g"  /etc/sysctl.conf
    fi
    if [ ! -n "$neigh_default_gc_thresh3" ];then
        echo "net.ipv4.neigh.default.gc_thresh3 = 40000" >> /etc/sysctl.conf
    else    
        sed -i "s/\(net.ipv4.neigh.default.gc_thresh3.*\)/net.ipv4.neigh.default.gc_thresh3 = 40000/g"  /etc/sysctl.conf
    fi
}

function kernel_msg() {
    kernel_msgmni=`grep "kernel.msgmni" /etc/sysctl.conf`
    kernel_msgmax=`grep "kernel.msgmax" /etc/sysctl.conf`
    kernel_msgmnb=`grep "kernel.msgmnb" /etc/sysctl.conf`
    if [ ! -n "$kernel_msgmax" ];then
        echo "kernel.msgmax = 8192" >> /etc/sysctl.conf
    else    
        sed -i "s/\(kernel.msgmax.*\)/kernel.msgmax = 8192/g"  /etc/sysctl.conf
    fi
    if [ ! -n "$kernel_msgmni" ];then
        echo "kernel.msgmni = 32768" >> /etc/sysctl.conf
    else    
        sed -i "s/\(kernel.msgmni.*\)/kernel.msgmni = 32768/g"  /etc/sysctl.conf
    fi
    if [ ! -n "$kernel_msgmnb" ];then
        echo "kernel.msgmnb = 4203520" >> /etc/sysctl.conf
    else    
        sed -i "s/\(kernel.msgmnb.*\)/kernel.msgmnb = 4203520/g"  /etc/sysctl.conf
    fi
}

function config_sysctl() {
    ip_forward
    neigh_default_gc_thresh
    kernel_msg
}

function set_coredump() {
    folder_coredump=coredump
    default_limit_core=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitCORE"`
    default_limit_nofile=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitNOFILE"`
    cd /root
    if [ ! -d "$folder_coredump" ];then
        mkdir $folder_coredump
        chmod 0773 $folder_coredump
    fi
    echo "kernel.core_pattern = /root/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
    if [ ! -n "$default_limit_core" ];then
        echo "DefaultLimitCORE=infinity" >> /etc/systemd/system.conf
    else
        sed -i "s/\(DefaultLimitCORE.*\)/DefaultLimitCORE=infinity/g"  /etc/systemd/system.conf
    fi
    if [ ! -n "$default_limit_nofile" ];then
        echo "DefaultLimitNOFILE=102400" >> /etc/systemd/system.conf
    else
        sed -i "s/\(DefaultLimitNOFILE.*\)/DefaultLimitNOFILE=102400/g"  /etc/systemd/system.conf   
    fi
    systemctl daemon-reload
    systemctl daemon-reexec
    sysctl -p /etc/sysctl.d/core.conf
    sysctl -p
}

function set_history() {
    grep '^HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
    if [[ $? -eq 1 ]];then
        grep '^#HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
        if [[ $? -eq 1 ]];then
            echo "HISTORY_IPADDR_tmp=\`who am i |awk '{ print \$5 }'\`" >> /etc/profile
        else
            sed -i "s/#HISTORY_IPADDR_tmp=/HISTORY_IPADDR_tmp=/" /etc/profile > /dev/null
        fi  
    fi

    grep '^HISTORY_IPADDR=' /etc/profile >/dev/null
    if [[ $? -eq 1 ]];then
        grep '^#HISTORY_IPADDR=' /etc/profile > /dev/null
        if [[ $? -eq 1 ]];then
            echo "HISTORY_IPADDR=\${HISTORY_IPADDR_tmp:1:-1}" >> /etc/profile
        else
            sed -i "s/#HISTORY_IPADDR=/HISTORY_IPADDR=/" /etc/profile > /dev/null
        fi
    fi
    grep '^HISTORY_FILE=' /etc/profile > /dev/null
    if [[ $? -eq 1 ]];then
        grep '^#HISTORY_FILE=' /etc/profile > /dev/null
        if [[ $? -eq 1 ]];then
            echo "HISTORY_FILE=/root/eGW/Logs/history/\${HISTORY_IPADDR}.log &> /dev/null" >> /etc/profile
        else
            sed -i "s/#HISTORY_FILE=/HISTORY_FILE=/" /etc/profile > /dev/null
        fi
    fi
    grep '^export PROMPT_COMMAND=' /etc/profile > /dev/null
    if [[ $? -eq 1 ]];then
        prompt_command_format='{ date "+%Y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(pwd) #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTORY_FILE'
        grep '^#export PROMPT_COMMAND' /etc/profile > /dev/null
        if [[ $? -eq 1 ]];then
            echo "export PROMPT_COMMAND='$prompt_command_format'" >> /etc/profile
        else
            sed -i "s/#export PROMPT_COMMAND=/export PROMPT_COMMAND=/" /etc/profile > /dev/null
        fi
    fi
    source /etc/profile
}

function update_ssh() {
    yum update -y openssh
}

function set_version() {
    version="WCG-1.4.4"
    mkdir -p /root/eGW/.version/versions
    lccmd_md5=`md5sum /usr/sbin/lccmd |awk '{print $1}'`
    ltegwd_md5=`md5sum /root/eGW/ltegwd |awk '{print $1}'`
    gtp_relay_md5=`md5sum /root/eGW/gtp-relay.ko |awk '{print $1}'`
    echo lccmd:$lccmd_md5 > /root/eGW/.version/versions/${version}.ver
    echo ltegwd:$ltegwd_md5 >> /root/eGW/.version/versions/${version}.ver
    echo gtp-relay.ko:$gtp_relay_md5 >> /root/eGW/.version/versions/${version}.ver
}

function recover_keepalived() {
    mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
    mv /root/eGW/keepalived.conf /etc/keepalived/keepalived.conf
}

function post_install_wcg() {
    systemctl stop monitor.service
    del_py
    recover_wcg_configure
    addx
    register_wcg
    other
    config_nginx
    config_redis
    set_system_env
    config_sysctl
    set_coredump
    set_history
    #update_ssh
    set_version
    recover_keepalived
    systemctl start monitor.service
}

post_install_wcg

##########################################################################################
%preun

DIR=/root/eGW
DIR_WCG=${DIR}.wcg


function unset_history() {
    grep '^HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
    if [[ $? -eq 0 ]];then
        sed -i "s/HISTORY_IPADDR_tmp=/#HISTORY_IPADDR_tmp=/" /etc/profile > /dev/null
    fi
    grep '^HISTORY_IPADDR=' /etc/profile >/dev/null
    if [[ $? -eq 0 ]];then
        sed -i "s/HISTORY_IPADDR=/#HISTORY_IPADDR=/" /etc/profile > /dev/null
    fi
    grep '^HISTORY_FILE=' /etc/profile > /dev/null
    if [[ $? -eq 0 ]];then
        sed -i "s/HISTORY_FILE=/#HISTORY_FILE=/" /etc/profile > /dev/null
    fi
    grep '^export PROMPT_COMMAND=' /etc/profile > /dev/null
    if [[ $? -eq 0 ]];then
        sed -i "s/export PROMPT_COMMAND=/#export PROMPT_COMMAND=/" /etc/profile > /dev/null
    fi
    source /etc/profile
}

function stop_wcg() {
    systemctl stop monitor.service
    pkill ltegwd
    pkill startAll.sh
    pkill egw_manage
    pkill egw_report
}

function bak_wcg() {
    if [ -d "$DIR" ];then
        if [ -d "$DIR_WCG" ];then    #如果备份文件存在,则删除
                rm -rf $DIR_WCG
        fi
        echo "cp $DIR to $DIR_WCG"
        cp -rf $DIR $DIR_WCG    #如果目录存在,备份目录
    fi
}

function recover_file() {
    if [ -d "$DIR" ];then
        touch /root/eGW/dailystatic.pyc
        touch /root/eGW/dailystatic.pyo
        touch /root/eGW/nginx_add.txt
        rm -rf ${DIR}/Licence/licence.auth
        rm -rf ${DIR}/Licence/licence.bin
        rm -rf ${DIR}/CDR/*
        mkdir ${DIR}/CDR/cdrDat
        rm -rf ${DIR}/Logs/ltegwd/*
        rm -rf ${DIR}/Logs/manage/*
        rm -rf ${DIR}/Logs/report/*
        rm -rf ${DIR}/Logs/watchdog/*
        rm -rf ${DIR}/Logs/history/*
        rm -rf ${DIR}/Logs/keepalived/*
        rm -rf ${DIR}/static/dailystatic/*
        rm -rf ${DIR}/static/userstatic/*
        rm -rf ${DIR}/.version
        #rm -rf ${DIR}/update/*
        cp /usr/local/lib/libzebra.so.0 /root/eGW
        mv /usr/lib/systemd/system/monitor.service /root/eGW
        mv /usr/sbin/lccmd /root/eGW
        mv /etc/keepalived/keepalived.conf /root/eGW
        mv /etc/keepalived/keepalived.conf.bak /etc/keepalived/keepalived.conf
        #rm -rf /usr/lib/systemd/system/monitor.service
        #rm -rf /usr/sbin/lccmd
        systemctl daemon-reload
    fi
}

function preun_uninstall_wcg() {
    unset_history
    stop_wcg
    bak_wcg
    recover_file
}

preun_uninstall_wcg

############################################################################################
%postun

#rm -rf /root/eGW
#rm -rf /usr/sbin/lccmd
############################################################################################

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,108评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,699评论 1 296
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,812评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,236评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,583评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,739评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,957评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,704评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,447评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,643评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,133评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,486评论 3 256
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,151评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,108评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,889评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,782评论 2 277
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,681评论 2 272

推荐阅读更多精彩内容