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

  1. #! /bin/sh
  2. # pnews [prefix] - prepare user's article on stdin for posting via relaynews
  3. #    prefix is for tear; if given, output will also be in
  4. #    ${prefix}hdr & ${prefix}body
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/etc/news/bin/config}
  8.  
  9. PATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN:$NEWSPATH; export PATH
  10. prefix=/tmp/pn$$        # default prefix
  11. hdrs=/tmp/pn$$hdrs        # 1036-conformant headers
  12. rmlist="$inhdrs $inbody $hdrs"    # remove hdr & body files by default
  13.  
  14. umask $NEWSUMASK
  15.  
  16. # argument procesing
  17. case $# in
  18. 0)    ;;
  19. 1)
  20.     prefix="$1"
  21.     rmlist="$hdrs"        # only remove scratch file(s)
  22.     ;;
  23. *)
  24.     echo "usage: $0 [prefix]" >&2
  25.     exit 1
  26.     ;;
  27. esac
  28. inhdrs=${prefix}hdr        # generated by tear: headers
  29. inbody=${prefix}body        # generated by tear: body
  30.  
  31. # tear moved down into if because it might fail...
  32.  
  33. # generate new headers and bash old headers ** takes 2.1 seconds
  34.  
  35. # touch up headers & rewrite dates to make them 1036-compliant.
  36. # canonicalise header keyword capitalisation;
  37. # greps for Control: and Approved: later assume this, as does defhdrs.awk,
  38. # so $inhdrs needs to stick around and be canonicalised.
  39. if tear $prefix &&    # output in $inhdrs and $inbody ** takes 0.4 seconds
  40.     canonhdr -dm <$inhdrs >$hdrs    # dredge up defaults ** takes 0.1 secs
  41. then
  42.     # are we a client of a server?
  43.     if test -r $NEWSCTL/server
  44.     then
  45.         svr="`cat $NEWSCTL/server`"
  46.         me="`hostname`"
  47.         case "$me" in
  48.         $svr)    args=                ;;
  49.         *)    args="-c $me -s $svr"        ;;
  50.         esac
  51.     else
  52.         args=
  53.     fi
  54.  
  55.     # POLICY: msgid format; usg gcos?
  56.     # tailor: add -u for USG GCOS fields
  57.     eval ` defaults $args `        # sets def* variables
  58.     case "$defname" in
  59.     "")    fullname="" ;;        # no full name, leave it off
  60.     *)    fullname=" ($defname)" ;;
  61.     esac
  62.  
  63.     # badsites="pucc.bitnet!"  # tailor, syntax is "host1!host2!...host3!"
  64.     awk -f $NEWSBIN/inject/defhdrs.awk \
  65.      defpath="$badsites$defuser" \
  66.      deffrom="$defuser$defmailsuf$fullname" deforg="$deforg" \
  67.      defmsgid="$defmsgid" me="$defhostname" $hdrs >$inhdrs
  68.     status=$?
  69. else    status=1
  70. fi
  71.  
  72. # pad zero-line articles, since old B [ir]news are confused by them
  73. # and the news readers generate zero-line control messages, alas.
  74. if test ! -s $inbody; then
  75.     (echo '';
  76.      echo This article was probably generated by a buggy news reader.) \
  77.      >$inbody
  78. fi
  79.  
  80. # output begins here
  81. # POLICY: don't generate Lines: because it is optional, munged in transit
  82. # by B News to make the count incorrect, and not pulling its weight.
  83. # If you just *have* to generate Lines: headers, uncomment line A and comment
  84. # out line(s) B.
  85. firstline="` sed 1q $inbody `"
  86. # . lines                    # NB: reads $inbody # line A
  87. case "$firstline" in                # line B
  88. '')    cat $inhdrs $inbody ;;            # emit the article  # line B
  89. *)    echo | cat $inhdrs - $inbody ;;        # insert blank line # line B
  90. esac                        # line B
  91.  
  92. if test -r $HOME/.signature; then
  93.     # POLICY: chop .sigs at 4 lines
  94.     echo "-- "; sed 4q $HOME/.signature    # glue on first bit of signature
  95. fi
  96. rm -f $rmlist
  97. exit $status
  98.