#!/bin/bash
#
#Version : 1.6
# 
#DATE:2018-12-28 BY Daniel.
#脚本更新
#1.判断是否安装scp优化
#2.根据服务器CPU核数自动修改PHP-FPM子进程数
#3.NGINX加入tar配置
#4.更新运营版，企业版版本号
#5.NGINX加入recordFile配置（2021.04.07）
#6.新增API代理平台安装和python版本变更（2022.06.13）
#7.安装失败打印（20220907）

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
exec > >(tee /home/update.log) 2>&1

cat << EOF
1.Install OK-CC-Cloud. 
2.Install OK-CC-Project.
3.Install OK-CC-BLA.
4.Install OK-CC-ApiProxy. 
EOF

read -p "Input your choice: " CHOICE

if [ ! -d /home/package ];then
        mkdir -p /home/package
fi

# 检查安装scp工具
if command -v scp &>/dev/null; then
    echo "scp is already installed"
else
    echo "Installing scp and dependencies..."
    yum install -y epel-release &>/dev/null
    yum install -y openssh openssh-clients &>/dev/null
    echo "scp installed successfully"
fi

# 检查ntpd
if command -v ntpd &>/dev/null; then
    echo "ntpd is already installed"
else
    echo "Installing ntpd..."
    yum install -y ntp &>/dev/null
    echo "ntpd installed successfully"
fi

# 确保 ntpd 开机启动
chkconfig ntpd on
echo "ntpd is set to start on boot"


#3.备份fs sounds目录
BACKUP_FS_SOUND () {
if [ -d /usr/local/freeswitch/sounds ];then 
        if [ ! -f /usr/local/freeswitch/sounds/okcc.tar.gz ];then
                cd /usr/local/freeswitch/sounds/
                tar -zcf okcc.tar.gz okcc
                cd /home
        else
                cd /usr/local/freeswitch/sounds/
                rm -rf okcc.tar.gz
                tar -zcf okcc.tar.gz okcc
                cd /home
        fi
fi
}

