home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / maint / addmissing < prev    next >
Text File  |  1995-04-27  |  2KB  |  102 lines

  1. #! /bin/sh
  2. # addmissing - add missing articles to history
  3. # Has a SORTTMP hook for feeding in a "-T dir" option if sort's default
  4. # temporary directory is short of space.
  5. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  6. . ${NEWSCONFIG-/etc/news/bin/config}
  7.  
  8. PATH=$NEWSCTL/bin:$NEWSBIN/maint:$NEWSBIN:$NEWSPATH ; export PATH
  9. umask $NEWSUMASK
  10.  
  11. dbzrebuild=n
  12. verbose=n
  13. for o
  14. do
  15.     case "$o" in
  16.     -d)    dbzrebuild=y    ;;
  17.     -v)    verbose=y    ;;
  18.     *)    echo "Usage: $0 [-d] [-v]" >&2
  19.         exit 2
  20.         ;;
  21.     esac
  22. done
  23.  
  24. # get main lock for history examination, and lock out expire too
  25. lock LOCK $$ || exit 1
  26. status=1
  27. trap "unlock LOCK ; trap 0 ; exit \$status" 0 1 2 15
  28. if lock -o LOCKexpire $$
  29. then
  30.     trap "unlock LOCK LOCKexpire ; trap 0 ; exit \$status" 0 1 2 15
  31. else
  32.     echo "$0: expire is running, $0 aborted" >&2
  33.     exit
  34. fi
  35.  
  36. # note the time
  37. >/tmp/time$$
  38.  
  39. # put together a list of known filenames from history
  40. egrep '    .*    ' $NEWSCTL/history | sed 's/.*    //' | tr '. ' '/
  41. ' | egrep '/' | sort -u $SORTTMP >/tmp/hist$$
  42.  
  43. # release the main lock, temporarily
  44. trap "unlock LOCKexpire ; trap 0 ; exit \$status" 0 1 2 15
  45. unlock LOCK
  46.  
  47. # sweep the tree, ignoring things that arrive while we're working
  48. cd $NEWSARTS
  49. them=
  50. for f in `ls | egrep -v '\.|(^lost\+found$)'`
  51. do
  52.     if test -d $f/.
  53.     then
  54.         them="$them $f"
  55.     fi
  56. done
  57. find $them -type f -name '[0-9]*' ! -newer /tmp/time$$ -print |
  58.     sort $SORTTMP >/tmp/tree$$
  59.  
  60. # find missing files, and build history entries for them
  61. comm -13 /tmp/hist$$ /tmp/tree$$ | histinfo | sort $SORTTMP |
  62.     awk -f $NEWSBIN/maint/histdups |
  63.     sort $SORTTMP -t'    ' +1n >/tmp/new$$
  64.  
  65. # check for oddities
  66. if egrep '^<[^>]*@trash>    ' /tmp/new$$ >/dev/null
  67. then
  68.     echo "$0: (warning) empty/trash articles found, will expire at once" >&2
  69.     echo "$0:     (grep history file for '@trash' to see them)" >&2
  70. fi
  71.  
  72. # lock things up again and plug them in
  73. cd $NEWSCTL
  74. lock LOCK $$ || exit
  75. trap "unlock LOCK LOCKexpire ; trap 0 ; exit \$status" 0 1 2 15
  76. if test " $dbzrebuild" = " y"
  77. then
  78.     cat /tmp/new$$ >>history
  79.     dbz history
  80. else
  81.     dbz -a history /tmp/new$$
  82. fi
  83.  
  84. case "$verbose" in
  85. y)    n="`wc -l </tmp/new$$ | tr -d ' '`"
  86.     echo "$0: found $n articles missing from history:"
  87.     if test " $n" -lt 50
  88.     then
  89.         cat /tmp/new$$
  90.     else
  91.         sed 3q /tmp/new$$
  92.         echo
  93.         echo "..."
  94.         echo
  95.         tail -3 /tmp/new$$
  96.     fi
  97.     ;;
  98. esac
  99.  
  100. rm -f /tmp/hist$$ /tmp/tree$$ /tmp/new$$ /tmp/time$$
  101. status=0
  102.