Index: filetraq
===================================================================
--- filetraq	(revisión: 616)
+++ filetraq	(copia de trabajo)
@@ -9,18 +9,31 @@
 
 # designed to be run periodically from any root's crontab, with output going in mail to root
 
-# scans /usr/local/filetraq/filetraq.conf unless given a different list
+# Defaults file
 
-file=/usr/local/filetraq/filetraq.conf
+defaults=/etc/default/filetraq
 
-# uses /usr/local/filetraq for backups unless given a different dir
+# scans /etc/filetraq.conf unless given a different list
 
-backupdir=/usr/local/filetraq/backups
+file=/etc/filetraq.conf
 
+# uses /var/lib/filetraq for backups unless given a different dir
+
+backupdir=/var/lib/filetraq
+
+# diff options
+diffopts="-p -C 1"
+# diff order
+difforder="newold"
+
+# Source defaults file if available
+test -f $defaults && . $defaults
+
 if [ "$1" != "" ]; then
 	if [ "$1" = "--help" ]; then
 		echo "FileTraq version 0.2"
 		echo "Syntax: $0 [filelist] [backupdir]";
+		echo "Defaults can be set in '/etc/default/filetraq'."
 		echo "If no filelist is specified, default is $file."
 		echo "If no backupdir is specified, default is $backupdir."
 		exit
@@ -40,28 +53,40 @@
 	backupdir=$2
 fi
 
-for entry in `cat $file | cut -d "#" -f 1`; do
-    for name in `find $entry -xtype f 2>&1`; do
-	if [ "$name" = "find:" ]; then
+# Exit quietly if there's no config file
+test -r "$file" || exit 0
+
+eval ls -1 `sed -n -e '/^[^#]/ { s/ /\\ /g; p; }' "$file"` 2> /dev/null | while read entry; do
+    find "$entry" -xtype f 2> /dev/null | while read name; do
+	if [ ! -e "$name" ]; then
 	    echo "File not found, or pattern didn't match any files: $entry"
 	    break
 	else
-	    backup=$backupdir/`echo $name \
-		| sed -e 's/^\/\(.*\)$/\1/' -e 's|/|\.|g'`
-	    if [ ! -e $backup ]; then
+	    bdir="$backupdir/`echo "$name"`"
+	    test -d "$bdir" || mkdir -p "$bdir"
+	    backup="$bdir/orig"
+	    if [ ! -e "$backup" ]; then
 		echo "Creating first backup of $name."
-		cp -af $name $backup
+		cp -pRLf "$name" "$backup"
 	    else
-		diff -p1 $name $backup
-		if [ $? = 1 ]; then
+		if [ "$difforder" = "oldnew" ]; then
+		  diff $diffopts "$backup" "$name"
+		else
+		  diff $diffopts "$name" "$backup"
+		fi
+		
+		ret=$?
+		if [ $ret = 1 ]; then
 		    # changes to save
-		    cp -af $backup $backup.`date +%m.%d.%y__%H.%M`
-		    cp -af $name $backup
+		    cp -pRLf "$backup" "$backup.`date +%m.%d.%y__%H.%M`"
+		    cp -pRLf "$name" "$backup"
 		fi
+		if [ $ret = 2 ]; then
+		    echo "Recording changes in binary file $name in backupdir"
+		    cp -pRLf "$backup" "$backup.`date +%m.%d.%y__%H.%M`"
+		    cp -pRLf "$name" "$backup"
+		fi
 	    fi
 	fi
     done
-    if [ "$ret" = "1" ]; then
-	echo "File not found: $entry"
-    fi
 done