#配置检查及修改
CHECK_CONF () {
#fs配置路径
FS_CONF=/usr/local/freeswitch/conf
#Nginx配置文件
NGINX_CONF=/usr/local/nginx/conf/nginx.conf
#php-fpm配置路径
PHPFPM_CONF=/usr/local/php/etc/php-fpm.conf

#1.检查时区,将时区改为东8区
ZONEINFO=`date -R |awk -F' ' '{print $6}'`
if [ "$ZONEINFO" != "+0800" ];then 
        \cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
        if `which ntpdate`;then
                /etc/init.d/ntpd stop &>/dev/null 
                /usr/sbin/ntpdate time2.aliyun.com &>/dev/null
                /sbin/hwclock -w &>/dev/null
                /etc/init.d/ntpd start &>/dev/null
        fi
fi

#2.修改PHP配置文件，行尾加入":/etc/lics/"
grep '/etc/lics' /usr/local/php/lib/php.ini &>/dev/null || sed -i 's@open_basedir = /var/www/html/:/var/www/web-v2/:/usr/local/freeswitch/conf/directory/default/:/usr/local/freeswitch/conf/sip_profiles/external/:/home/ipcc/data/:/usr/local/freeswitch/conf/autoload_configs/:/tmp/:/dev/shm/:/ipcc/etc/pub/@open_basedir = /var/www/html/:/var/www/web-v2/:/usr/local/freeswitch/conf/directory/default/:/usr/local/freeswitch/conf/sip_profiles/external/:/home/ipcc/data/:/usr/local/freeswitch/conf/autoload_configs/:/tmp/:/dev/shm/:/ipcc/etc/pub/:/etc/lics/@g' /usr/local/php/lib/php.ini

#3.修改FS最大sessions和CPS 
CORE_NUMS=`cat /proc/cpuinfo |grep processor |wc -l`
if [ $CORE_NUMS -ge 1 ];then 
        grep '<param name="max-sessions" value="5000"/>' $FS_CONF/autoload_configs/switch.conf.xml &>/dev/null || sed -i 's@<param name="max-sessions" value="1500"/>@<param name="max-sessions" value="5000"/>@g' $FS_CONF/autoload_configs/switch.conf.xml
        grep '<param name="sessions-per-second" value="300"/>' $FS_CONF/autoload_configs/switch.conf.xml &>/dev/null || sed -i 's@<param name="sessions-per-second" value="100"/>@<param name="sessions-per-second" value="300"/>@g' $FS_CONF/autoload_configs/switch.conf.xml
fi

#4.根据服务器CPU核数自动修改PHP-FPM子进程数
if [ $CORE_NUMS -le 4 ];then
        sed -i s@'pm.max_children = .*'@'pm.max_children = 4'@g $PHPFPM_CONF
        sed -i s@'pm.start_servers = .*'@'pm.start_servers = 2'@g $PHPFPM_CONF
        sed -i s@'pm.min_spare_servers = .*'@'pm.min_spare_servers = 2'@g $PHPFPM_CONF
        sed -i s@'pm.max_spare_servers = .*'@'pm.max_spare_servers = 4'@g $PHPFPM_CONF
fi

if [ $CORE_NUMS -gt 4 ];then
        sed -i s@'pm.max_children = .*'@'pm.max_children = '$CORE_NUMS''@g $PHPFPM_CONF
        sed -i s@'pm.start_servers = .*'@'pm.start_servers = '$[$CORE_NUMS/2]''@g $PHPFPM_CONF
        sed -i s@'pm.min_spare_servers = .*'@'pm.min_spare_servers = '$[$CORE_NUMS/2]''@g $PHPFPM_CONF
        sed -i s@'pm.max_spare_servers = .*'@'pm.max_spare_servers = '$CORE_NUMS''@g $PHPFPM_CONF
fi



#检查专用网络还是经典网络
#PUBLIC_IP=`curl members.3322.org/dyndns/getip`
#if `ifconfig |grep $PUBLIC_IP`;then
#       sleep 1
#else
#       sed -i s@"auto-nat@"$PUBLIC_IP@g $FS_CONF/sip_profiles/{internal,external}.xml
#fi


#5./etc/rc.sysinit追加配置
grep '/ipcc/sbin/system-startup-hook.sh' /etc/rc.sysinit  &>/dev/null || \
cat >> /etc/rc.sysinit << EOF
if [ -f /ipcc/sbin/system-startup-hook.sh ]; then
    if [ ! -x /ipcc/sbin/system-startup-hook.sh ]; then
        chmod +x /ipcc/sbin/system-startup-hook.sh
    fi

    /ipcc/sbin/system-startup-hook.sh
fi
EOF


if [ -f /ipcc/sbin/system-startup-hook/lock-file.sh ];then
        if ! grep "/usr/local/freeswitch/run/freeswitch.pid" /ipcc/sbin/system-startup-hook/lock-file.sh;then
                echo "rm -rf /usr/local/freeswitch/run/freeswitch.pid" >>/ipcc/sbin/system-startup-hook/lock-file.sh
        fi
fi


#修改net.ipv4.tcp_max_tw_buckets的值
if grep 'net.ipv4.tcp_max_tw_buckets' /etc/sysctl.conf;then
        sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
        echo "net.ipv4.tcp_max_tw_buckets = 60000" >> /etc/sysctl.conf
else
        echo "net.ipv4.tcp_max_tw_buckets = 60000" >> /etc/sysctl.conf
fi

/sbin/sysctl -p &>/dev/null

#6修改Nginx配置
#6.1修改nginx超时时长
if ! grep fastcgi_read_timeout $NGINX_CONF;then
        sed -i '/gzip_disable/a\    fastcgi_read_timeout 150;' $NGINX_CONF
fi

#6.2添加tar路径
if ! grep 'location ~ \\.tar' $NGINX_CONF;then
        sed -i '/ # MP3 file is not in the wb root dir/i\       location ~ \\.tar {' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\           root   /home/ipcc;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\       }' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\\'     $NGINX_CONF
fi

