beautified scripts

This commit is contained in:
Axel Kittenberger 2010-08-03 15:03:42 +00:00
parent cf47587b9b
commit 3e8050172f
3 changed files with 41 additions and 34 deletions

View File

@ -1,13 +1,15 @@
#!/bin/bash #!/bin/bash
# test the case of directory being cp -r'ed and touched. lsyncd 1.0 doesn't handle this case well.
set -e set -e
CON="\E[47;34m" CON="\E[47;34m"
COFF="\033[0m" COFF="\033[0m"
echo -e "$CON***************************************************************$COFF"
echo -e "$CON** Testing the case of directory being cp -r'ed and touched. **$COFF"
echo -e "$CON** With default delay **$COFF"
echo -e "$CON***************************************************************$COFF"
WORKSOURCE=$(mktemp -d) WORKSOURCE=$(mktemp -d)
WORKSOURCE="/tmp/src" WORKTARGET=$(mktemp -d)
WORKTARGET="/tmp/trg"
PIDFILE=$(mktemp) PIDFILE=$(mktemp)
LOGFILE=$(mktemp) LOGFILE=$(mktemp)
@ -22,7 +24,7 @@ echo -e "$CON* waiting for lsyncd to start$COFF"
sleep 4s sleep 4s
# cp -r the directory # cp -r the directory
echo -e "$CON* make a lot of data$OFF" echo -e "$CON* making a lot of data$COFF"
for A in 1 2 3 4 5 6 7 8 9 10; do for A in 1 2 3 4 5 6 7 8 9 10; do
cp -r "${WORKSOURCE}"/a "${WORKSOURCE}"/b${A} cp -r "${WORKSOURCE}"/a "${WORKSOURCE}"/b${A}
echo 'test2' > "${WORKSOURCE}"/b${A}/a/another echo 'test2' > "${WORKSOURCE}"/b${A}/a/another
@ -35,7 +37,7 @@ for A in 1 2 3 4 5 6 7 8 9 10; do
done done
echo -e "$CON*waiting until lsyncd does the job.$COFF" echo -e "$CON*waiting until lsyncd does the job.$COFF"
sleep 60s sleep 20s
echo -e "$CON*killing lsyncd$COFF" echo -e "$CON*killing lsyncd$COFF"
LSYNCPID=$(cat "${PIDFILE}") LSYNCPID=$(cat "${PIDFILE}")
@ -54,7 +56,7 @@ sleep 1s
echo -e "$CON*differences$COFF" echo -e "$CON*differences$COFF"
diff -urN "${WORKSOURCE}" "${WORKTARGET}" diff -urN "${WORKSOURCE}" "${WORKTARGET}"
#rm "${PIDFILE}" rm "${PIDFILE}"
#rm "${LOGFILE}" rm "${LOGFILE}"
#rm -rf "${WORKTARGET}" rm -rf "${WORKTARGET}"
#rm -rf "${WORKSOURCE}" rm -rf "${WORKSOURCE}"

View File

@ -1,7 +1,11 @@
#!/bin/bash #!/bin/bash
# test the case of directory being mv'ed and rm'ed. lsyncd 1.0 didn't handle this case well.
set -e set -e
CON="\E[47;34m"
COFF="\033[0m"
echo -e "$CON************************************************************$COFF"
echo -e "$CON** Testing the case of directory being moved and removed. **$COFF"
echo -e "$CON************************************************************$COFF"
WORKSOURCE=$(mktemp -d) WORKSOURCE=$(mktemp -d)
WORKTARGET=$(mktemp -d) WORKTARGET=$(mktemp -d)
@ -12,34 +16,33 @@ echo $WORKSOURCE
echo $WORKTARGET echo $WORKTARGET
echo $PIDFILE echo $PIDFILE
# populate the filesystem. echo -e "$CON* populating the filesystem.$COFF"
mkdir "${WORKSOURCE}"/a mkdir "${WORKSOURCE}"/a
mkdir "${WORKSOURCE}"/b mkdir "${WORKSOURCE}"/b
touch "${WORKSOURCE}"/a/f touch "${WORKSOURCE}"/a/f
touch "${WORKSOURCE}"/b/g touch "${WORKSOURCE}"/b/g
echo ./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}" echo -e "$CON* starting lsyncd.$COFF"
./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}" ./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}"
LSYNCPID=$(cat "${PIDFILE}") LSYNCPID=$(cat "${PIDFILE}")
# try to wait until lsyncd starts and rsyncs initial file, hope 2s is enough. echo -e "$CON* waiting for lsyncd to start.$COFF"
sleep 2s sleep 4s
# move a file # move a file
echo "moving a directory" echo -e "$CON* moving a directory$COFF"
mv "${WORKSOURCE}"/a "${WORKSOURCE}"/c mv "${WORKSOURCE}"/a "${WORKSOURCE}"/c
echo "create a file there"
echo -e "$CON* creating a file there$COFF"
touch "${WORKSOURCE}"/c/h touch "${WORKSOURCE}"/c/h
echo "and delete a directory" echo -e "$CON* and deleting a directory$COFF"
#lsyncd 1.0 dies here
rm -r "${WORKSOURCE}"/b rm -r "${WORKSOURCE}"/b
echo "wait for events to trigger" echo -e "$CON* waiting for lsyncd to do the job.$COFF"
# try to wait until lsyncd does the job.
sleep 10s sleep 10s
echo "killing daemon"
echo -e "$CON* killing daemon$COFF"
if ! kill "${LSYNCPID}"; then if ! kill "${LSYNCPID}"; then
cat "${LOGFILE}" cat "${LOGFILE}"
diff -ur "${WORKSOURCE}" "${WORKTARGET}" || true diff -ur "${WORKSOURCE}" "${WORKTARGET}" || true
@ -48,14 +51,13 @@ if ! kill "${LSYNCPID}"; then
fi fi
sleep 1s sleep 1s
echo -e "$CON* log file contents$COFF"
echo "log file contents"
cat "${LOGFILE}" cat "${LOGFILE}"
#this should be grep.
echo -e "$CON* differences$COFF"
diff -ur "${WORKSOURCE}" "${WORKTARGET}" diff -ur "${WORKSOURCE}" "${WORKTARGET}"
#rm "${PIDFILE}" rm "${PIDFILE}"
#rm "${LOGFILE}" rm "${LOGFILE}"
#rm -rf "${WORKTARGET}" rm -rf "${WORKTARGET}"
#rm -rf "${WORKSOURCE}" rm -rf "${WORKSOURCE}"

View File

@ -1,11 +1,14 @@
#!/bin/bash #!/bin/bash
# copyright 2008 Junichi Uekawa <dancer@debian.org> # copyright 2008 Junichi Uekawa <dancer@debian.org>
# licensed under GPLv2 or later, see the file ../COPYING for details. # licensed under GPLv2 or later, see the file ../COPYING for details.
set -e
CON="\E[47;34m"
COFF="\033[0m"
# test that --help outputs help message and exit code of 0 echo -e "$CON*****************************************************************$COFF"
set -e echo -e "$CON* Testing that --help outputs help message and exit code of 0. **$COFF"
echo -e "$CON*****************************************************************$COFF"
set -o pipefail set -o pipefail
# assume that USAGE being in output is good enough. # assume that USAGE being in output is good enough.
./lsyncd --help | grep '^USAGE:'
./lsyncd --help | grep '^USAGE:'