cdn开启关闭功能脚本

cdn开启关闭功能脚本

cat cdn_open_close.sh 
#!/bin/bash
# Author: royoy
# Ver   : v3
# Date  : 07/2019
# LMod  : 10/2019
# Desc  : open&close cdn for xxxtyt
# Usage : ./script_name [ open_cdn|close_cdn ]

conf_php="/var/cache/salt/master/minions/web-1-xxxtyt.production/files/data/xxxtyt/config/var.php"
cdn_opt="${1:?Usage : ./script_name [ open_cdn|close_cdn ]}"

# Check if conf_php file exsits
if [ ! -s "$conf_php" ];then echo "$conf_php file not exsit or is null";exit 23;fi
reg="${2:-`sed -n '/domain_static/{p;q}' $conf_php |grep -Po '(?<=https:\/\/)[^\/]+'`}"

manage_cdn(){
        [ "x$1" = "xopen_cdn" ] && {
                if [ -n "$2" ];then
                        sed -i '0,/domain_static/s@\(https://\).*\(/\)@\1'$reg'\2@' $conf_php || exit 12
                fi
                sed -i -r '/.*domain_static.*'$reg'.*/{s@^[ |/|\t]*[/|\t| ]*@\t@;/.*domain_static.*'$reg'.*/s/0/1/}' $conf_php && font -d "Open CDN\t" -green "OK" -r -n || exit 13
        } || {
                if [ -n "$2" ];then
                        sed -i '0,/domain_static/s@\(https://\).*\(/\)@\1'$reg'\2@' $conf_php || exit 14
                fi
                sed -i '/.*domain_static.*'$reg'/s@^@//&@;/.*domain_static.*'$reg'/s/1/0/' $conf_php && font -d "Close CDN\t" -green "OK" -reset -n || exit 15
        }
}

[[ "open_cdn close_cdn" =~ "$cdn_opt" ]] && manage_cdn "$cdn_opt" "$2"