# $Id$
# $URL$
-if [ ! -x /usr/local/bin/date ] ; then
- echo "/usr/local/bin/date existiert nicht!" >&2
- exit 10;
-fi
-
-echo "Sichere alle Dateien ..."
+# set -x
-if [ ! -d .old ] ; then
- echo "Erstelle Verzeichnis '.old' ..."
- mkdir .old || exit 2
+if [ -x /usr/local/bin/date ] ; then
+ DATE=/usr/local/bin/date
+elif [ -x /usr/local/gnu-bin/date ] ; then
+ DATE=/usr/local/gnu-bin/date
+else
+ echo "GNU-Date nicht gefunden!" >&2
+ exit 10;
fi
if [ "$#" = "0" ] ; then
- echo "Keine Dateien angegeben, verwende statt dessen '*'."
- FILES="*"
+ # echo "Keine Dateien angegeben, verwende statt dessen '.'."
+ FILES="."
else
- FILES=$@
+ FILES=$@
fi
+OLD_DIR=""
+
for f in $FILES ; do
- if [ -f $f ] ; then
- n=".old/$f.`/usr/local/bin/date -r $f '+%Y-%m-%d-%H-%M-%S'`"
- echo " - $f -> $n"
- cp -p $f $n
- fi
+ if [ -f $f ] ; then
+ if [ "$OLD_DIR" = "" ] ; then
+ if echo ${f} | grep "/" >/dev/null ; then
+ OLD_DIR=`echo ${f} | sed 's#/[^/]*$##'`/.old
+ else
+ OLD_DIR=.old
+ fi
+ # echo "Lege Old-Dir auf '${OLD_DIR}' fest."
+ fi
+ if [ ! -d $OLD_DIR ] ; then
+ echo "Erstelle Verzeichnis '${OLD_DIR}' ..."
+ mkdir ${OLD_DIR} || exit 2
+ fi
+ n="${OLD_DIR}/`basename ${f}`.`$DATE -r $f '+%Y-%m-%d-%H-%M-%S'`"
+ echo " - $f -> $n"
+ cp -p $f $n
+ elif [ -d $f ] ; then
+ if [ "${f}" = "." -o "${f}" = ".." ] ; then
+ # echo "Sichere Verzeichnis '${f}' ..."
+ LIST_PATTERN="${f}/.* ${f}/*"
+ LIST=""
+ for ff in $LIST_PATTERN ; do
+ if [ -f ${ff} ] ; then
+ LIST="$LIST ${ff}"
+ elif [ -d ${ff} ] ; then
+ DIRNAME=`basename ${ff}`
+ if [ "${DIRNAME}" != "." -a "${DIRNAME}" != ".." -a "${DIRNAME}" != ".old" ] ; then
+ LIST="$LIST ${ff}"
+ fi
+ fi
+ done
+ $0 $LIST
+ else
+ DIRNAME=`basename ${f}`
+ if [ "${DIRNAME}" != "." -a "${DIRNAME}" != ".." -a "${DIRNAME}" != ".old" ] ; then
+ echo "Sichere Verzeichnis '${f}' ..."
+ $0 ${f}/.* ${f}/*
+ fi
+ fi
+ fi
done
-
-