home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / bin / Pnews < prev    next >
Encoding:
Text File  |  1995-05-14  |  12.4 KB  |  555 lines

  1. #!/bin/sh
  2. # $Id: Pnews.SH,v 3.0 1992/02/23 21:25:39 davison Trn $
  3. # This software is Copyright 1991 by Stan Barber. 
  4. #
  5. # Permission is hereby granted to copy, reproduce, redistribute or otherwise
  6. # use this software as long as: there is no monetary profit gained
  7. # specifically from the use or reproduction of this software, it is not
  8. # sold, rented, traded or otherwise marketed, and this copyright notice is
  9. # included prominently in any copy made. 
  10. #
  11. # The author make no claims as to the fitness or correctness of this software
  12. # for any use whatsoever, and it is provided as is. Any use of this software
  13. # is at the user's own risk. 
  14. #
  15. # syntax: Pnews -h headerfile            or
  16. #      Pnews -h headerfile oldarticle    or
  17. #         Pnews newsgroup title            or just
  18. #         Pnews
  19.  
  20. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  21.  
  22. # System dependencies
  23.  
  24. mailer="${RNMAILER-/usr/sbin/sendmail}"
  25. # if you change this to something that does signatures, take out signature code
  26.  
  27. case undef in
  28. define)
  29.     # where recordings and distributions are kept
  30.     lib=`/usr/lib/trn/filexp /tmp`
  31.     # where important rn things are kept
  32.     rnlib=`/usr/lib/trn/filexp /usr/lib/trn`
  33.     artcheck=trn-artchk
  34.     nntplist=nntplist
  35.     ;;
  36. undef)
  37.     # where recordings and distributions are kept
  38.     lib="/tmp"
  39.     # where important rn things are kept
  40.     rnlib="/usr/lib/trn"
  41.     artcheck=/usr/bin/trn-artchk
  42.     nntplist=/usr/bin/nntplist
  43.     ;;
  44. esac
  45.  
  46. # your organization name
  47. orgname="/etc/origanization"
  48. # what pager you use--if you have kernal paging use cat
  49. pager="${PAGER-/bin/more}"
  50. # how you derive full names, bsd, usg, or other
  51. nametype="bsd"
  52. # default editor
  53. defeditor="/usr/bin/ue"
  54. # how not to echo with newline
  55. n=""
  56. c="\c"
  57.  
  58. # You should also look at the distribution warnings below marked !DIST!
  59. # to make sure any distribution regions you are a member of are included.
  60. # The following are some prototypical distribution groups.  If you do not
  61. # use them all set the unused ones to a non-null string such as 'none'.
  62. loc="none"
  63. org="none"
  64. multistate="none"
  65. city="none"
  66. state="none"
  67. cntry="none"
  68. cont="none"
  69.  
  70. active=none
  71. test=test
  72. sed=/usr/bin/sed
  73. echo=/bin/echo
  74. cat=/bin/cat
  75. egrep=/usr/bin/egrep
  76. grep=/usr/bin/grep
  77. tr=/usr/bin/tr
  78. inews=inews
  79. cp=/bin/cp
  80. sleep=/usr/bin/sleep
  81. rm=/bin/rm
  82. who=
  83. mv=/bin/mv
  84.  
  85. nidump=
  86. ypmatch=
  87.  
  88. orgname=${NEWSORG-${ORGANIZATION-$orgname}}
  89. homedir=${HOME-$LOGDIR}
  90. dotdir=${DOTDIR-$homedir}
  91. tmpart=$dotdir/.article
  92. speller=$rnlib/Speller
  93.  
  94. tmp="${TMPDIR-/tmp}"
  95. newsgroups=${NEWSGROUPS-$lib/newsgroups}
  96. active=${NEWSACTIVE-$active}
  97. case "$active" in
  98. none) active="$tmp/Pnact.$$";;
  99. esac
  100. news_sig=${NEWSSIGNATURE-$dotdir/.news_sig}
  101.  
  102. case "$NETSPEED" in
  103. fast)
  104.     if $test ! -f "$newsgroups"; then
  105.     newsgroups="$tmp/Pnng.$$";
  106.     rmlist="$newsgroups";
  107.     cmdlist="$nntplist -o $newsgroups newsgroups ;";
  108.     fi
  109.     if $test ! -f "$active"; then
  110.     active="$tmp/Pnact.$$";
  111.     rmlist="$rmlist $active";
  112.     cmdlist="$cmdlist $nntplist -o $active active";
  113.     fi
  114.     ;;
  115. esac
  116.  
  117. if $test -f $dotdir/.pnewsexpert; then
  118.     expertise=expert
  119. else
  120.     $cat <<'EOM'
  121. I see you've never used this version of Pnews before.  I will give you extra
  122. help this first time through, but then you must remember what you learned.
  123. If you don't understand any question, type h and a CR (carriage return) for
  124. help.
  125.  
  126. If you've never posted an article to the net before, it is HIGHLY recommended
  127. that you read the netiquette document found in news.announce.newusers so
  128. that you'll know to avoid the commonest blunders.  To do that, interrupt
  129. Pnews, get to the top-level prompt of [t]rn, and use the command
  130. "g news.announce.newusers" to go to that group.
  131.  
  132. EOM
  133.     expertise=beginner
  134. fi
  135.  
  136. case $cntry in
  137.   can) Stpr=Province ; stpr=province ;;
  138.   *)   Stpr=State ; stpr=state ;;
  139. esac
  140.  
  141. case $multistate in
  142.   pnw) multistpr="Pacific NorthWest" ;;
  143.   *)   multistpr="Multi-State Area" ;;
  144. esac
  145.  
  146. headerfile=""
  147. case $# in
  148. 0) ;;
  149. *)  case $1 in
  150.     -h)
  151.     headerfile="$2"
  152.     shift
  153.     shift
  154.     case $# in
  155.     0)
  156.         oldart=""
  157.         ;;
  158.     *)
  159.         oldart="$1"
  160.         shift
  161.         ;;
  162.     esac
  163.     ;;
  164.     esac
  165.     ;;
  166. esac
  167.  
  168. case $headerfile in
  169. '')
  170.     . $rnlib/Pnews.header
  171.     ;;
  172. *)
  173.     $cat < $headerfile  > $tmpart
  174.     ;;
  175. esac
  176.     rescue="$sleep 1; $cat $tmpart >>${HOME-$LOGDIR}/dead.article ; $rm -f $rmlist ; $echo Article appended to ${HOME-$LOGDIR}/dead.article ; exit"
  177.     if $test -n "$rmlist" ; then
  178.     trap "$rm -f $rmlist" 0
  179.     fi
  180.     trap "trap : 1; $rescue" 1
  181.     trap "$rescue" 2
  182.  
  183. $echo ""
  184.  
  185. # extract the newsgroups list and distribution
  186. hdr_newsgroups=`$sed -n -e '/^Newsgroups:/{' -e 's///' -e 's/,/ /g' -e p -e q -e '}' $tmpart`
  187. hdr_distribution=`$sed -n -e '/^Distribution:/{' -e 's///' -e p -e q -e '}' $tmpart`
  188.  
  189. # check for "poster" magic cookie.  Allow erroneous user@site too.
  190. flag=0
  191. for ng in $hdr_newsgroups ; do
  192.     case "$ng" in
  193.     poster)    flag=1 ;;
  194.     *@*) flag=1 ;;
  195.     *)    ;;
  196.     esac
  197. done
  198. case $flag in
  199. 1)
  200.     $cat <<'EOM'
  201.  
  202. The original author has requested that messages be sent back via mail
  203. rather than posting to news.  Do you want to jump out of this and
  204. EOM
  205.     $echo $n "mail your reply instead? [yn] $c"
  206.     read ans
  207.     case $ans in
  208.     n*) tweak="$tmp/Pntwk.$$"
  209.         $sed '1,/^[     ]*$/{/^Newsgroups:/d;
  210.         s/^X-ORIGINAL-NEWSGROUPS:/Newsgroups:/;}' $tmpart >$tweak
  211.         $cp $tweak $tmpart
  212.         $rm -f $tweak
  213.         ;;
  214.     *)  exit ;;
  215.     esac
  216.     $echo " "
  217.     $echo "The Cc: line should have the poster's requested return address."
  218.     ;;
  219. esac
  220.   
  221. # play recorded message
  222. if $test -s ${lib}/recording ; then
  223.      for ng in $hdr_newsgroups ; do
  224.     _rec1=${lib}/`$sed -n "/^$ng/s/^.*    //p" ${lib}/recording`
  225.     _tmp=`$echo $ng |$sed "s/\..*//"`
  226.     _rec2=${lib}/`$cat -s ${lib}/recording|$grep ${_tmp}.all|$sed "s/^.*    //"`
  227.     if $test -f ${_rec1} ; then
  228.         $cat -s ${_rec1}
  229.     fi
  230.     if $test -f ${_rec2} ; then
  231.         $cat -s ${_rec2}
  232.     fi
  233.     done
  234. fi
  235.  
  236. # determine the distribution of this message
  237. set X $hdr_distribution
  238. shift
  239. if $test $# -gt 0 ; then
  240.     dist=$1.whatever
  241. else
  242.     set X $hdr_newsgroups
  243.     shift
  244.     if $test $# -gt 0 ; then
  245.     dist=$1.whatever
  246.     else
  247.     dist=misc.whatever
  248.     fi
  249. fi
  250. case $dist in
  251. *.*)
  252.     ;;
  253. *)
  254.     dist=$dist.whatever
  255.     ;;
  256. esac
  257.  
  258. case "$FAST_PNEWS" in
  259. y*) ;;
  260. *)
  261. # tell them what we think they are doing... !DIST!
  262. case $dist in
  263. world.*|comp.*|news.*|sci.*|rec.*|misc.*|soc.*|talk.*|alt.*|'')
  264.     $cat <<'EOM'
  265. This program posts news to thousands of machines throughout the entire
  266. civilized world.  Your message will cost the net hundreds if not thousands of
  267. dollars to send everywhere.  Please be sure you know what you are doing.
  268.  
  269. EOM
  270.     ;;
  271. vmsnet.*)
  272.     $echo 'This program posts news to many machines.'
  273.     ;;
  274. bit.*)
  275.     $echo 'This program posts news to many machines on BITNET.'
  276.     ;;
  277. ddn.*)
  278.     $echo 'This program posts news to many machines throughout the internet.'
  279.     ;;
  280. $cont.*)
  281.     $echo 'This program posts news to many machines throughout the continent.'
  282.     ;;
  283. $cntry.*)
  284.     $echo 'This program posts news to many machines throughout the country.'
  285.     ;;
  286. $multistate.*)
  287.     $echo "This program posts news to many machines throughout the ${multistpr}."
  288.     ;;
  289. $state.*)
  290.     $echo "This program posts news to many machines throughout the ${stpr}."
  291.     ;;
  292. $city.*)
  293.     $echo 'This program posts news to many machines throughout the city.'
  294.     ;;
  295. $org.*)
  296.     $echo 'This program posts news to machines throughout the organization.'
  297.     ;;
  298. $loc.*)
  299.     $echo 'This program posts news to machines throughout the local organization.'
  300.     ;;
  301. *.*)
  302.     $echo 'This program may post news to many machines.'
  303.     ;;
  304. to.*)
  305.     $echo 'This program may post news to a particular machine.'
  306.     ;;
  307. *)
  308.     $echo 'This program posts news to everyone on the machine.'
  309.     ;;
  310. esac
  311. ans=""
  312. while $test "X$ans" = X ; do
  313.     $echo $n "Are you absolutely sure that you want to do this? [ny] $c"
  314.     read ans
  315.     case $ans in
  316.     y*) ;;
  317.     f*) ;;
  318.     h*) $cat <<'EOH'
  319.  
  320. Type n or CR to exit, y to post.
  321.  
  322. EOH
  323.     ans="" ;;
  324.     *) exit ;;
  325.     esac
  326. done
  327. ;;
  328. esac
  329.  
  330. # run nntplist in the background, if necessary
  331. if $test -n "$cmdlist"; then
  332.     ( eval $cmdlist ) >/dev/null 2>&1 &
  333. fi
  334.  
  335. case "$FAST_PNEWS" in
  336. y*) file=''
  337.     $echo "" >> $tmpart
  338.     state=edit
  339.     ;;
  340. *)  file=h;;
  341. esac
  342. while $test "X$file" = Xh ; do
  343.     $echo ""
  344.     $echo $n "Prepared file to include [none]: $c"
  345.     read file
  346.     case $file in
  347.     h)
  348.     $cat <<'EOH'
  349.  
  350. If you have already produced the body of your article, type the filename
  351. for it here.  If you just want to proceed directly to the editor, type a
  352. RETURN.  In any event, you will be allowed to edit as many times as you
  353. want before you send off the article.
  354. EOH
  355.     ;;
  356.     '')
  357.     $echo "" >> $tmpart
  358.     state=edit
  359.     ;;
  360.     *)
  361.     $cat $file >>$tmpart
  362.     state=check
  363.     ;;
  364.     esac
  365. done
  366.  
  367. $echo ""
  368.  
  369. if $test -r $news_sig; then
  370.     $echo "-- " >> $tmpart
  371.     $sed 4q $news_sig >> $tmpart
  372. fi
  373.  
  374. while : ; do
  375.     case $state in
  376.     edit)
  377.     case $expertise in
  378.     beginner)
  379.         $cat </dev/null >$dotdir/.pnewsexpert
  380.         $cat <<'EOMessage'
  381. A temporary file has been created for you to edit.  Be sure to leave at
  382. least one blank line between the header and the body of your message.
  383. (And until a certain bug is fixed all over the net, don't start the body of
  384. your message with any indentation, or it may get eaten.)
  385.  
  386. Within the header may be fields that you don't understand.  If you don't
  387. understand a field (or even if you do), you can simply leave it blank, and
  388. it will go away when the article is posted.
  389.  
  390. Type return to get the default editor, or type the name of your favorite
  391. editor.
  392.  
  393. EOMessage
  394.         ;;
  395.     esac
  396.     case "${VISUAL-${EDITOR-}}" in
  397.     '')
  398.         tmp=h
  399.         ;;
  400.     *)
  401.         tmp=''
  402.         ;;
  403.     esac
  404.     while $test "X$tmp" = Xh ; do
  405.         $echo $n "Editor [${VISUAL-${EDITOR-$defeditor}}]: $c"
  406.         read tmp
  407.         case $tmp in
  408.         h)
  409.         $cat <<'EOH'
  410.  
  411. Type a return to get the default editor, or type the name of the editor you
  412. prefer.  The default editor depends on the VISUAL and EDITOR environment
  413. variables.
  414.  
  415. EOH
  416.         ;;
  417.         '')
  418.         ;;
  419.         *)
  420.         VISUAL=$tmp
  421.         export VISUAL
  422.         ;;
  423.         esac
  424.     done
  425.     trap : 2
  426.     ${VISUAL-${EDITOR-$defeditor}} $tmpart $oldart
  427.     trap "$rescue" 2
  428.     state=check
  429.     ;;
  430.     
  431.     check)
  432.     # wait for possible background nntplist
  433.     $test -n "$cmdlist" && wait
  434.  
  435.     # warn about long lines, malformed headers, misspelled newsgroups
  436.     ($artcheck $tmpart 79 $newsgroups $active) 2>/dev/null
  437.     state=ask
  438.     ;;
  439.  
  440.     ask)
  441.     $echo ""
  442.     $echo $n "Check spelling, Send, Abort, Edit, or List? $c"
  443.     read ans
  444.  
  445.     case "$ans" in
  446.     [aA]*)
  447.         state=rescue
  448.         ;;
  449.     [eE]*)
  450.         set $ans
  451.         case $# in
  452.         2)  VISUAL="$2" ;;
  453.         esac
  454.         state=edit
  455.         ;;
  456.     [lL]*)
  457.         $pager $tmpart
  458.         state=ask
  459.         ;;
  460.     [cC]*|[sS][pP]*)
  461.         $speller $tmpart
  462.         state=ask
  463.         ;;
  464.     [sS]*)
  465.         state=send
  466.         ;;
  467.     [hH]*)
  468.         $cat <<'EOH'
  469.  
  470. Type c to check the article's spelling, s to send the article, a to abort
  471. and append the article to dead.article, e to edit the article again, or l
  472. to list the article with your pager.
  473.  
  474. To invoke an alternate editor, type 'e editor'.
  475. EOH
  476.     esac
  477.     ;;
  478.     
  479.     send)
  480.     set X `$sed < $tmpart -n -e '/^Newsgroups: /{' -e p -e q -e '}'`
  481.     shift
  482.     case $# in
  483.     2)
  484.         state=cleanup
  485.         #posted_to="$2"
  486.         headerstrip='1,/^[     ]*$/{/^[A-Z][-A-Za-z0-9]*:[     ]*$/d;
  487.             /^X-ORIGINAL-NEWSGROUPS:/d;
  488.             /^[Cc][Cc]:/d;
  489.             /^Distribution: world/d;}'
  490.         if $sed "$headerstrip" $tmpart | $inews -h ; then
  491.             : null
  492.         else
  493.             state=ask
  494.         fi
  495.         cc=`$sed -n '1,/^[     ]*$/{/^[Cc][Cc]:[     ][^     ]/p;}' $tmpart|
  496.          $sed 's/^[Cc][Cc]:[     ][     ]*//'`
  497.         if $test "X$cc" != X ; then
  498.             case "$mailer" in
  499.             *recmail)    set X ;;
  500.             *sendmail)    set X -t ;;
  501.             *)        set X `echo $cc | $sed 's/,/ /g'` ;;
  502.             esac
  503.             shift
  504.             (#$echo "X-Also-Posted-To: $posted_to"
  505.              case "$mailer" in
  506.              *recmail|*sendmail) $echo To: $cc ;;
  507.              esac
  508.              $sed "$headerstrip" $tmpart
  509.              if $test -f $homedir/.signature; then
  510.             $echo "-- "
  511.             $cat $homedir/.signature
  512.              fi
  513.             ) | $mailer $@
  514.         fi
  515.         ;;
  516.     *)
  517.         $echo ""
  518.         $echo "Malformed Newsgroups line."
  519.         $echo ""
  520.         $sleep 1
  521.         state=edit
  522.         ;;
  523.     esac
  524.     ;;
  525.     rescue)
  526.     if $test -s $tmpart; then
  527.         $cat $tmpart >> ${HOME-$LOGDIR}/dead.article
  528.         $echo "Article appended to ${HOME-$LOGDIR}/dead.article"
  529.         $echo "A copy may be temporarily found in $tmpart"
  530.     else
  531.         $echo "Null article discarded."
  532.     fi
  533.     exit
  534.     ;;
  535.     cleanup)
  536.     case "${AUTHORCOPY-none}" in
  537.     none)
  538.         ;;
  539.     *)
  540.         set X ${USER-${LOGNAME-`$who am i`}} unknown
  541.         shift
  542.         $rnlib/mbox.saver $tmpart "." "." 0 0 Pnews $AUTHORCOPY "From $1 `LANG= date`"
  543.         if $test $? -eq 0 ; then
  544.         $echo "Article appended to $AUTHORCOPY"
  545.         else
  546.         $echo "Cannot append to $AUTHORCOPY"
  547.         fi
  548.         ;;
  549.     esac
  550.     exit
  551.     ;;
  552.     esac
  553. done
  554.