#6.3添加recordFile路径
if ! grep 'recordFile' $NGINX_CONF;then
        sed -i '/ # MP3 file is not in the wb root dir/i\        # for recordFile' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                       location /recordFile {' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                root           /var/www/web-v2/;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                fastcgi_index  index.php;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\\                rewrite /recordFile/(.*) /service/index.php?m=common&c=recordFile&f=$1 last;'     $NGINX_CONF
                sed -i '/ # MP3 file is not in the wb root dir/i\        }'     $NGINX_CONF
fi


#7.恢复sounds
if [ -f /usr/local/freeswitch/sounds/okcc.tar.gz ];then
        cd /usr/local/freeswitch/sounds/
        tar -zxf okcc.tar.gz
        cd /home
fi

#8.修改CPU空闲配置
cat /etc/global.xml | grep "min_idel_cpu" | while read line
do
        value=`echo $line | awk -F " " '{print $3}'`
        if [ '$value' != 'value="10"' ];then
                sed -i s@'<param name="min_idel_cpu" '${value}' />'@'<param name="min_idel_cpu" value="10" />'@g /etc/global.xml
                
        fi
done

#9.ridis添加配置
#9.1 php添加redis库
if ! grep extension=redis.so /usr/local/php/lib/php.ini &>/dev/null;then
        sed -i '/extension=php_shmop.dll/a\extension=redis.so' /usr/local/php/lib/php.ini
fi

#9.2 监控项目加入redis
if ! grep redis /etc/hb-srv.xml &>/dev/null;then
        sed -i '/<\/process>/i\        <10>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\            <param name=\"name\"      value=\"redis\" \/>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\            <param name=\"startcmd\"  value=\"service redis start\" \/>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\            <param name=\"version\"   value=\"1.0\" \/>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\            <param name=\"heartbeat\" value=\"false\" \/>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\            <param name=\"pid\"       value=\"/usr/local/redis-5.0.4/run/redis.pid\" \/>' /etc/hb-srv.xml
        sed -i '/<\/process>/i\        <\/10>' /etc/hb-srv.xml
fi
}

#10 修改python版本号
#/usr/libexec/urlgrabber-ext-down  删除第一行插入 #! /usr/bin/python2.7
sed -i '1d' /usr/libexec/urlgrabber-ext-down && sed -i '1i\#! /usr/bin/python2.7' /usr/libexec/urlgrabber-ext-down &>/dev/null

#/usr/bin/yum                      删除第一行插入 #! /usr/bin/python2.7
sed -i '1d' /usr/bin/yum && sed -i '1i\#! /usr/bin/python2.7' /usr/bin/yum &>/dev/null

#/usr/bin/firewall-cmd             删除第一行插入 #!/usr/bin/python2.7 -Es
sed -i '1d' /usr/bin/firewall-cmd && sed -i '1i\#!/usr/bin/python2.7 -Es' /usr/bin/firewall-cmd &>/dev/null

#/usr/sbin/firewalld               删除第一行插入 #!/usr/bin/python2.7 -Es
sed -i '1d' /usr/sbin/firewalld && sed -i '1i\#!/usr/bin/python2.7 -Es' /usr/sbin/firewalld &>/dev/null

