該程序的目的是找到SVN目錄下的須要發佈到CDN上的文件,圖片類型文件直接發佈,JS、CSS等文件通過YUI壓縮工具壓縮以後再發布到CDN上。 css
#該函數對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