home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gnats-3.01 / send-pr / send-pr.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-04-14  |  11.8 KB  |  453 lines

  1. #!/bin/sh
  2. # Submit a problem report to a GNATS site.
  3. # Copyright (C) 1993 Free Software Foundation, Inc.
  4. # Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
  5. # version written by Heinz G. Seidl (hgs@ide.com).
  6. #
  7. # This file is part of GNU GNATS.
  8. #
  9. # GNU GNATS is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # GNU GNATS is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with GNU GNATS; see the file COPYING.  If not, write to
  21. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. # The version of this send-pr.
  24. VERSION=@VERSION@
  25.  
  26. # The submitter-id for your site.
  27. SUBMITTER=unknown
  28.  
  29. # Where the GNATS directory lives, if at all.
  30. GNATS_ROOT=@GNATS_ROOT@
  31.  
  32. # The default mail address for PR submissions. 
  33. GNATS_ADDR=@GNATS_ADDR@
  34.  
  35. # Where the gnats category tree lives.
  36. LIBDIR=@LIBDIR@
  37.  
  38. # What mailer to use.
  39. MAIL_AGENT=/bin/mail
  40.  
  41. # The default release for this host.
  42. DEFAULT_RELEASE="@DEFAULT_RELEASE@"
  43.  
  44. # The default organization.
  45. DEFAULT_ORGANIZATION="@DEFAULT_ORGANIZATION@"
  46.  
  47. # The default site to look for.
  48. GNATS_SITE=@GNATS_SITE@
  49. #
  50.  
  51. if [ -z "$HOSTNAME" ]; then
  52.   if [ -f /bin/hostname ] ; then HOSTNAME=`/bin/hostname` 
  53.   elif [ -f /usr/bin/hostname ] ; then HOSTNAME=`/usr/bin/hostname` 
  54.   # Solaris et al.
  55.   elif [ -f /usr/ucb/hostname ] ; then HOSTNAME=`/usr/ucb/hostname`
  56.   # Irix
  57.   elif [ -f /usr/bsd/hostname ] ; then HOSTNAME=`/usr/bsd/hostname`
  58.   else echo "$COMMAND: HOSTNAME not set and hostname not found"; exit 1
  59.   fi
  60. fi
  61.  
  62. if [ -z "$LOGNAME" -a -n "$USER" ]; then
  63.   LOGNAME=$USER
  64. fi
  65. if [ -z "$LOGNAME" ]; then
  66.   FROM=
  67.   REPLY_TO=
  68. else
  69.   FROM="$LOGNAME@$HOSTNAME"
  70.   REPLY_TO="$LOGNAME@$HOSTNAME"
  71. fi
  72.  
  73. # Find out the name of the originator of this PR.
  74. if [ -n "$NAME" ]; then
  75.   ORIGINATOR="$NAME"
  76. elif [ -f $HOME/.fullname ]; then
  77.   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
  78. elif [ -f /bin/domainname ]; then
  79.   if [ "`/bin/domainname`" != "" -a -f /usr/bin/ypcat ]; then
  80.     ORIGINATOR="`/usr/bin/ypcat passwd | cat - /etc/passwd | grep '^$LOGNAME:' /etc/passwd | cut -f5 -d':' | sed -e 's/,.*//'`"
  81.   fi
  82. fi
  83.  
  84. if [ "$ORIGINATOR" = "" ]; then
  85.   ORIGINATOR="`grep '^$LOGNAME:' /etc/passwd | cut -f5 -d':' | sed -e 's/,.*//'`"
  86. fi
  87.  
  88. if [ -n "$ORGANIZATION" ]; then
  89.   if [ -f "$ORGANIZATION" ]; then
  90.     ORGANIZATION="`cat $ORGANIZATION`"
  91.   fi
  92. else
  93.   if [ -n "$DEFAULT_ORGANIZATION" ]; then
  94.     ORGANIZATION="$DEFAULT_ORGANIZATION"
  95.   elif [ -f $HOME/.organization ]; then
  96.     ORGANIZATION="`cat $HOME/.organization`"
  97.   elif [ -f $HOME/.signature ]; then
  98.     ORGANIZATION="`cat $HOME/.signature`"
  99.   fi
  100. fi
  101.  
  102. # If they don't have a preferred editor set, then use
  103. if [ -z "$VISUAL" ]; then
  104.   if [ -z "$EDITOR" ]; then
  105.     EDIT=vi
  106.   else
  107.     EDIT="$EDITOR"
  108.   fi
  109. else
  110.   EDIT="$VISUAL"
  111. fi
  112.  
  113. # Find out some information.
  114. SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
  115.         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
  116. ARCH=`[ -f /bin/arch ] && /bin/arch`
  117. MACHINE=`[ -f /bin/machine ] && /bin/machine`
  118.  
  119. [ -z "$TMPDIR" ] && TMPDIR=/tmp
  120.  
  121. TEMP=$TMPDIR/p$$
  122. BAD=$TMPDIR/pbad$$
  123. REF=$TMPDIR/pf$$
  124.  
  125. COMMAND=`echo $0 | sed -e 's,.*/,,g`
  126. USAGE="Usage: $COMMAND [-pPVL] [-t address] [-f filename] [--request-id] [--version]"
  127. REMOVE=
  128.  
  129. while [ $# -gt 0 ]; do
  130.   case "$1" in
  131.     -V|--version) echo "$VERSION"; exit 0 ;;
  132.     -t) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
  133.     shift ; GNATS_ADDR="$1"
  134.     EXPLICIT_GNATS_ADDR=true
  135.         ;;
  136.     -f) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
  137.     shift ; IN_FILE="$1"
  138.     if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
  139.       echo "$COMMAND: cannot read $IN_FILE"
  140.       exit 1
  141.     fi
  142.     ;;
  143.     -p) PRINT_INTERN=true ;;
  144.     -r) REMOVE=true ;;
  145.     -P) PRINT=true ;;
  146.     -L) FORMAT=norm ;;
  147.     -CL) FORMAT=lisp ;;
  148.     --request-id) REQUEST_ID=true ;;
  149.     -*) echo "$USAGE" ; exit 1 ;;
  150.     *) if [ -z "$USER_GNATS_SITE" ]; then
  151.     if [ ! -r "$LIBDIR/gnats/$1" ]; then
  152.        echo "$COMMAND: the GNATS site $1 does not have a categories list."
  153.        exit 1
  154.      else
  155.        # The site name is the alias they'll have to have created.
  156.        USER_GNATS_SITE=$1
  157.      fi
  158.        else
  159.      echo "$USAGE" ; exit 1
  160.        fi
  161.        ;;
  162.  esac
  163.  shift
  164. done
  165.  
  166. if [ -n "$USER_GNATS_SITE" ]; then
  167.   GNATS_SITE=$USER_GNATS_SITE
  168.   GNATS_ADDR=$USER_GNATS_SITE-gnats
  169. fi
  170.  
  171. if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" ]; then
  172.   cat << '__EOF__'
  173. It seems that send-pr is not installed with your unique submitter-id.
  174. Please use the program install-sid to modify send-pr to include your
  175. ID with each report you submit.
  176. __EOF__
  177.   exit 1
  178. fi
  179.  
  180. if [ -r "$LIBDIR/gnats/$GNATS_SITE" ]; then
  181.   CATEGORIES=`grep -v '^#' $LIBDIR/gnats/$GNATS_SITE | sort`
  182. else
  183.   echo "$COMMAND: could not read $LIBDIR/gnats/$GNATS_SITE for categories list."
  184.   exit 1
  185. fi
  186.  
  187. if [ -z "$CATEGORIES" ]; then
  188.   echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
  189.   exit 1
  190. fi
  191.  
  192. case "$FORMAT" in
  193.   lisp) echo "$CATEGORIES" | \
  194.         awk 'BEGIN {printf "("} {printf "(\"%s\") ",$0} END {printf ")\n"}'
  195.         exit 0
  196.         ;;
  197.   norm) echo "$CATEGORIES" | \
  198.         awk 'BEGIN {print "Known categories:"; i = 1 }
  199.           { printf ("%-12.12s", $0); if ((++i % 5) == 0) { print "" } }
  200.             END { print ""; }'
  201.         exit 0
  202.         ;;
  203. esac
  204.  
  205. ORIGINATOR_C='<name of the PR author (one line)>'
  206. ORGANIZATION_C='<organization of PR author (multiple lines)>'
  207. CONFIDENTIAL_C='<[ yes | no ] (one line)>'
  208. SYNOPSIS_C='<synopsis of the problem (one line)>'
  209. SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
  210. PRIORITY_C='<[ low | medium | high ] (one line)>'
  211. CATEGORY_C='<name of the product (one line)>'
  212. CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
  213. RELEASE_C='<release number or tag (one line)>'
  214. ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
  215. DESCRIPTION_C='<precise description of the problem (multiple lines)>'
  216. HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
  217.  
  218. # Catch some signals.
  219. trap 'rm -f $REF $TEMP ; exit 0' 0
  220. trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP ; exit 1' 1 2 3 13 15
  221.  
  222. # If they told us to use a specific file, then do so.
  223. if [ -n "$IN_FILE" ]; then
  224.   if [ "$IN_FILE" = "-" ]; then
  225.     # The PR is coming from the standard input.
  226.     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
  227.       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
  228.     else
  229.       cat >> $TEMP
  230.     fi
  231.   else
  232.     # Use the file they named.
  233.     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
  234.       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
  235.     else
  236.       cat $IN_FILE > $TEMP
  237.     fi
  238.   fi
  239. else
  240.  
  241.   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
  242.     # If their PR_FORM points to a bogus entry, then bail.
  243.     if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
  244.       echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
  245.       sleep 1
  246.       PRINT_INTERN=bad_prform
  247.     fi
  248.   fi
  249.  
  250.   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
  251.     cp $PR_FORM $TEMP || ( echo "$COMMAND: could not copy $PR_FORM" ; exit 1 )
  252.   else
  253.     for file in $TEMP $REF ; do
  254.       cat  > $file << '__EOF__'
  255. SEND-PR: -*- send-pr -*-
  256. SEND-PR: Lines starting with `SEND-PR' will be removed automatically as
  257. SEND-PR: well as all comments (the text below enclosed in `<' and `>').
  258. SEND-PR: 
  259. SEND-PR: Please consult the man page `send-pr(1)' if you are not sure,
  260. SEND-PR: how to fill out a problem report.
  261. SEND-PR:
  262. SEND-PR: Choose from the following categories:
  263. SEND-PR:
  264. __EOF__
  265.  
  266.       # Format the categories so they fit onto lines.
  267.       echo "$CATEGORIES" | awk '
  268.       BEGIN { printf "SEND-PR: "; i = 1 }
  269.            { printf ("%-12.12s", $COMMAND) ;
  270.          if ((++i % 5) == 0) { printf "\nSEND-PR: "}}
  271.       END   { printf "\nSEND-PR:\n" }' >> $file
  272.  
  273.       cat >> $file << __EOF__
  274. To: $GNATS_ADDR
  275. Subject: 
  276. From: $FROM
  277. Reply-To: $REPLY_TO
  278. X-send-pr-version: $VERSION
  279.  
  280. >Submitter-Id:   $SUBMITTER
  281. >Originator:      $ORIGINATOR
  282. >Organization:
  283. `
  284.   if [ -n "$ORGANIZATION" ]; then
  285.     echo "$ORGANIZATION"
  286.   else
  287.     echo "    $ORGANIZATION_C" ;
  288.   fi ;
  289. `
  290. >Confidential:  $CONFIDENTIAL_C
  291. >Synopsis:    $SYNOPSIS_C
  292. >Severity:    $SEVERITY_C
  293. >Priority:    $PRIORITY_C
  294. >Category:     $CATEGORY_C
  295. >Class:        $CLASS_C
  296. >Release:    `if [ -n "$DEFAULT_RELEASE" ]; then
  297.            echo "$DEFAULT_RELEASE"
  298.          else
  299.            echo "    $RELEASE_C"
  300.          fi; `
  301. >Environment:
  302.         $ENVIRONMENT_C
  303. `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
  304. `[ -n "$ARCH" ] && echo Architecture: $ARCH`
  305. `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
  306. >Description:     
  307.     $DESCRIPTION_C
  308. >How-To-Repeat:     
  309.     $HOW_TO_REPEAT_C
  310. __EOF__
  311.     done
  312.   fi
  313.  
  314.   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
  315.     cat $TEMP
  316.     exit 0
  317.   fi
  318.  
  319.   chmod u+w $TEMP
  320.   if [ -z "$REQUEST_ID" ]; then
  321.     eval $EDIT $TEMP
  322.   else
  323.     ed -s $TEMP << '__EOF__'
  324. /^Subject/s/^Subject:.*/Subject: request for a customer id/
  325. /^>Category/s/^>Category:.*/>Category: send-pr/
  326. w
  327. q
  328. __EOF__
  329.   fi
  330.  
  331.   if cmp -s $REF $TEMP ; then
  332.     echo "$COMMAND: problem report not filled out, therefore not sent"
  333.     exit 1
  334.   fi
  335. fi
  336.  
  337. #
  338. #    Check the enumeration fields
  339.  
  340. CNT=0
  341.  
  342. # This is a "sed-subroutine" with one keyword parameter 
  343. # (with workaround for Sun sed bug)
  344. #
  345. SED_CMD='
  346. /$PATTERN/{
  347. s|||
  348. s|<.*>||
  349. s|^[     ]*||
  350. s|[     ]*$||
  351. p
  352. q
  353. }'
  354.  
  355. # 0) Hack on To:...if they edited the header, then that's the address
  356. #    they really wanted to send to (don't blame 'em for forgetting about
  357. #    the -t option), so use it instead.
  358. #
  359. PATTERN="^To:"
  360. TO=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  361. case "$TO" in
  362.   ""|"$GNATS_ADDR") ;;
  363.   *)  GNATS_ADDR=$TO ;;
  364. esac
  365. #
  366. # 1) Confidential
  367. #
  368. PATTERN=">Confidential:"
  369. CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  370. case "$CONFIDENTIAL" in
  371.   ""|yes|no) CNT=`expr $CNT + 1` ;;
  372.   *) echo "0: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
  373. esac
  374. #
  375. # 2) Severity
  376. #
  377. PATTERN=">Severity:"
  378. SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  379. case "$SEVERITY" in
  380.   ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
  381.   *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
  382. esac
  383. #
  384. # 3) Priority
  385. #
  386. PATTERN=">Priority:"
  387. PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  388. case "$PRIORITY" in
  389.   ""|low|medium|high) CNT=`expr $CNT + 1` ;;
  390.   *)  echo "$COMMAND: \`$PRIORITY is not a valid value for \`Priority."
  391. esac
  392. #
  393. # 4) Category
  394. #
  395. PATTERN=">Category:"
  396. CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  397. FOUND=
  398. for C in $CATEGORIES
  399. do
  400.   if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
  401. done
  402. if [ -n "$FOUND" ]; then
  403.   CNT=`expr $CNT + 1`    
  404. else
  405.   if [ -z "$CATEGORY" ]; then
  406.     echo "$COMMAND: you must include a Category: field in your report."
  407.   else
  408.     echo "$COMMAND: \`$CATEGORY' is not a known category."
  409.   fi
  410. fi
  411. #
  412. # 5) Class
  413. #
  414. PATTERN=">Class:"
  415. CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
  416. case "$CLASS" in
  417.   ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
  418.   *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
  419. esac
  420.  
  421. if  [ "$CNT" -lt 5 ] && [ -z "$FORCE"  ]; then
  422.   if [ -z "$REMOVE" ]; then
  423.     echo "$COMMAND: the problem report remains in $BAD and is not sent."
  424.     mv $TEMP $BAD
  425.   else
  426.     echo "$COMMAND: the problem report is not sent."
  427.   fi
  428.   exit 1
  429. fi
  430.  
  431. #
  432. #    Remove comments and send the problem report
  433. #    (we have to use patterns, where the comment contains regex chars)
  434. #
  435. # /^>Originator:/s;$ORIGINATOR;;
  436. sed  -e "
  437. /^SEND-PR:/d
  438. /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
  439. /^>Confidential:/s;<.*>;;
  440. /^>Synopsis:/s;$SYNOPSIS_C;;
  441. /^>Severity:/s;<.*>;;
  442. /^>Priority:/s;<.*>;;
  443. /^>Category:/s;$CATEGORY_C;;
  444. /^>Class:/s;<.*>;;
  445. /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
  446. /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
  447. /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
  448. /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
  449. " $TEMP | eval $MAIL_AGENT $GNATS_ADDR
  450.  
  451. echo "$COMMAND: problem report sent to $GNATS_ADDR"
  452. exit 0
  453.