diff options
author | Jonas Smedegaard <dr@jones.dk> | 2004-08-05 19:14:58 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2004-08-05 19:14:58 +0000 |
commit | 6a008e282c4804d51b3d5fb4f812b6aa77613b23 (patch) | |
tree | 37d29d2cd3e3519231d5311c8e457a2f22954a33 | |
parent | 890f2daa3ce1482427514f0b29bc4fd66a66cde4 (diff) |
Complete rewrite...
-rwxr-xr-x | savelocaltweaks | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/savelocaltweaks b/savelocaltweaks index 7471765..7f2c84d 100755 --- a/savelocaltweaks +++ b/savelocaltweaks @@ -1,52 +1,59 @@ #!/bin/sh -set -e +#set -e -targetdir=/tmp/localtweaks +basedir="/etc" +targetdir="/tmp/localtweaks" + +for ext in .orig .old; do + extfiles="`find $basedir -name \*$ext`" + for extfile in $extfiles; do + xextfile="${extfile%$ext}" + files="$files ${xextfile#$basedir}" + done +done -origfiles="`cd /etc && find . -name '*.orig'`" -oldfiles="`cd /etc && find . -name '*.old'`" includes="" excludes="" if [ -d /etc/local ]; then if [ -r /etc/local/localtweaks.include ]; then includes="`cat /etc/local/localtweaks.include`" + for include in $includes; do + files="$files ${include#$basedir}" + done fi if [ -r /etc/local/localtweaks.exclude ]; then - excludes="`cat /etc/local/localtweaks.exclude`" + xexcludes="`cat /etc/local/localtweaks.exclude`" + for exclude in $xexcludes; do + excludes="$excludes ${exclude#$basedir}" + done fi fi -files="$origfiles $oldfiles $includes" - -# process all *.{orig,old} once each +# process all files once each for file in `for x in $files; do echo $x; done | uniq | sort`; do - olddir="/etc/`dirname $file`" - newdir="$targetdir/`dirname $file`" - oldname="`basename $file`" - newname="`basename $file .orig`" + for exclude in $excludes; do - [ "$newname" = "$exclude" ] && continue 2 + [ "$file" = "$exclude" ] && continue 2 done - if [ ! -e $olddir/$newname.orig ]; then - newname="`basename $file .old`" - fi - if [ "$oldname" = "$newname" ]; then - echo "FATAL: file is neither .orig nor .old: \"$file\"!" - exit 1 - fi - if [ ! -e $olddir/$oldname ]; then - echo "FATAL: file found disappeared again: \"$file\"!" - exit 1 + + if [ -e $basedir/${file}.orig ]; then + ext=".orig" + elif [ -e $basedir/${file}.old ]; then + ext=".old" + else + ext="" fi + + newdir="$targetdir/$basedir/`dirname $file`" mkdir -p $newdir - cp -af $olddir/$newname $newdir - - # Only diff against non-empty files. - if [ -s $olddir/$oldname ]; then - diff -ruN $olddir/$oldname $olddir/$newname > $newdir/$newname.diff - chown --reference=$olddir/$newname $newdir/$newname.diff - chmod --reference=$olddir/$newname $newdir/$newname.diff - chmod a-x $newdir/$newname.diff + cp -af $basedir/$file $newdir + + # Only diff against existing and non-empty files. + if [ -n "$ext" ] && [ -s $basedir/$file$ext ]; then + diff -ruN $basedir/$file$ext $basedir/$file > $targetdir/$basedir/$file.diff + chown --reference=$basedir/$file $targetdir/$basedir/$file.diff + chmod --reference=$basedir/$file $targetdir/$basedir/$file.diff + chmod a-x $targetdir/$basedir/$file.diff fi done |