check 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. source "/swcode/swcode.bash"
  3. rerunasroot "$@"
  4. #must use './' to differentiate in `grep -v` between the two dirs for filtering out those 'Only in' from '/'
  5. repodir="./OSes/archlinux/" #old
  6. rootdir="/" #new
  7. #by default 'new' (aka green color) is considered the current computer / dir, and the repo is considered old, unless you pass arg:
  8. if test "$1" == "swap" -o "$1" == "newinrepo"; then
  9. dir1="$rootdir" #old
  10. dir2="$repodir" #new
  11. #swapped=1
  12. shift 1
  13. else
  14. dir1="$repodir" #old
  15. dir2="$rootdir" #new
  16. #swapped=0
  17. fi
  18. cmd=(
  19. sudo diff --no-dereference -upr "$@" #-- "$dir1" "$dir2"
  20. )
  21. filterout_for1a() {
  22. local known1='File ./OSes/archlinux/home/user/.local/share/xorg is a directory while file /home/user/.local/share/xorg is a symbolic link'
  23. #^ this will always be like this due to saxing Xorg.0.log file from that xorg dir which points to /tmp and thus rsync makes it a dir! there's no other way!
  24. #TODO: need escaper function for the above text!
  25. grep -v "^${known1}$"
  26. }
  27. colorstuff_for1a() {
  28. sed -re 's/^((File|Symbolic links) .*)$/'"$(tput setab 3)$(tput setaf 0)"'\1'"$(tput sgr0)"'/g' | colordiff
  29. }
  30. #1. show only stdout first:
  31. #a. without 'Only in' lines:
  32. "${cmd[@]}" -- "$dir1" "$dir2" 2>/dev/null | grep -v '^Only in' | filterout_for1a | colorstuff_for1a | less -R
  33. #b. show only 'Only in' lines:
  34. #echo "!$hostname!"
  35. #exit 1
  36. "${cmd[@]}" -- "$dir1" "$dir2" 2>/dev/null | grep '^Only in' | grep -v '^Only in /' | grep -vE "\.hostspecific=(${hostname}|${z575hostname}|${t400hostname}|${intelhostname})" | grep -vE '^Only in '"${repodir%%/}"'/: (fstat(_.*)?\.lst|restore_for_host_.*|restore_fstat.bash|restor_hostspecific_files)$' | grep -vE 'COMPILE_TIME(_dual)?.host=' | grep -vE 'kernel-.*\.config\.removed.*due_to_.*\.backup'| less -R
  37. #^ ".hostspecific=${hostname}" can be part of a dir and not part of the file within that dir, hence no '$' (eol) after the hostname and no regex in the 'grep' command, to be able to match such cases!
  38. #XXX: ignoring some files that exist only in $repodir like restor_hostspecific_files and others like that!
  39. #doneTODO: show diff for all *.hostspecific=${hostname} files comparing them with their non-hostspecific-name counterparts from /
  40. tempscript="$(mktemp --dry-run --tmpdir="/tmp" -t -- "q1q_check_XXXXXXXXXX_$(date --iso-8601=ns|tr ':,+' '_')")"
  41. cat > "$tempscript" <<EOF
  42. #!/bin/bash
  43. #autogenerated by '$0' from pwd:'$(pwd)'
  44. #XXX: this should run as root or risk errors like this: diff: //root/.ssh/known_hosts: Permission denied
  45. #for now, caller is root, so it'll do
  46. if test "\$#" -gt "1"; then
  47. echo "!! Got '\$#' args but expected only 1, got: '\$*'"
  48. fi
  49. fn="\$1"
  50. sanefn="\$(echo "\$fn" | sed -re 's/^(.*)\.hostspecific='".*"'$/${rootdir//\//\\/}\/\1/g')"
  51. #TODO: in generator aka $0, for the sed above ^ cut last / from rootdir since we're unconditionally adding an / via sed above! this will avoid duplicating the / and being seen within diff
  52. #XXX warning: due to the way the following is called, it mixes files with dirs, so you shouldn't search for "^diff " within 'less' but instead search for '^\\+\\+\\+ /' (only one \\)
  53. colordiff --no-dereference -upr "${repodir%%/}/\$fn" "\$sanefn"
  54. EOF
  55. chmod a+x -- "$tempscript"
  56. #find should search only in repo, so depends on value of 'swapped'
  57. #if test "$swapped" -eq "1"; then
  58. # finddir="$dir2"
  59. #else
  60. # finddir="$dir1"
  61. #fi
  62. #XXX: we ignore swap in this case, else find will search the whole root filesystem and therefore will take ages and with lots of 'Only in'
  63. #Exclude a bunch of filenames like Xorg.0.log because comparison would need the one in / be stripped of timing at least!
  64. find "$repodir" -name '*.hostspecific='"${hostname}" -and -printf '%P\0'| grep --null-data -vE '^(home/user/.local/share/xorg/Xorg.0.log(.hostspecific='"${hostname}"')?)$' | xargs -P1 -0 --no-run-if-empty --exit "-I{}" -n1 -- "$tempscript" "{}" 2>&1 | less -R
  65. #exit 1
  66. #TODO: cleanup tempscript
  67. #FIXME: I should separately get the stderr from in the above $tempscript runs!
  68. #3. Show stderr separately because otherwise it intermixes with the stdout and makes searches inaccurate:
  69. "${cmd[@]}" -- "$dir1" "$dir2" 2>&1 1>/dev/null | less -R
  70. #4. now compare other hosts's hostspecific files with our current host's files eg. ./OSes/archlinux/etc/default/tlp.hostspecific=Z575 with //etc/default/tlp
  71. #this will show any changes done on other hosts that you might want done on this host too, when the files are already set/named as *.hostspecific=hostnamehere
  72. find "$repodir" -name '*.hostspecific=*' -and ! -name '*.hostspecific='"${hostname}" -and -printf '%P\0'| grep --null-data -vE '^(home/user/.local/share/xorg/Xorg.0.log(.hostspecific=.*)?|.*\.gitinfo.log.hostspecific=.*)$' | xargs -P1 -0 --no-run-if-empty --exit "-I{}" -n1 -- "$tempscript" "{}" 2>&1 | less -R
  73. #Note: errors like `diff: //etc/tmpfiles.d/i2c-pm.conf: No such file or directory` are to be ignored, this simply means some files aren't present on this host but they are on the other host(s)
  74. #XXX here search for ^\+\+\+ only! not for ^diff ! or you'll miss files!
  75. #XXX here also search for `^Binary ` to see binary files differences