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