home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / ctl / rmgroup < prev    next >
Text File  |  1994-11-27  |  3KB  |  120 lines

  1. #! /bin/sh
  2. # rmgroup group - delete group
  3. # subject to $NEWSCTL/controlperm:  four fields per line, first
  4. # a newsgroup pattern, second an author name (or "any"), third a set of
  5. # operations ("n" newgroup, "r" rmgroup), and fourth a set of
  6. # flags ("y" do it, "n" don't, "q" don't report at all, "v" include
  7. # entire control message in report) (default "nv").
  8.  
  9. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  10. . ${NEWSCONFIG-/etc/news/bin/config}
  11.  
  12. PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH; export PATH
  13. umask $NEWSUMASK
  14.  
  15. g="$1"
  16.  
  17. posting=/tmp/rp$$
  18. hdr=/tmp/rc$$
  19.  
  20. # get the full article, and its header, into files for inspection
  21. trap "rm -f $posting $hdr ; trap 0 ; exit 0" 0
  22. cat >$posting
  23. canonhdr $posting >$hdr
  24.  
  25. # who sent it?
  26. author="`egrep '^From:' $hdr | sed 's/^[^:]*: *//' `"
  27. authorid="`echo \"$author\" | sed '/.*<\(.*\)>.*/s//\1/
  28.                    /\([^ ][^ ]*\)  *(.*).*/s//\1/'`"
  29.  
  30. # was it approved?
  31. case "`egrep '^Approved:' $hdr`" in
  32. '')    reject=${reject-'no Approved header'}    ;;
  33. esac
  34.  
  35. # do we have the group?
  36. getg="\$1 == \"$g\" { print }"
  37. got="`awk \"$getg\" $NEWSCTL/active`"
  38. case "$got" in
  39. '')    exit 0        ;;    # silently ignore unknown groups
  40. esac
  41.  
  42. # consult control file, if present
  43. perms=$NEWSCTL/controlperm
  44. action=nv
  45. if test -r $perms
  46. then
  47.     newaction=`gngp -a -r "$g" $perms | awk '$3 ~ /r/' |
  48.         awk '$2 == "any" || $2 == "'"$authorid"'" { print $4 }' |
  49.         sed -n 1p`
  50.     case "$newaction" in
  51.     ?*)    action=$newaction    ;;
  52.     esac
  53. fi
  54. case "$action" in
  55. *n*)    reject=${reject-'controlperm file denies permission'}    ;;
  56. esac
  57.  
  58. # the verdict
  59. case "$reject" in
  60. ?*)    case "$action" in
  61.     *q*)    ;;
  62.     *)    (
  63.             echo "rmgroup: \`$author' tried"
  64.             echo "to remove newsgroup \`$g'."
  65.             echo "Request was refused:"
  66.             echo "    $reject"
  67.             echo "Use delgroup to do it by hand, if appropriate."
  68.             case "$action" in
  69.             *v*)    echo '==='
  70.                 cat $posting
  71.                 echo '==='
  72.                 ;;
  73.             esac
  74.         ) | report 'rejected rmgroup'
  75.         ;;
  76.     esac
  77.     exit
  78.     ;;
  79. esac
  80.  
  81. # do the job
  82. awk '$1 != "'"$g"'"' $NEWSCTL/active >$NEWSCTL/active.tmp
  83. new="`wc -l <$NEWSCTL/active.tmp`"
  84. new=`expr $new + 1`
  85. if test " $new" -ne `wc -l <$NEWSCTL/active`
  86. then
  87.     fail="active.tmp length is incorrect, something's wrong"
  88. elif mv $NEWSCTL/active.tmp $NEWSCTL/active
  89. then
  90.     awk '$1 != "'"$g"'"' $NEWSCTL/active.times >$NEWSCTL/active.times.t
  91.     mv $NEWSCTL/active.times.t $NEWSCTL/active.times
  92.     awk '$1 != "'"$g"'"' $NEWSCTL/newsgroups >$NEWSCTL/newsgroups.tmp
  93.     mv $NEWSCTL/newsgroups.tmp $NEWSCTL/newsgroups
  94.     echo "$g" | tr '.' '/' >>$NEWSCTL/dirs.tbd
  95. else
  96.     fail='cannot rename active.tmp to active'
  97. fi
  98.  
  99. # and report it, if appropriate
  100. case "$action" in
  101. *q*)    ;;
  102. *)    (
  103.         echo "$author said to"
  104.         echo "remove \`$g'."
  105.         case "$fail" in
  106.         '')    echo "This was done."    ;;
  107.         *)    echo "This failed:"
  108.             echo "    $fail"
  109.             ;;
  110.         esac
  111.         case "$action" in
  112.         *v*)    echo '==='
  113.             cat $posting
  114.             echo '==='
  115.             ;;
  116.         esac
  117.     ) | report "rmgroup $g"
  118.     ;;
  119. esac
  120.