summaryrefslogtreecommitdiff
path: root/savelocaltweaks
blob: 96e9e0b8a6a21d6694e8fb4b017a5ca4e962d0ed (plain)
  1. #!/bin/sh
  2. #set -e
  3. basedir="/etc"
  4. targetdir="/tmp/localtweaks"
  5. includefile="/etc/local/localtweaks.include"
  6. excludefile="/etc/local/localtweaks.exclude"
  7. extensions=".orig .old"
  8. for ext in $extensions; do
  9. extfiles="`find $basedir -name \*$ext`"
  10. for extfile in $extfiles; do
  11. xextfile="${extfile%$ext}"
  12. files="$files ${xextfile#$basedir}"
  13. done
  14. done
  15. includes=""
  16. if [ -d "`dirname $includefile`" ] && [ -r $includefile ]; then
  17. includes="`cat $includefile`"
  18. for include in $includes; do
  19. files="$files ${include#$basedir}"
  20. done
  21. fi
  22. excludes=""
  23. if [ -d "`dirname $excludefile`" ] && [ -r $excludefile ]; then
  24. xexcludes="`cat $excludefile`"
  25. for exclude in $xexcludes; do
  26. excludes="$excludes ${exclude#$basedir}"
  27. done
  28. fi
  29. # process all files once each
  30. for file in `for x in $files; do echo $x; done | uniq | sort`; do
  31. # file were chosen based on backups - it may not exist itelf
  32. [ -s "$basedir/$file" ] || continue
  33. for exclude in $excludes; do
  34. [ "$file" = "$exclude" ] && continue 2
  35. done
  36. ext=""
  37. for xext in $extensions; do
  38. if [ -e $basedir/$file$xext ]; then
  39. ext="$xext"
  40. continue
  41. fi
  42. done
  43. newdir="$targetdir/$basedir/`dirname $file`"
  44. mkdir -p $newdir
  45. cp -af $basedir/$file $newdir
  46. # Only diff against existing and non-empty files.
  47. if [ -n "$ext" ] && [ -s $basedir/$file$ext ]; then
  48. diff -ruN $basedir/$file$ext $basedir/$file > $targetdir/$basedir/$file.diff
  49. chown --reference=$basedir/$file $targetdir/$basedir/$file.diff
  50. chmod --reference=$basedir/$file $targetdir/$basedir/$file.diff
  51. chmod a-x $targetdir/$basedir/$file.diff
  52. fi
  53. done