home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / bsnews < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  11.5 KB

  1. From decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery Thu Aug  3 08:51:06 PDT 1989
  2. Article 991 of comp.sources.misc:
  3. Path: decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i099: bsnews - Bootstrap News
  7. Message-ID: <61162@uunet.UU.NET>
  8. Date: 22 Jul 89 01:19:08 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: ron@mlfarm.UUCP (Ronald Florence)
  11. Organization: Maple Lawn Farm, Stonington, CT
  12. Lines: 397
  13. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  14.  
  15. Posting-number: Volume 7, Issue 99
  16. Submitted-by: ron@mlfarm.UUCP (Ronald Florence)
  17. Archive-name: bsnews
  18.  
  19. [[A patch for this arrived before this went out; I applied it, so this
  20.   is effectively at patclevel 1.  ++bsa]]
  21. [[This cleans out the c.s.m queue, except for one program (indexor) which
  22.   needs to be split to avoid message length limits.  ++bsa]]
  23.  
  24. Bootstrap News is a collection of programs which enable a leaf node to
  25. take a news feed without installing a full news package.  News
  26. articles are accumulated in a Unix-mail type spool file, where they
  27. can be read with a mail reader such as `Mail' or `elm'.
  28.  
  29. #--------------------------------CUT HERE-------------------------------------
  30. #! /bin/sh
  31. #
  32. # This is a shell archive.  Save this into a file, edit it
  33. # and delete all lines above this comment.  Then give this
  34. # file to sh by executing the command "sh file".  The files
  35. # will be extracted into the current directory owned by
  36. # you with default permissions.
  37. #
  38. # The files contained herein are:
  39. #
  40. # -rw-r--r--  1 allbery      1987 Jul 21 21:14 Readme
  41. # -rw-r--r--  1 allbery      1759 Jul 21 21:14 Makefile
  42. # -rw-r--r--  1 allbery      1890 Jul 21 21:14 rnews.c
  43. # -rw-r--r--  1 allbery       409 Jul 21 21:14 checknews.c
  44. # -rw-r--r--  1 allbery       306 Jul 21 21:14 uurec.proto
  45. # -rw-r--r--  1 allbery       987 Jul 21 21:11 pn.proto
  46. #
  47. echo 'x - Readme'
  48. if test -f Readme; then echo 'shar: not overwriting Readme'; else
  49. sed 's/^X//' << '________This_Is_The_END________' > Readme
  50. Xbsnews - Bootstrap News
  51. Xcopyright 1989 Ronald Florence
  52. X
  53. XBootstrap News is a collection of programs which enable a leaf node to
  54. Xtake a news feed without installing a full news package.  News
  55. Xarticles are accumulated in a Unix-mail type spool file, where they
  56. Xcan be read with a mail reader such as `Mail' or `elm'.
  57. X
  58. XThe Makefile builds the following programs and files:
  59. X
  60. X    rnews  -    run by a `uux - yoursys!rnews' command to 
  61. X            read single articles, batched, or batched 
  62. X            and compressed news into the news spool.
  63. X
  64. X    uurec -     posts articles which arrive as mail 
  65. X            via `sendnews' into the news spool.
  66. X
  67. X    pn -        a simple news poster.
  68. X
  69. X    checknews - monitors whether new news has arrived.
  70. X
  71. X    readnews -  invokes the mail reader.
  72. X
  73. X    /usr/lib/news/seq -       last outgoing article number.
  74. X
  75. X    /usr/spool/news/bsnews -  the mail spool.
  76. X
  77. X  
  78. XTo build bootstrap news, make any changes needed in `Makefile', and
  79. Xrun `make'.  For a `uux' feed, add `rnews' to /usr/lib/uucp/L.cmds or
  80. Xthe equivalent.  For a `sendnews' feed, create a sendmail alias for
  81. Xrnews: "|/usr/bin/uurec", or use cron to run `uurec' periodically with
  82. X/usr/spool/mail/rnews as input.  Adding the command `checknews' to
  83. Xyour `.login' or `.profile' file will give you notification of new
  84. Xnews when you log in.
  85. X
  86. XYou may need to change `pn.proto':  
  87. X     If your `echo' uses `-n' instead of `\c' to suppress the newline,
  88. X     If `logname' does not give the user's name,
  89. X     If `uuname -l' does not give the system's uucp name,
  90. X     To use an editor other than `vi' to compose outgoing news, or
  91. X     To proof outgoing articles with a pager other than `more'.
  92. X
  93. XPermission is hereby granted for unlimited non-commercial use of these
  94. Xprograms, on condition that the copyright notices are left intact and
  95. Xany modifications to the source code are noted as such.  No warranty
  96. Xof any kind is implied or granted for this material.
  97. X
  98. X
  99. XRonald Florence        
  100. XMaple Lawn Farm, Stonington, CT
  101. Xron@mlfarm  
  102. X...{hsi!aati,rayssd}!mlfarm!ron
  103. ________This_Is_The_END________
  104. if test `wc -c < Readme` -ne 1987; then
  105.     echo 'shar: Readme was damaged during transit (should have been 1987 bytes)'
  106. fi
  107. fi        ; : end of overwriting check
  108. echo 'x - Makefile'
  109. if test -f Makefile; then echo 'shar: not overwriting Makefile'; else
  110. sed 's/^X//' << '________This_Is_The_END________' > Makefile
  111. X# Makefile for bootstrap news
  112. X# copyright 1989 Ronald Florence  (ron@mlfarm, 7/11/89)
  113. X#
  114. X# To build bootstrap news:
  115. X#   1. Change READER to your favorite mail reader with the option flag
  116. X#      used to specify a spool file.
  117. X#   2. Change HOST to the name of your news feed.  If you get news
  118. X#      from more than one host, select the one to which you feed news,
  119. X#      and change FEEDER to something like `Usenet_news'.
  120. X#   3. Run `make'.  
  121. X#
  122. X
  123. XREADER = Mail -f
  124. XHOST = mlfarm
  125. XFEEDER = news@$(HOST).UUCP
  126. X
  127. XSPOOL = /usr/spool/news
  128. XNEWSSPOOL = $(SPOOL)/bsnews
  129. XNEWSDIR = /usr/lib/news
  130. XSEQFILE = $(NEWSDIR)/seq
  131. XBINDIR = /usr/bin
  132. XCOMPRESS = $(BINDIR)/compress
  133. XCFLAGS = -O -s -DFeeder='"$(FEEDER)"' -DNewsspool='"$(NEWSSPOOL)"'
  134. XPGMS = uurec pn checknews rnews readnews
  135. XFILES = spoolfile seqfile
  136. XSRCS = checknews.c rnews.c uurec.proto pn.proto
  137. XSHELL = /bin/sh
  138. X
  139. Xbsnews: install
  140. X    @ [ -x $(COMPRESS) ] || { echo "You need $(COMPRESS) for batched & compressed feeds."; }
  141. X
  142. Xinstall: $(PGMS)  $(FILES)
  143. X    cp $(PGMS) $(BINDIR)
  144. X    cd $(BINDIR)
  145. X    chgrp bin $(PGMS)
  146. X    chown bin $(PGMS)
  147. X    @echo
  148. X    @echo "Add rnews to /usr/lib/uucp/L.cmds for a uux feed, or create a"
  149. X    @echo "sendmail alias for rnews: \"|/usr/bin/uurec\" for a mail feed."
  150. X
  151. Xspoolfile:
  152. X    [ -d $(SPOOL) ] || mkdir $(SPOOL)
  153. X    [ -f $(NEWSSPOOL) ] || > $(NEWSSPOOL)
  154. X    chmod 666 $(NEWSSPOOL)
  155. X
  156. Xseqfile:
  157. X    [ -f $(SEQFILE) ] || { mkdir $(NEWSDIR); echo "1" > $(SEQFILE); }
  158. X    chmod 666 $(SEQFILE)
  159. X
  160. Xuurec:    uurec.proto
  161. X    sed "s|/usr/spool/news/bsnews|$(NEWSSPOOL)|" uurec.proto > uurec
  162. X    chmod +x uurec
  163. X
  164. Xpn:    pn.proto
  165. X    sed  "s/BigNode/$(HOST)/" pn.proto > pn
  166. X    chmod +x pn
  167. X
  168. Xreadnews: 
  169. X    echo "$(READER) $(NEWSSPOOL)" > readnews
  170. X    chmod +x readnews
  171. X
  172. Xshar:    Readme Makefile $(SRCS)
  173. X    shar -a Readme Makefile $(SRCS) > bsnews.shar
  174. X
  175. Xclean:
  176. X    rm $(PGMS) 
  177. ________This_Is_The_END________
  178. if test `wc -c < Makefile` -ne 1759; then
  179.     echo 'shar: Makefile was damaged during transit (should have been 1759 bytes)'
  180. fi
  181. fi        ; : end of overwriting check
  182. echo 'x - rnews.c'
  183. if test -f rnews.c; then echo 'shar: not overwriting rnews.c'; else
  184. sed 's/^X//' << '________This_Is_The_END________' > rnews.c
  185. X/*
  186. X * rnews.c - uux command for bootstrap news
  187. X * copyright 1989 Ronald Florence (ron@mlfarm 7/9/89)
  188. X */
  189. X
  190. X#include <stdio.h>
  191. X#include <time.h>
  192. X
  193. X#ifndef Newsspool
  194. X#define Newsspool    "/usr/spool/news/bsnews"
  195. X#endif
  196. X#ifndef Feeder
  197. X#define Feeder         "Usenet"
  198. X#endif
  199. X
  200. X#define Compress     "/usr/bin/compress -dc > "
  201. X
  202. Xchar      *mktemp(),
  203. X        dcomp[40] = Compress;
  204. X
  205. Xmain()
  206. X{
  207. X  FILE    *nf, *cf;
  208. X  char  buf[BUFSIZ],
  209. X        *tmpnews = mktemp("newsart.XXXXXX");
  210. X  register  c;
  211. X  int    new = 1, n;
  212. X
  213. X  if (!(nf = fopen(Newsspool, "a")))
  214. X    {
  215. X      fprintf(stderr, "rnews: can't write to %s\n", Newsspool);
  216. X      exit(1);
  217. X    }
  218. X
  219. X  while (fgets(buf, BUFSIZ, stdin) != NULL)
  220. X    {
  221. X                /* batched? */
  222. X      if (!strncmp(buf, "#! ", 3))
  223. X    {
  224. X                /* compressed? */
  225. X      if (!strncmp(buf+3, "cunbatch", 8))
  226. X        {
  227. X          strcat(dcomp, tmpnews);
  228. X          if (!(cf = popen(dcomp, "w")))
  229. X        {
  230. X          timestamp();
  231. X          fprintf(nf, "\nNews lost!  Can't uncompress (rnews).\n\n");
  232. X          exit(1);
  233. X        }
  234. X                /* uncompress */
  235. X          while ((c = getchar()) != EOF)
  236. X        putc(c, cf);
  237. X          pclose(cf);
  238. X                /* and loop around to unbatch */
  239. X          cf = freopen(tmpnews, "r", stdin);
  240. X          continue;
  241. X        }
  242. X                /* unpack the batch */
  243. X      else if (sscanf(buf+3, "rnews %d", &n) == 1)  
  244. X        {
  245. X          timestamp(nf);
  246. X          for (c = 0; c < n; c += strlen(buf))
  247. X        {
  248. X          fgets(buf, BUFSIZ, stdin);
  249. X          if (!strncmp(buf, "From ", 5))
  250. X            putc('>', nf);
  251. X          fputs(buf, nf);
  252. X        }
  253. X          putc('\n', nf);
  254. X          continue;
  255. X        }
  256. X    }
  257. X                /* it must be unbatched */
  258. X      else    
  259. X    {
  260. X      if (new)
  261. X        {
  262. X          timestamp(nf);
  263. X          new = 0;
  264. X        }
  265. X      if (!strncmp(buf, "From ", 5))
  266. X        putc('>', nf);
  267. X      fputs(buf, nf);
  268. X    }
  269. X    }
  270. X  if (!new)
  271. X    putc('\n', nf);
  272. X  unlink(tmpnews);
  273. X  exit(0);
  274. X}
  275. X
  276. X
  277. Xtimestamp(newsfile)
  278. XFILE  *newsfile;
  279. X{
  280. X  long    clock, time();
  281. X  char    *ctime();
  282. X
  283. X  time(&clock);
  284. X  fprintf(newsfile, "From %s %s", Feeder, ctime(&clock));
  285. X}
  286. ________This_Is_The_END________
  287. if test `wc -c < rnews.c` -ne 1890; then
  288.     echo 'shar: rnews.c was damaged during transit (should have been 1890 bytes)'
  289. fi
  290. fi        ; : end of overwriting check
  291. echo 'x - checknews.c'
  292. if test -f checknews.c; then echo 'shar: not overwriting checknews.c'; else
  293. sed 's/^X//' << '________This_Is_The_END________' > checknews.c
  294. X/*
  295. X * checknews.c - checks for bootstrap news
  296. X * copyright 1989 Ronald Florence (ron@mlfarm, 7/7/89)
  297. X */
  298. X
  299. X#include <stdio.h>
  300. X#include <sys/types.h>
  301. X#include <sys/stat.h>
  302. X
  303. X#ifndef Newsspool
  304. X#define Newsspool  "/usr/spool/news/bsnews"
  305. X#endif
  306. X
  307. Xmain()
  308. X{
  309. X  struct stat st;
  310. X
  311. X  if (stat(Newsspool, &st) == -1)
  312. X    st.st_size = 0;
  313. X  if (st.st_size && (st.st_atime < st.st_mtime))
  314. X    puts("New news has arrived.");
  315. X}
  316. ________This_Is_The_END________
  317. if test `wc -c < checknews.c` -ne 409; then
  318.     echo 'shar: checknews.c was damaged during transit (should have been 409 bytes)'
  319. fi
  320. fi        ; : end of overwriting check
  321. echo 'x - uurec.proto'
  322. if test -f uurec.proto; then echo 'shar: not overwriting uurec.proto'; else
  323. sed 's/^X//' << '________This_Is_The_END________' > uurec.proto
  324. X:
  325. X# uurec - bootstrap news by mail 
  326. X# copyright 1989 Ronald Florence  (ron@mlfarm, 7/6/89)
  327. X
  328. XNewsspool=/usr/spool/news/bsnews
  329. X
  330. Xsed    '/^Received: .*/d
  331. X    /^    id .*/d
  332. X    /^Subject: .*/d
  333. X    /^To: .*/d
  334. X    /^Message-Id: .*/d
  335. X    /^Date: .*/d
  336. X    /^From: .*/d
  337. X    s/^NFrom />From /
  338. X    s/^N//'  >> $Newsspool
  339. Xecho "\n" >> $Newsspool
  340. X
  341. X
  342. ________This_Is_The_END________
  343. if test `wc -c < uurec.proto` -ne 306; then
  344.     echo 'shar: uurec.proto was damaged during transit (should have been 306 bytes)'
  345. fi
  346. fi        ; : end of overwriting check
  347. echo 'x - pn.proto'
  348. if test -f pn.proto; then echo 'shar: not overwriting pn.proto'; else
  349. sed 's/^X//' << '________This_Is_The_END________' > pn.proto
  350. X:
  351. X# pn - news poster for bootstrap news 
  352. X# Copyright 1989 Ronald Florence (ron@mlfarm, 7/7/89)
  353. X#
  354. X
  355. XHostname=BigNode
  356. XSeqfile=/usr/lib/news/seq
  357. Xset `date`
  358. XDatestr="$3 $2 `expr $6 % 100` $4 $5"
  359. XID=`cat $Seqfile`
  360. XSys=`uuname -l`
  361. XUser=`logname`
  362. X
  363. Xecho "Newsgroups: \c"
  364. Xread Groups rest
  365. Xecho "Subject: \c"
  366. Xread Subject rest
  367. X
  368. XTmpart=/tmp/newsart.$$
  369. X
  370. Xcat > $Tmpart <<EOH
  371. XPath: $Sys!$User
  372. XFrom: $User@$Sys.UUCP
  373. XNewsgroups: $Groups
  374. XSubject: $Subject
  375. XMessage-ID: <$ID@$Sys.UUCP>
  376. XDate: $Datestr
  377. XFollowup-To: 
  378. XDistribution:
  379. XKeywords: 
  380. XOrganization:
  381. XLines: 
  382. X
  383. X
  384. XEOH
  385. X
  386. Xvi +13 $Tmpart
  387. X
  388. Xcls
  389. Xmore $Tmpart
  390. Xecho "----------"
  391. Xecho "\nPost this article to all of usenet? \c"
  392. Xwhile read yn
  393. X  do case $yn in
  394. X    y|Y|yes|Yes|YES) uux - -r $Hostname!rnews < $Tmpart ; 
  395. X                 echo `expr $ID + 1` > $Seqfile ;
  396. X                 echo "Posted!" ;
  397. X                 break ;;
  398. X       n|N|no|No|NO) echo "Article cancelled!" ;
  399. X                 break ;;
  400. X                  *) echo "Yes or no? \c" ;;
  401. X     esac
  402. X  done
  403. Xrm -f $Tmpart
  404. ________This_Is_The_END________
  405. if test `wc -c < pn.proto` -ne 987; then
  406.     echo 'shar: pn.proto was damaged during transit (should have been 987 bytes)'
  407. fi
  408. fi        ; : end of overwriting check
  409. exit 0
  410. -- 
  411. Ronald Florence                    ...{hsi!aati,rayssd}!mlfarm!ron
  412.  
  413.  
  414.