#!/bin/bash function GetKey(){ section=$(echo $1 | cut -d '.' -f 1) key=$(echo $1 | cut -d '.' -f 2) sed -n "/\[$section\]/,/\[.*\]/{ /^\[.*\]/d /^[ \t]*$/d /^$/d /^#.*$/d s/^[ \t]*$key[ \t]*=[ \t]*\(.*\)[ \t]*/\1/p }" rule } function GetInclude(){ sed -n "/\[$1\]/,/\[.*\]/{ /^\[.*\]/d /^[ \t]*$/d /^$/d /^#.*$/d s/^[ \t]*\(.*\)[ \t]*/\1/p }" rule } BACKUP_FOLDER=$(GetKey "base.dir_Test") OUT_FOLDER1=$(cd "$(dirname "$0")"; pwd)/Release/ OUT_FOLDER2=$(cd "$(dirname "$0")"; pwd)/Compare/ INCLUDE_PARAM="" EXCLUDE_PARAM="" HONBAN="" for ed in $(echo $(GetKey "exclude.dirs")|tr ':' ' '|tr -s ' ') do EXCLUDE_PARAM=$EXCLUDE_PARAM" -x "$ed done if [ "$#" -gt 0 ]; then if [ ! -z $(echo $1|grep "-") ]; then while getopts hix: OPTION do case $OPTION in i)for ed in $(cat rule |grep -v "exclude" | grep -v "base" |grep "\[\(.*\)\]" |tr '\n|\[\]' ' ') do for module in $(GetInclude $ed) do INCLUDE_PARAM=$INCLUDE_PARAM"\/"$ed"\/"$module"\/|" done done INCLUDE_PARAM=$(echo $INCLUDE_PARAM |sed "s/.$//");; h)BACKUP_FOLDER=$(GetKey "base.dir_HB"); HONBAN="TRUE"; OUT_FOLDER1=$(cd "$(dirname "$0")"; pwd)/Release_HB/;: OUT_FOLDER2=$(cd "$(dirname "$0")"; pwd)/Compare_HB/;; x)EXCLUDE_PARAM=$EXCLUDE_PARAM" -x "$OPTARG;; \?)echo "invalid parameter!" exit 1;; esac done shift $(($OPTIND - 1)) fi fi echo $INCLUDE_PARAM #echo "EXCLUDE_PARAM:"$EXCLUDE_PARAM echo "----------------------------------------------------------------------------------------------------------" shopt -s extglob if [ -d $OUT_FOLDER1 ]; then rm -rf $OUT_FOLDER1!(db-upgrade|*.sh|pmnwdl-inc) else mkdir -p $OUT_FOLDER1 fi if [ -d $OUT_FOLDER2 ]; then rm -rf $OUT_FOLDER2 mkdir -p $OUT_FOLDER2 else mkdir -p $OUT_FOLDER2 fi REL_FOLDER=$(echo $1 |sed "s/[\/]$//") TMP_FOLDER=$(echo $2 |sed "s/[\/]$//") if [ ! -z $REL_FOLDER ]; then if [ ! -z $(echo $REL_FOLDER|grep -E "^[0-9]+$") ]; then REL_FOLDER=$BACKUP_FOLDER$(ls -t $BACKUP_FOLDER | sort -r | grep $REL_FOLDER | head -n 1) fi else REL_FOLDER=$(ls -t $BACKUP_FOLDER | sort -r | grep $(date +%Y%m%d) | head -n 1) if [ -z $REL_FOLDER ]; then REL_FOLDER=$(ls -t $BACKUP_FOLDER | sort -r| head -n 1) fi REL_FOLDER=$BACKUP_FOLDER$REL_FOLDER fi if [ -z $2 ]; then CNOW=$(echo "$REL_FOLDER"|awk 'BEGIN{FS="/"} {print substr($5,0,8)}') #echo 'CNOW:'$CNOW TMP_FOLDER=$BACKUP_FOLDER$(ls $BACKUP_FOLDER |sort -r |awk -v cnow="$CNOW" '{for(i=1;i<=NF;i++) if(substr($i,0,8) < cnow ){ print $i;exit}}') fi echo "REL_FOLDER:"$REL_FOLDER echo "TMP_FOLDER:"$TMP_FOLDER echo "----------------------------------------------------------------------------------------------------------" if [ -d $REL_FOLDER -a -d $TMP_FOLDER ]; then if [ ! -z $(echo $REL_FOLDER|grep -E '^/home/basz/.*/[0-9]+$') -a ! -z $(echo $TMP_FOLDER|grep -E '^/home/basz/.*/[0-9]+$') ]; then for file in $(diff -x .svn $EXCLUDE_PARAM -qurN $REL_FOLDER $TMP_FOLDER |awk '{print $2 }') do if [ ! -z $INCLUDE_PARAM ]; then if [ -z $(echo $file | grep -E $INCLUDE_PARAM) ]; then continue fi fi if [ -f $file ]; then if [ -z $HONBAN ]; then BASEFOLDER=$(dirname $file|cut -d '/' -f 6-) FOLDER1=$OUT_FOLDER1$BASEFOLDER FOLDER2=$OUT_FOLDER2$BASEFOLDER if [ ! -d $FOLDER1 ]; then mkdir -p $FOLDER1 fi if [ ! -d $FOLDER2 ]; then mkdir -p $FOLDER2 fi cp -fp $file $FOLDER1/ echo $file file2=$TMP_FOLDER/$BASEFOLDER/$(basename $file) if [ -f $file2 ]; then #echo $file2 cp -fp $file2 $FOLDER2/ fi else BASEFOLDER=$(dirname $file|cut -d '/' -f 6-7) FOLDER1=$OUT_FOLDER1$BASEFOLDER FOLDER2=$OUT_FOLDER2$BASEFOLDER if [ ! -z $BASEFOLDER ]; then if [ ! -d $FOLDER1 ]; then echo $REL_FOLDER/$BASEFOLDER mkdir -p $FOLDER1 cp -rfp $REL_FOLDER/$BASEFOLDER/* $FOLDER1 fi fi fi fi done chown -R builder:builder $OUT_FOLDER1 chown -R builder:builder $OUT_FOLDER2 exit 0 fi fi echo 'invalid folder!'