#黑名单服务器配置
BLA_CONF () {
#fs配置路径
FS_CONF=/usr/local/freeswitch/conf
#Nginx配置文件
NGINX_CONF=/usr/local/nginx/conf/nginx.conf
#php-fpm配置路径
PHPFPM_CONF=/usr/local/php/etc/php-fpm.conf

#1.检查时区,将时区改为东8区
ZONEINFO=`date -R |awk -F' ' '{print $6}'`
if [ "$ZONEINFO" != "+0800" ];then 
        \cp -a /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
        if `which ntpdate`;then
                /etc/init.d/ntpd stop &>/dev/null 
                /usr/sbin/ntpdate ntp.api.bz &>/dev/null
                /sbin/hwclock -w &>/dev/null
                /etc/init.d/ntpd start &>/dev/null
        fi
fi

#2.修改FS最大sessions和CPS 
CORE_NUMS=`cat /proc/cpuinfo |grep processor |wc -l`
if [ $CORE_NUMS -ge 1 ];then 
        grep '<param name="max-sessions" value="5000"/>' $FS_CONF/autoload_configs/switch.conf.xml &>/dev/null || sed -i 's@<param name="max-sessions" value="1500"/>@<param name="max-sessions" value="10000"/>@g' $FS_CONF/autoload_configs/switch.conf.xml
        grep '<param name="sessions-per-second" value="100"/>' $FS_CONF/autoload_configs/switch.conf.xml &>/dev/null || sed -i 's@<param name="sessions-per-second" value="100"/>@<param name="sessions-per-second" value="300"/>@g'
    grep '<param name="sessions-per-second" value="200"/>' $FS_CONF/autoload_configs/switch.conf.xml &>/dev/null || sed -i 's@<param name="sessions-per-second" value="200"/>@<param name="sessions-per-second" value="300"/>@g'
        $FS_CONF/autoload_configs/switch.conf.xml

fi

#3.根据服务器CPU核数自动修改PHP-FPM子进程数
if [ $CORE_NUMS -le 4 ];then
        sed -i s@'pm.max_children = .*'@'pm.max_children = 4'@g $PHPFPM_CONF
        sed -i s@'pm.start_servers = .*'@'pm.start_servers = 2'@g $PHPFPM_CONF
        sed -i s@'pm.min_spare_servers = .*'@'pm.min_spare_servers = 2'@g $PHPFPM_CONF
        sed -i s@'pm.max_spare_servers = .*'@'pm.max_spare_servers = 4'@g $PHPFPM_CONF
fi

if [ $CORE_NUMS -gt 4 ];then
        sed -i s@'pm.max_children = .*'@'pm.max_children = '$CORE_NUMS''@g $PHPFPM_CONF
        sed -i s@'pm.start_servers = .*'@'pm.start_servers = '$[$CORE_NUMS/2]''@g $PHPFPM_CONF
        sed -i s@'pm.min_spare_servers = .*'@'pm.min_spare_servers = '$[$CORE_NUMS/2]''@g $PHPFPM_CONF
        sed -i s@'pm.max_spare_servers = .*'@'pm.max_spare_servers = '$CORE_NUMS''@g $PHPFPM_CONF
fi



#检查专用网络还是经典网络
#PUBLIC_IP=`curl members.3322.org/dyndns/getip`
#if `ifconfig |grep $PUBLIC_IP`;then
#       sleep 1
#else
#       sed -i s@"auto-nat@"$PUBLIC_IP@g $FS_CONF/sip_profiles/{internal,external}.xml
#fi


#4./etc/rc.sysinit追加配置
grep '/ipcc/sbin/system-startup-hook.sh' /etc/rc.sysinit  &>/dev/null || \
cat >> /etc/rc.sysinit << EOF
if [ -f /ipcc/sbin/system-startup-hook.sh ]; then
    if [ ! -x /ipcc/sbin/system-startup-hook.sh ]; then
        chmod +x /ipcc/sbin/system-startup-hook.sh
    fi

    /ipcc/sbin/system-startup-hook.sh
fi
EOF


if [ -f /ipcc/sbin/system-startup-hook/lock-file.sh ];then
        if ! grep "/usr/local/freeswitch/run/freeswitch.pid" /ipcc/sbin/system-startup-hook/lock-file.sh;then
                echo "rm -rf /usr/local/freeswitch/run/freeswitch.pid" >>/ipcc/sbin/system-startup-hook/lock-file.sh
        fi
fi


#5.修改net.ipv4.tcp_max_tw_buckets的值
if grep 'net.ipv4.tcp_max_tw_buckets' /etc/sysctl.conf;then
        sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
        echo "net.ipv4.tcp_max_tw_buckets = 25000" >> /etc/sysctl.conf
else
        echo "net.ipv4.tcp_max_tw_buckets = 25000" >> /etc/sysctl.conf
fi

/sbin/sysctl -p &>/dev/null

#6修改Nginx配置
#6.1修改nginx超时时长
if ! grep fastcgi_read_timeout $NGINX_CONF;then
        sed -i '/gzip_disable/a\    fastcgi_read_timeout 150;' $NGINX_CONF
fi

#6.2添加tar路径
if ! grep 'location ~ \\.tar' $NGINX_CONF;then
        sed -i '/ # MP3 file is not in the wb root dir/i\       location ~ \\.tar {' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\           root   /home/ipcc;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\       }' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\\'     $NGINX_CONF
