summaryrefslogtreecommitdiff
path: root/savelocaltweaks
blob: 601838c16c330dd3a9702c9cb9e9337632a1b6f3 (plain)
  1. #!/bin/sh
  2. targetdir=/tmp/localtweaks
  3. origfiles="`cd /etc && find . -name '*.orig'`"
  4. oldfiles="`cd /etc && find . -name '*.old'`"
  5. # merge all to only process once when both .orig and .old exist
  6. files="`echo $origfiles $oldfiles | tsort`"
  7. for file in $files; do
  8. olddir="/etc/`dirname $file`"
  9. newdir="$targetdir/`dirname $file`"
  10. oldname="`basename $file`"
  11. newname="`basename $file .orig`"
  12. if [ ! -e $olddir/$newname.orig ]; then
  13. newname="`basename $file .old`"
  14. fi
  15. if [ "$oldname" = "$newname" ]; then
  16. echo "FATAL: file is neither .orig nor .old: \"$file\"!"
  17. exit 1
  18. fi
  19. if [ ! -e $olddir/$oldname ]; then
  20. echo "FATAL: file found disappeared again: \"$file\"!"
  21. exit 1
  22. fi
  23. mkdir -p $newdir
  24. cp -af $olddir/$newname $newdir
  25. # Only diff against non-empty files.
  26. if [ -s $olddir/$oldname ]; then
  27. diff -ruN $olddir/$oldname $olddir/$newname > $newdir/$newname.diff
  28. chmod --reference=$olddir/$newname $newdir/$newname.diff
  29. chown --reference=$olddir/$newname $newdir/$newname.diff
  30. fi
  31. done