summaryrefslogtreecommitdiff
path: root/addons/x11infoscreen/usr/local/bin/savelocaltweaks
blob: b303cda5ca3ab6296154091406e30693ed04f4dc (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. for exclude in $excludes; do
  32. [ "$file" = "$exclude" ] && continue 2
  33. done
  34. ext=""
  35. for xext in $extensions; do
  36. if [ -e $basedir/$file$xext ]; then
  37. ext="$xext"
  38. continue
  39. fi
  40. done
  41. newdir="$targetdir/$basedir/`dirname $file`"
  42. mkdir -p $newdir
  43. cp -af $basedir/$file $newdir
  44. # Only diff against existing and non-empty files.
  45. if [ -n "$ext" ] && [ -s $basedir/$file$ext ]; then
  46. diff -ruN $basedir/$file$ext $basedir/$file > $targetdir/$basedir/$file.diff
  47. chown --reference=$basedir/$file $targetdir/$basedir/$file.diff
  48. chmod --reference=$basedir/$file $targetdir/$basedir/$file.diff
  49. chmod a-x $targetdir/$basedir/$file.diff
  50. fi
  51. done