fi

#6.3添加recordFile路径
if ! grep 'recordFile' $NGINX_CONF;then
        sed -i '/ # MP3 file is not in the wb root dir/i\        # for recordFile' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                       location /recordFile {' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                root           /var/www/web-v2/;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\                fastcgi_index  index.php;' $NGINX_CONF
        sed -i '/ # MP3 file is not in the wb root dir/i\\                rewrite /recordFile/(.*) /service/index.php?m=common&c=recordFile&f=$1 last;'     $NGINX_CONF
                sed -i '/ # MP3 file is not in the wb root dir/i\        }'     $NGINX_CONF
fi

}

#CloudCC版本


PKG=(V5.0.9 V5.0.9.1 V5.0.11 V5.0.12)


#Project版本 
PKG2=(V1.0.40 V1.0.41 V1.0.41.1 V1.0.42 V1.0.42.1 V1.0.42.2 V1.0.42.3 V1.0.42.4 V1.1.1 V1.1.2 V1.1.2.1 V1.1.2.2 V1.1.3 V1.1.3.1 V1.1.3.2 V1.1.3.3 V1.1.4 V1.1.5 V1.1.5.1 V1.1.6 V1.1.6.1 V1.1.7 V1.1.8 V1.1.8.1 V1.1.9 V1.1.11 V1.1.12 V1.1.13 V1.1.14 V1.1.15 V1.1.21 V1.1.22 V1.1.23 V1.1.24 V1.1.25 V1.1.26 V1.1.27 V1.1.28 V1.1.29 V1.1.31 V1.1.32 V1.1.41 V1.1.42 V1.1.43 V1.1.44 V1.1.45)
#PKG2=(V1.0.10 V1.0.9 V1.0.11 V1.0.12 V1.0.13 V1.0.14 V1.0.15 V1.0.16 V1.0.18 V1.0.19 V1.0.21.1 V1.0.21.2 V1.0.22 V1.0.31 V1.0.32 V1.0.33 V1.0.33.1 V1.0.34 V1.0.34.1 V1.0.35 V1.0.36 V1.0.37 V1.0.38 V1.0.39 V1.0.39.1 V1.0.41 V1.0.41.1 V1.0.42 V1.0.42.1 V1.0.42.2 V1.0.42.3 V1.0.42.4 V1.1.1 V1.1.2 V1.1.2.1 V1.1.2.2 V1.1.2.3 V1.1.2.4 V1.1.2.5 V1.1.3 V1.1.3.1 V1.1.3.2 V1.1.3.3 V1.1.4 V1.1.5 V1.1.5.1 V1.1.6 V1.1.6.1 V1.1.7 V1.1.8 V1.1.8.1 V1.1.9 V1.1.11 V1.1.12 V1.1.13 V1.1.14 V1.1.15 V1.1.21 V1.1.22 V1.1.23 V1.1.24 V1.1.25 V1.1.26)
#BLA版本
PKG3=(V1.0.0 V1.0.1 V1.0.2)

#ApiProxy-new版本
PKG4=(V1.0.0 V1.0.1)

INSTALL_CLOUD () {
BACKUP_FS_SOUND
for I in ${PKG[*]};do
    echo "`date +'%F %H:%M:%S'` $I ">>/var/log/install_package.log
    cd /home/package
        if [ $I == V2.5.0 ] ;then
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./check.sh
                tar -xf l_ipp_7.1.1.117_intel64.tar.gz
                cd l_ipp_7.1.1.117_intel64
                ./install.sh
                cd ../
                ./install.sh
                echo "*********************Install $I finished...**************************"
                sleep 2
        else
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./install.sh
        if [ $? == 0 ];then
            echo "`date +'%F %H:%M:%S'` $I " >>/var/log/install_package.log
        else
            echo "`date +'%F %H:%M:%S'` $I Install fail..." >>/var/log/install_package.log
        fi
                echo "*********************Install $I finished...**************************"
                sleep 2
        fi
done
}

