プログラム発行時のCDN自動配置-shell


このプログラムの目的は、SVNディレクトリの下にあるCDNに公開する必要があるファイルを見つけ、ピクチャタイプのファイルを直接公開し、JS、CSSなどのファイルをYUI圧縮ツールで圧縮してからCDNに公開することです.
#    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にプッシュできます.