check 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ok, for whatever reason this works(so no need to "sudo bash -i" below):
  19. #some from /home/user/.second.bashrc
  20. export GIT_PAGER=less
  21. export LESS='-+X -R -+S -+F -+E -I -M --shift 5'
  22. export LESS_TERMCAP_mb=$'\E[01;31m'
  23. export LESS_TERMCAP_md=$'\E[01;38;5;75m'
  24. export LESS_TERMCAP_me=$'\E[0m'
  25. export LESS_TERMCAP_se=$'\E[0m'
  26. export LESS_TERMCAP_so=$'\E[01;33m'
  27. export LESS_TERMCAP_ue=$'\E[0m'
  28. export LESS_TERMCAP_us=$'\E[04;38;5;200m'
  29. export PAGER=less
  30. echo "Search string for 'less':"
  31. echo "^(diff |File|\+\+\+|Binary file|Only in|diff: )"
  32. read -rp "press enter to continue"
  33. echo "processing..."
  34. cmd=(
  35. # "bash -i" makes this work(and thus 'less' will show nice linenumbers during 'diff'):
  36. #$ sudo bash -i -c 'echo $LESS'
  37. #-+X -R -+S -+F -+E -I -M --shift 5
  38. #ok so trying "sudo -i" instead of "bash -i":
  39. #sudo -i -- diff --no-dereference -upr "$@" #-- "$dir1" "$dir2"
  40. #^ didn't work at all!
  41. #sudo -- bash -i -c 'diff --no-dereference -upr "$@"' #-- "$dir1" "$dir2"
  42. #^fail!
  43. sudo -- diff --no-dereference -upr "$@" #-- "$dir1" "$dir2"
  44. #^ only one working!
  45. )
  46. filterout_for1a() {
  47. local known1='File ./OSes/archlinux/home/user/.local/share/xorg is a directory while file /home/user/.local/share/xorg is a symbolic link'
  48. #^ 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!
  49. #TODO: need escaper function for the above text!
  50. grep -v "^${known1}$"
  51. }
  52. colorstuff_for1a() {
  53. sed -re 's/^((File|Symbolic links) .*)$/'"$(tput setab 3)$(tput setaf 0)"'\1'"$(tput sgr0)"'/g' | colordiff
  54. }
  55. #1. show only stdout first:
  56. #a. without 'Only in' lines:
  57. "${cmd[@]}" -- "$dir1" "$dir2" 2>/dev/null | grep -v '^Only in' | filterout_for1a | colorstuff_for1a | less -R
  58. #b. show only 'Only in' lines:
  59. #echo "!$hostname!"
  60. #exit 1
  61. "${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
  62. #^ ".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!
  63. #XXX: ignoring some files that exist only in $repodir like restor_hostspecific_files and others like that!
  64. #doneTODO: show diff for all *.hostspecific=${hostname} files comparing them with their non-hostspecific-name counterparts from /
  65. tempscript="$(mktemp --dry-run --tmpdir="/tmp" -t -- "q1q_check_XXXXXXXXXX_$(date --iso-8601=ns|tr ':,+' '_')")"
  66. cat > "$tempscript" <<EOF
  67. #!/bin/bash
  68. #autogenerated by '$0' from pwd:'$(pwd)'
  69. #XXX: this should run as root or risk errors like this: diff: //root/.ssh/known_hosts: Permission denied
  70. #for now, caller is root, so it'll do
  71. if test "\$#" -gt "1"; then
  72. echo "!! Got '\$#' args but expected only 1, got: '\$*'"
  73. fi
  74. fn="\$1"
  75. sanefn="\$(echo "\$fn" | sed -re 's/^(.*)\.hostspecific='".*"'$/${rootdir//\//\\/}\/\1/g')"
  76. #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
  77. #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 \\)
  78. colordiff --no-dereference -upr "${repodir%%/}/\$fn" "\$sanefn"
  79. EOF
  80. chmod a+x -- "$tempscript"
  81. #find should search only in repo, so depends on value of 'swapped'
  82. #if test "$swapped" -eq "1"; then
  83. # finddir="$dir2"
  84. #else
  85. # finddir="$dir1"
  86. #fi
  87. #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'
  88. #Exclude a bunch of filenames like Xorg.0.log because comparison would need the one in / be stripped of timing at least!
  89. 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
  90. #exit 1
  91. #TODO: cleanup tempscript
  92. #FIXME: I should separately get the stderr from in the above $tempscript runs!
  93. #3. Show stderr separately because otherwise it intermixes with the stdout and makes searches inaccurate:
  94. "${cmd[@]}" -- "$dir1" "$dir2" 2>&1 1>/dev/null | less -R
  95. #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
  96. #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
  97. 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
  98. #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)
  99. #XXX here search for ^\+\+\+ only! not for ^diff ! or you'll miss files!
  100. #XXX here also search for `^Binary ` to see binary files differences