check_series.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. ERRORS=0
  3. if [ "$1" = "" ]
  4. then
  5. pushd . >/dev/null
  6. else
  7. echo Checking $1 ...
  8. pushd $1 >/dev/null
  9. fi
  10. if [ ! -f series ]
  11. then
  12. echo no series file found
  13. popd >/dev/null
  14. exit 1
  15. fi
  16. for i in *
  17. do
  18. if [ "$i" != "series" -a "$i" != "status" ]
  19. then
  20. j=`echo $i | sed -e 's@[A-Za-z0-9_.+-]@@g'`
  21. if [ "$j" != "" ]
  22. then
  23. echo illiegal character\(s\) \'$j\' in filename \'$i\'
  24. ERRORS=`expr $ERRORS + 1`
  25. fi
  26. j=`echo $i | sed -e 's@\.@\\\.@g'`
  27. COUNT=`grep ^$j$ series | wc | sed -e 's@^\s*@@g' -e 's@ .*$@@g'`
  28. if [ "$COUNT" != "1" ]
  29. then
  30. ERRORS=`expr $ERRORS + 1`
  31. echo $i appears $COUNT times in series
  32. fi
  33. # NUM=3
  34. NUM=`grep -n '^diff' $i | head -1 | sed -e 's@\:.*$@@'`
  35. if [ "$NUM" = "" ]
  36. then
  37. cp $i /tmp/cs$$
  38. else
  39. NUM=`expr $NUM - 1`
  40. head -$NUM $i > /tmp/cs$$
  41. fi
  42. if file /tmp/cs$$ | grep 'ISO-' >/dev/null
  43. then
  44. ERRORS=`expr $ERRORS + 1`
  45. echo non-ascii characters in $i
  46. fi
  47. rm /tmp/cs$$
  48. if head -1 $i | grep -v '^# HG changeset patch$' >/dev/null
  49. then
  50. ERRORS=`expr $ERRORS + 1`
  51. echo bad hg header in $i
  52. fi
  53. if ! head -3 $i | grep '^# User .*[@<].*[>A-Za-z0-9]$' >/dev/null
  54. then
  55. ERRORS=`expr $ERRORS + 1`
  56. echo bad hg header in $i
  57. fi
  58. if ! head -4 $i | grep '# Date .*[0-9]$' >/dev/null
  59. then
  60. ERRORS=`expr $ERRORS + 1`
  61. echo bad hg header in $i
  62. fi
  63. fi
  64. done
  65. for i in `cat series`
  66. do
  67. if [ ! -f $i ]
  68. then
  69. echo File $i in series does not exist.
  70. ERRORS=`expr $ERRORS + 1`
  71. echo $i
  72. fi
  73. done
  74. popd >/dev/null
  75. if [ "$ERRORS" = "0" ]
  76. then
  77. echo no errors detected
  78. exit 0
  79. else
  80. if [ "$ERRORS" = "1" ]
  81. then
  82. echo 1 error detected
  83. else
  84. echo $ERRORS errors detected
  85. fi
  86. fi
  87. exit 1