1#! /bin/sh
2#
3# lrzszbug - create a bug report and mail it to the bug address.
4#
5# configuration section:
6#       these variables are filled in by configure
7#
8VERSION="@VERSION@"
9BUGGLIBC="bugs@bulkmail.ohse.de"
10
11PATH=$PATH:/bin:/usr/bin:/usr/local/bin
12export PATH
13
14TEMP=/tmp/lrzszbug.$$
15
16BUGADDR=${1-$BUGGLIBC}
17ENVIRONMENT=`uname -a`
18
19: ${EDITOR=emacs}
20
21: ${USER=${LOGNAME-`whoami`}}
22
23trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
24trap 'rm -f $TEMP $TEMP.x' 0
25
26
27# How to read the passwd database.
28PASSWD="cat /etc/passwd"
29
30if [ -f /usr/lib/sendmail ] ; then
31        MAIL_AGENT="/usr/lib/sendmail -oi -t"
32elif [ -f /usr/sbin/sendmail ] ; then
33        MAIL_AGENT="/usr/sbin/sendmail -oi -t"
34else
35        MAIL_AGENT=rmail
36fi
37
38# Figure out how to echo a string without a trailing newline
39N=`echo 'hi there\c'`
40case "$N" in
41*c)	ECHON1='echo -n' ECHON2= ;;
42*)	ECHON1=echo ECHON2='\c' ;;
43esac
44
45# Find out the name of the originator of this PR.
46if [ -n "$NAME" ]; then
47  ORIGINATOR="$NAME"
48elif [ -f $HOME/.fullname ]; then
49  ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
50else
51  # Must use temp file due to incompatibilities in quoting behavior
52  # and to protect shell metacharacters in the expansion of $LOGNAME
53  $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
54  ORIGINATOR="`cat $TEMP`"
55  rm -f $TEMP
56fi
57
58if [ -n "$ORGANIZATION" ]; then
59  if [ -f "$ORGANIZATION" ]; then
60    ORGANIZATION="`cat $ORGANIZATION`"
61  fi
62else
63  if [ -f $HOME/.organization ]; then
64    ORGANIZATION="`cat $HOME/.organization`"
65  elif [ -f $HOME/.signature ]; then
66    ORGANIZATION=`sed -e "s/^/  /" $HOME/.signature; echo ">"`
67  fi
68fi
69
70# If they don't have a preferred editor set, then use
71if [ -z "$VISUAL" ]; then
72  if [ -z "$EDITOR" ]; then
73    EDIT=vi
74  else
75    EDIT="$EDITOR"
76  fi
77else
78  EDIT="$VISUAL"
79fi
80
81# Find out some information.
82SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
83        ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
84ARCH=`[ -f /bin/arch ] && /bin/arch`
85MACHINE=`[ -f /bin/machine ] && /bin/machine`
86
87ORGANIZATION_C='<organization of PR author (multiple lines)>'
88SYNOPSIS_C='<synopsis of the problem (one line)>'
89SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
90PRIORITY_C='<[ low | medium | high ] (one line)>'
91CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
92RELEASE_C='<release number or tag (one line)>'
93ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
94DESCRIPTION_C='<precise description of the problem (multiple lines)>'
95HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
96FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
97
98
99cat > $TEMP <<EOF
100SEND-PR: -*- send-pr -*-
101SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
102SEND-PR: will all comments (text enclosed in \`<' and \`>').
103SEND-PR:
104From: ${USER}
105To: ${BUGADDR}
106Subject: lrzsz: [50 character or so descriptive subject here (for reference)]
107
108>Submitter-Id:	net
109>Originator:	${ORIGINATOR}
110>Organization:
111${ORGANIZATION- $ORGANIZATION_C}
112>Confidential:	no
113>Synopsis:	$SYNOPSIS_C
114>Severity:	$SEVERITY_C
115>Priority:	$PRIORITY_C
116>Category:	lrzsz
117>Class:		$CLASS_C
118>Release:	lrzsz-${VERSION}
119>Environment:
120	$ENVIRONMENT_C
121`[ -n "$SYSTEM" ] && echo System: $SYSTEM`
122`[ -n "$ARCH" ] && echo Architecture: $ARCH`
123`[ -n "$MACHINE" ] && echo Machine: $MACHINE`
124`[ -f "lrz" ] && echo " include, if possible, the output of 'ldd lrz'"`
125`[ -f "src/lrz" ] && echo " include, if possible, the output of 'ldd src/lrz'"`
126`[ -f "lrzsz-@VERSION@/src/lrz" ] && echo " include, if possible, the output of 'ldd lrzsz-@VERSION@/src/lrz'"`
127
128>Description:
129	$DESCRIPTION_C
130>How-To-Repeat:
131	$HOW_TO_REPEAT_C
132>Fix:
133	$FIX_C
134EOF
135
136chmod u+w $TEMP
137cp $TEMP $TEMP.x
138
139eval $EDIT $TEMP
140
141if cmp -s $TEMP $TEMP.x; then
142	echo "File not changed, no bug report submitted."
143	exit 1
144fi
145
146#
147#       Check the enumeration fields
148
149# This is a "sed-subroutine" with one keyword parameter
150# (with workaround for Sun sed bug)
151#
152SED_CMD='
153/$PATTERN/{
154s|||
155s|<.*>||
156s|^[ 	]*||
157s|[ 	]*$||
158p
159q
160}'
161
162
163while :; do
164  CNT=0
165
166  #
167  # 1) Severity
168  #
169  PATTERN=">Severity:"
170  SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
171  case "$SEVERITY" in
172    ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
173    *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
174  esac
175  #
176  # 2) Priority
177  #
178  PATTERN=">Priority:"
179  PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
180  case "$PRIORITY" in
181    ""|low|medium|high) CNT=`expr $CNT + 1` ;;
182    *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
183  esac
184  #
185  # 3) Class
186  #
187  PATTERN=">Class:"
188  CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
189  case "$CLASS" in
190    ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
191    *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
192  esac
193
194  [ $CNT -lt 3 ] &&
195    echo "Errors were found with the problem report."
196
197  while :; do
198    $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
199    read input
200    case "$input" in
201      a*)
202	echo "$COMMAND: problem report saved in $HOME/dead.lrzszbug."
203	cat $TEMP >> $HOME/dead.lrzszbug
204        xs=1; exit
205        ;;
206      e*)
207        eval $EDIT $TEMP
208        continue 2
209        ;;
210      s*)
211        break 2
212        ;;
213    esac
214  done
215done
216#
217#       Remove comments and send the problem report
218#       (we have to use patterns, where the comment contains regex chars)
219#
220# /^>Originator:/s;$ORIGINATOR;;
221sed  -e "
222/^SEND-PR:/d
223/^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
224/^>Confidential:/s;<.*>;;
225/^>Synopsis:/s;$SYNOPSIS_C;;
226/^>Severity:/s;<.*>;;
227/^>Priority:/s;<.*>;;
228/^>Class:/s;<.*>;;
229/^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
230/^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
231/^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
232/^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
233/^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
234" $TEMP > $TEMP.x
235
236if $MAIL_AGENT < $TEMP.x; then
237  echo "$COMMAND: problem report sent"
238  xs=0; exit
239else
240  echo "$COMMAND: mysterious mail failure, report not sent."
241  echo "$COMMAND: problem report saved in $HOME/dead.lrzszbug."
242  cat $TEMP >> $HOME/dead.lrzszbug
243fi
244
245exit 0
246