From ec68dd670a2beff79116ac168c5ec4db5c4f391a Mon Sep 17 00:00:00 2001 From: wwccss Date: Mon, 23 Sep 2013 09:34:57 +0800 Subject: [PATCH 1/2] + add the syncext.sh. --- tools/syncext.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 tools/syncext.sh diff --git a/tools/syncext.sh b/tools/syncext.sh new file mode 100755 index 0000000000..cb9e531f96 --- /dev/null +++ b/tools/syncext.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# +# This shell is used to sync extension files. +# +# @author chunsheng wang +# @author yidong wang +# + +# Judge the params, must give $src and $dest. +if [ $# -lt 2 ]; then + echo './syncext.sh src dest' + exit 1 +fi + +# Judge inotifywait tool exists or not. +which inotifywait > /dev/null +if [ $? -ne 0 ]; then + echo 'No inotifywait. Please install inotify-tools, for debian or ubuntun run apt-get install inotify-tools.'; + exit 1 +fi + +# Get $src and $dest. +src=$1 +dest=$2 + +# Rsync when the shell load first. +rsync -aqP --exclude='*.svn' $src/ $dest +echo `date "+%H:%M:%S"` sync $src to $dest succssfully. + +# Watch the $src directory, and sync files to destination. +inotifywait -mrq --event create,modify,delete,move --format '%w %e %f' --exclude=".svn" $src |\ +while read watcher event file ; do + + # compute the $path2process. + path2process=$watcher$file + path2process=${path2process/$src/$dest} + + # Delete a file or a directory. + if [ "$event" == "DELETE" -o "$event" == "DELETE,ISDIR" ]; then + + # If delete a file, use rm -fr, directory, use rmdir for security. + if [ "$event" == "DELETE" ]; then + rm -fr $path2process + else + rmdir $path2process + fi + + echo `date "+%H:%M:%S"` $path2process deleted.; + + # If event is ngnored, continue. + elif [ "$event" == "IGNORED" ]; then + + continue + + # Sync files. + else + + echo `date "+%H:%M:%S"` $path2process copied. + rsync -aqP --exclude='*.svn' $src/ $dest + fi + +done From d00bfd3280f0425c13bef623363c54f68cddb883 Mon Sep 17 00:00:00 2001 From: wwccss Date: Mon, 23 Sep 2013 09:48:50 +0800 Subject: [PATCH 2/2] * fix the bug. --- tools/syncext.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/syncext.sh b/tools/syncext.sh index cb9e531f96..b73773d37e 100755 --- a/tools/syncext.sh +++ b/tools/syncext.sh @@ -20,11 +20,11 @@ if [ $? -ne 0 ]; then fi # Get $src and $dest. -src=$1 -dest=$2 +src=$1/ +dest=$2/ # Rsync when the shell load first. -rsync -aqP --exclude='*.svn' $src/ $dest +rsync -aqP --exclude='*.svn' $src $dest echo `date "+%H:%M:%S"` sync $src to $dest succssfully. # Watch the $src directory, and sync files to destination.