xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | BASEDIR=${TOPDIR_AP} |
| 4 | BASE_BAKEUP_DIR=${TOPDIR_AP}/../.tmp/base_backup |
| 5 | LAST_COPY_DIR=${TOPDIR_AP}/../.tmp/lastcopy |
| 6 | LAST_COPY_FILE_LIST=${TOPDIR_AP}/../.tmp/cleanfilelist |
| 7 | |
| 8 | function CleanDIR() |
| 9 | { |
| 10 | echo "===========>rm ${1##*/}<===========" |
| 11 | rm -fr $1/* |
| 12 | } |
| 13 | |
| 14 | function CopyDIR() |
| 15 | { |
| 16 | #echo -ne "${1##*../../../}\t\t\t\t\t\t${2##*../../../}" |
| 17 | |
| 18 | if [ ! -d $1 ];then |
| 19 | return |
| 20 | fi |
| 21 | |
| 22 | if [ ! -d $2 ];then |
| 23 | mkdir -p $2 |
| 24 | fi |
| 25 | |
| 26 | if [[ -d .tmp ]]; then |
| 27 | rm -fr ./.tmp/ |
| 28 | fi |
| 29 | |
| 30 | if [[ -d $1 ]]; then |
| 31 | if [[ "`ls -A $1 2>/dev/null`" = ".svn" || "`ls -A $1 2>/dev/null`" = "" ]]; then |
| 32 | echo -e "$1:\033[0;33;1mnothing done\033[0m" |
| 33 | else |
| 34 | mkdir -p .tmp || echo -e "1==>err\n" |
| 35 | cp -rp $1/* ./.tmp/ ||echo -e "2==>err\n" |
| 36 | find ./.tmp/ -type d -name '.svn' | xargs rm -fr |
| 37 | cp -rp ./.tmp/* $2/ || echo -e "3==>err\n" |
| 38 | # cd .tmp |
| 39 | # find . -type f -exec echo $2'/'{} \; >> ../.copyfilelist |
| 40 | # cd .. |
| 41 | rm -fr ./.tmp/ |
| 42 | echo -e "$1:\033[0;31;1mOK\033[0m" |
| 43 | fi |
| 44 | else |
| 45 | echo -e ":\033[0;33;1mNo such directory\033[0m" |
| 46 | fi |
| 47 | } |
| 48 | |
| 49 | function CopyFile() |
| 50 | { |
| 51 | echo "copy $1 to $2" |
| 52 | cp -p $1 $2 |
| 53 | # echo $2 >> .copyfilelist |
| 54 | } |
| 55 | |
| 56 | function DeleteLastCopy() |
| 57 | { |
| 58 | cd ${BASEDIR} |
| 59 | if [[ -f ${LAST_COPY_FILE_LIST} ]]; then |
| 60 | echo "Delete the last copied files" |
| 61 | cat ${LAST_COPY_FILE_LIST} | while read v2 |
| 62 | do |
| 63 | #patchdir=${v2%/*} |
| 64 | rm -f "$v2" |
| 65 | done |
| 66 | |
| 67 | rm -fr ${LAST_COPY_DIR}/* |
| 68 | rm -f ${LAST_COPY_FILE_LIST} |
| 69 | else |
| 70 | echo "first copy,${LAST_COPY_FILE_LIST} NOT EXIST and skip." |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | function RevertBase() |
| 75 | { |
| 76 | if [ -d $BASE_BAKEUP_DIR ];then |
| 77 | CopyDIR $BASE_BAKEUP_DIR $BASEDIR |
| 78 | rm -fr $BASE_BAKEUP_DIR/* |
| 79 | else |
| 80 | echo "no $BASE_BAKEUP_DIR and skip" |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | function ModeCopy() |
| 85 | { |
| 86 | ###########################1==>copy apps######################################## |
| 87 | #echo "===========>copy files<=============" |
| 88 | CopyDIR ${PRJ_PRODUCT_DIR}/src ${LAST_COPY_DIR} |
| 89 | } |
| 90 | |
| 91 | function BaseBackup() |
| 92 | { |
| 93 | mkdir -p ${BASE_BAKEUP_DIR} |
| 94 | cd ${LAST_COPY_DIR} && find ./ -type f > ${LAST_COPY_FILE_LIST} |
| 95 | cat ${LAST_COPY_FILE_LIST} | while read v2 |
| 96 | do |
| 97 | patchdir=${v2%/*} |
| 98 | if [ -f "${BASEDIR}/$v2" ]; then |
| 99 | mkdir -p ${BASE_BAKEUP_DIR}/$patchdir |
| 100 | cp "${BASEDIR}/$v2" "${BASE_BAKEUP_DIR}/$v2" |
| 101 | fi |
| 102 | done |
| 103 | } |
| 104 | |
| 105 | echo "[1/6]Check the last copied files" |
| 106 | DeleteLastCopy |
| 107 | |
| 108 | echo "[2/6]Revert the base files" |
| 109 | RevertBase |
| 110 | |
| 111 | echo "[3/6]copy to last_copy_dir" |
| 112 | ModeCopy |
| 113 | |
| 114 | echo "[4/6]Backup base files to backup_dir" |
| 115 | BaseBackup |
| 116 | |
| 117 | echo "[5/6]copy files to base_dir from last_copy_dir" |
| 118 | CopyDIR ${LAST_COPY_DIR} ${BASEDIR} |
| 119 | |
| 120 | echo "[6/6]${PRJ_NAME} files copy complete" |