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

  1. #! /bin/sh
  2. # mergeactive - merge active data from another site into this site's
  3. #    active file, cautiously
  4. # mergeactive [-#] file ...
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/etc/news/bin/config}
  8.  
  9. PATH=$NEWSCTL/bin:$NEWSBIN/maint:$NEWSBIN:$NEWSPATH ; export PATH
  10. umask $NEWSUMASK
  11.  
  12. replace=y
  13. for dummy
  14. do
  15.     case "$1" in
  16.     '-#')    replace=n    ;;
  17.     --)    shift ; break    ;;
  18.     -*)    echo "$0: unknown option \`$1'" >&2 ; exit 2    ;;
  19.     *)    break        ;;
  20.     esac
  21.     shift
  22. done
  23.  
  24. cd $NEWSCTL
  25.  
  26. tmp=/tmp/am$$
  27. tmpb=/tmp/am$$b
  28. err=/tmp/am$$e
  29. locks=
  30. status=1
  31. trap 'rm -f $tmp $tmpb $err ; unlock $locks ; trap 0 ; exit $status' 0 1 2 15
  32.  
  33. # gather up the input
  34. cat $* >$tmp
  35.  
  36. # do some checking
  37. checkactive -i -q $tmp >$err 2>&1
  38. if test -s $err
  39. then
  40.     echo "$0: problems in input:" >&2
  41.     cat $err >&2
  42.     exit
  43. fi
  44.  
  45. # now we need to make sure things don't change underfoot...
  46. lock LOCK $$ 10 || exit
  47. locks=LOCK
  48.  
  49. # let's be paranoid...
  50. checkactive -q active >$err 2>&1
  51. if test -s $err
  52. then
  53.     echo "$0: problems in $NEWSCTL/active:" >&2
  54.     cat $err >&2
  55.     exit
  56. fi
  57.  
  58. # pick out the new ones
  59. awk '{ print $1, $4 }' $tmp | sort >$tmpb
  60. sort active | join -a2 - $tmpb | awk 'NF == 2' >$tmp
  61.  
  62. # and away we go...
  63. cp active active.tmp
  64. awk '{ print $1, "0000000000", "00001", $2 }' $tmp >>active.tmp
  65. cp active.times actimes.tmp
  66. me=${LOGNAME-${USER-unknown}}@`newshostname`
  67. now=`now`
  68. sed "s/ .*/ $now $me/" $tmp >>actimes.tmp
  69.  
  70. # should we proceed?
  71. if test " $replace" = " n"
  72. then
  73.     status=0
  74.     exit
  75. fi
  76.  
  77. # do the dirty deed
  78. mv active active.old || exit
  79. mv active.tmp active || exit
  80. mv active.times active.times.o && mv actimes.tmp active.times
  81.  
  82. # and add any necessary directories
  83. adddirs
  84.  
  85. # looks like it worked
  86. status=0
  87.