INSTALL_PROJECT () {
BACKUP_FS_SOUND
for I in ${PKG2[*]};do
    echo "`date +'%F %H:%M:%S'` $I ">>/var/log/install_package.log
        cd /home/package
        if [ $I == V1.0.10 ] ;then
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./check.sh
                tar -xf l_ipp_7.1.1.117_intel64.tar.gz
                cd l_ipp_7.1.1.117_intel64
                ./install.sh
                cd ../
                ./install.sh
                echo "*********************Install $I finished...**************************"
                sleep 2
        else
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./install.sh
        if [ $? == 0 ];then
            echo "`date +'%F %H:%M:%S'` $I " >>/var/log/install_package.log
        else
            echo "`date +'%F %H:%M:%S'` $I Install fail..." >>/var/log/install_package.log
        fi
                echo "*********************Install $I finished...**************************"
                sleep 2
        fi
done
}

INSTALL_BLA () {
scp root@ai.dipcc.com:/home/package/2.3/V2.5.*  /home/package
for I in ${PKG3[*]};do
    echo "`date +'%F %H:%M:%S'` $I ">>/var/log/install_package.log
        cd /home/package
        if [ $I == V1.0.0 ] ;then
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./check.sh
                ./install.sh
                echo "*********************Install $I finished...**************************"
                sleep 2
        else
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./install.sh
        if [ $? == 0 ];then
            echo "`date +'%F %H:%M:%S'` $I " >>/var/log/install_package.log
        else
            echo "`date +'%F %H:%M:%S'` $I Install fail..." >>/var/log/install_package.log
        fi
                echo "*********************Install $I finished...**************************"
                sleep 2
        fi
done
}

INSTALL_API-PROXY() {
for I in ${PKG4[*]};do
    echo "`date +'%F %H:%M:%S'` $I ">>/var/log/install_package.log
        cd /home/package
        if [ $I == V1.0.0 ] ;then
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./install.sh
                echo "*********************Install $I finished...**************************"
                sleep 2
        else
                tar -xf $I-BIN.tar.gz
                cd $I/BIN
                ./install.sh
        if [ $? == 0 ];then
            echo "`date +'%F %H:%M:%S'` $I " >>/var/log/install_package.log
        else
            echo "`date +'%F %H:%M:%S'` $I Install fail..." >>/var/log/install_package.log
        fi
                echo "*********************Install $I finished...**************************"
                sleep 2
        fi
done
}

RESTART_SERVICE () {
/etc/init.d/ipccd restart
/etc/init.d/php-fpm restart
/etc/init.d/freeswitch restart
/etc/init.d/mysql restart
}

RM_PACKAGE () {
        if [ -d /home/package ];then
                rm -rf /home/package/*
        fi
}

BACKUP_CORE_MODULE () {
    if [ ! -d /home/backup ];then
        mkdir /home/backup
    fi

    date=`date +'%F_%H:%M:%S'`
    if [ -f /ipcc/bin/scd ];then
        tar zcf /home/backup/scd-${date}.tar.gz /ipcc/bin/scd
    fi

}


UPDATE_CLOUD () {
echo "NONE"
exit 0
}

case $CHOICE in 
1)
    BACKUP_CORE_MODULE
        INSTALL_CLOUD
        CHECK_CONF
        RESTART_SERVICE
        RM_PACKAGE
        ;;
2)
    BACKUP_CORE_MODULE
        INSTALL_PROJECT
        CHECK_CONF
        RESTART_SERVICE
        RM_PACKAGE
        ;;
3)
        INSTALL_BLA
        BLA_CONF
        RESTART_SERVICE
        #RM_PACKAGE
        ;;
4)
        INSTALL_API-PROXY
        CHECK_CONF
        RESTART_SERVICE
        RM_PACKAGE
        ;;
*)
        echo "Please Input 1 2 or 3"
        ;;
esac
