发布程序时候的CDN自动部署

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#该函数对CDN目录进行处理 
DEAL_CDN() { 
    cdnChangeLog=$fabuLog/changeLog.cdn 
    apacheNeedYuiFileList=$fabuLog/apacheNeedYuiFileList.cdn 
    cdnNeedYuiFileList=$fabuLog/cdnNeedYuiFileList.cdn 
    if [ ! -d $cdnSrc ] || [ `ls -A $cdnSrc | wc -l` -eq 0 ]; then { 
        IS_DIR $cdnSrc 
        cd $webSrc 
        find . -type f -name "*.js" -o -name "*.css" > $cdnChangeLog 
        cd - 
        excludefile=$fabuConf/exclude.cdn 
    } else { 
                #$webSrc为svn更新的包含图片、js、css等文件类型的目录 
                cd $webSrc 
                find . -type f -name "*.js" -o -name "*.css" | xargs stat -c '%n %Y' | sort -k1,1 > $apacheNeedYuiFileList 
                #$cdnSrc为最后使用rsync命令发布到CDN上去的目录,该目录和在线CDN目录除了排除文件以外是一致的 
                cd $cdnSrc 
                find . -type f -name "*.js" -o -name "*.css" | xargs stat -c '%n %Y' | sort -k1,1 > $cdnNeedYuiFileList 
                #处理修改,apacheNeedYuiFileList中时间戳大于cdnNeedYuiFileList时间戳的为需要处理修改的 
                join $apacheNeedYuiFileList $cdnNeedYuiFileList | awk '{if($2>$3)print $1}' > $cdnChangeLog 
                #处理增加,在apacheNeedYuiFileList中有的,但是在cdnNeedYuiFileList中没有的,为增加 
                while read line; 
                do 
                        namename=$(echo $line | awk '{print $1}') 
                        grep -q  $namename $cdnNeedYuiFileList 
                        if [ $? != 0 ];then 
                                echo $namename >> $cdnChangeLog 
                        fi 
                done < $apacheNeedYuiFileList 
                #处理删除,在cdnNeedYuiFileList中有的,但是在apacheNeedYuiFileList中没有的,为删除 
                cd $cdnSrc 
                while read line; 
                do 
                        namename=$(echo $line | awk '{print $1}') 
                        grep -q $namename $apacheNeedYuiFileList 
                        if [ $? != 0 ];then 
                                rm -f $namename 
                        fi 
                done < $cdnNeedYuiFileList 
        excludefile=$fabuConf/exclude.cdn 
    } 
    fi
    #$excludefile中会排除掉js、css文件
    rsync -av --del --exclude-from="$excludefile" $webSrc/ $cdnSrc > $fabuLog/getOringal.cdn
    for file in `cat $cdnChangeLog`; do
        dir=`dirname $file`
        IS_DIR $cdnSrc/$dir
        #使用enca为需要压缩的文件确定文件编码,对于不确定的编码类型不压缩
        lang_result=$(/usr/local/bin/enca -L zh $webSrc/$file)
        echo "$lang_result" | grep -Eq 'UTF-8|ASCII' && charset=UTF-8
        echo "$lang_result" | grep -Eq 'GB2312' && charset=GB2312
        charset=${charset:-unknown}
        if [ "$charset" == "unknown" ];then
                rsync -av $webSrc/$file $cdnSrc/$file
                continue
        fi
        $JAVA_HOME/bin/java \
        -jar $YUI_HOME/yuicompressor-2.4.7.jar \
        $webSrc/$file -o $cdnSrc/$file \
        --charset $charset
        unset charset
    done
}


处理完成后,使用rsync命令可以将$cdnSrc推到在线CDN