| 1 |
#!/bin/sh |
| 2 |
# Create a bug report for a client and mail it to the argus mailing list |
| 3 |
# A completely plagaristic move on my part by using the |
| 4 |
# mysql bug reporting script. Thanks guys!!!! |
| 5 |
|
| 6 |
echo "Finding system information for a Argus bug report" |
| 7 |
|
| 8 |
VERSION="5.0.2" |
| 9 |
BUGMAIL="[email protected]" |
| 10 |
|
| 11 |
LIBC_INFO="" |
| 12 |
for pat in /lib/libc.* /lib/libc-* /usr/lib/libc.* /usr/lib/libc-* |
| 13 |
do |
| 14 |
TMP=`ls -l $pat 2>/dev/null` |
| 15 |
if test $? = 0 |
| 16 |
then |
| 17 |
LIBC_INFO="$LIBC_INFO |
| 18 |
$TMP" |
| 19 |
fi |
| 20 |
done |
| 21 |
|
| 22 |
PATH=../:$PATH:/bin:/usr/bin:/usr/local/bin |
| 23 |
export PATH |
| 24 |
|
| 25 |
BUGADDR=${1-$BUGMAIL} |
| 26 |
ENVIRONMENT=`uname -a` |
| 27 |
|
| 28 |
: ${USER=${LOGNAME-`whoami`}} |
| 29 |
|
| 30 |
COMMAND=`echo $0|sed 's%.*/\([^/]*\)%\1%'` |
| 31 |
|
| 32 |
# Try to create a secure tmpfile |
| 33 |
umask 077 |
| 34 |
TEMPDIR=/tmp/argusclientbug-$$ |
| 35 |
mkdir $TEMPDIR || (echo "can not create directory in /tmp, aborting"; exit 1;) |
| 36 |
TEMP=${TEMPDIR}/argusclientbug |
| 37 |
|
| 38 |
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR; exit 1' 1 2 3 13 15 |
| 39 |
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR' 0 |
| 40 |
|
| 41 |
# How to read the passwd database. |
| 42 |
PASSWD="cat /etc/passwd" |
| 43 |
|
| 44 |
if test -f /usr/lib/sendmail |
| 45 |
then |
| 46 |
MAIL_AGENT="/usr/lib/sendmail -oi -t" |
| 47 |
elif test -f /usr/sbin/sendmail |
| 48 |
then |
| 49 |
MAIL_AGENT="/usr/sbin/sendmail -oi -t" |
| 50 |
else |
| 51 |
MAIL_AGENT="rmail $BUGMAIL" |
| 52 |
fi |
| 53 |
|
| 54 |
# Figure out how to echo a string without a trailing newline |
| 55 |
N=`echo 'hi there\c'` |
| 56 |
case "$N" in |
| 57 |
*c) ECHON1='echo -n' ECHON2= ;; |
| 58 |
*) ECHON1=echo ECHON2='\c' ;; |
| 59 |
esac |
| 60 |
|
| 61 |
# Find out the name of the originator of this PR. |
| 62 |
if test -n "$NAME" |
| 63 |
then |
| 64 |
ORIGINATOR="$NAME" |
| 65 |
elif test -f $HOME/.fullname |
| 66 |
then |
| 67 |
ORIGINATOR="`sed -e '1q' $HOME/.fullname`" |
| 68 |
else |
| 69 |
# Must use temp file due to incompatibilities in quoting behavior |
| 70 |
# and to protect shell metacharacters in the expansion of $LOGNAME |
| 71 |
$PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP |
| 72 |
ORIGINATOR="`cat $TEMP`" |
| 73 |
rm -f $TEMP |
| 74 |
fi |
| 75 |
|
| 76 |
if test -n "$ORGANIZATION" |
| 77 |
then |
| 78 |
if test -f "$ORGANIZATION" |
| 79 |
then |
| 80 |
ORGANIZATION="`cat $ORGANIZATION`" |
| 81 |
fi |
| 82 |
else |
| 83 |
if test -f $HOME/.organization |
| 84 |
then |
| 85 |
ORGANIZATION="`cat $HOME/.organization`" |
| 86 |
elif test -f $HOME/.signature |
| 87 |
then |
| 88 |
ORGANIZATION=`sed -e "s/^/ /" $HOME/.signature; echo ">"` |
| 89 |
fi |
| 90 |
fi |
| 91 |
|
| 92 |
PATH_DIRS=`echo $PATH | sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' ` |
| 93 |
|
| 94 |
which_1 () |
| 95 |
{ |
| 96 |
for cmd |
| 97 |
do |
| 98 |
# Absolute path ?. |
| 99 |
if expr "x$cmd" : "x/" > /dev/null |
| 100 |
then |
| 101 |
echo "$cmd" |
| 102 |
exit 0 |
| 103 |
else |
| 104 |
for d in $PATH_DIRS |
| 105 |
do |
| 106 |
file="$d/$cmd" |
| 107 |
if test -x "$file" -a ! -d "$file" |
| 108 |
then |
| 109 |
echo "$file" |
| 110 |
exit 0 |
| 111 |
fi |
| 112 |
done |
| 113 |
fi |
| 114 |
done |
| 115 |
exit 1 |
| 116 |
} |
| 117 |
|
| 118 |
change_editor () |
| 119 |
{ |
| 120 |
echo "You can change editor by setting the environment variable VISUAL." |
| 121 |
echo "If your shell is a bourne shell (sh) do" |
| 122 |
echo "VISUAL=your_editors_name; export VISUAL" |
| 123 |
echo "If your shell is a C shell (csh) do" |
| 124 |
echo "setenv VISUAL your_editors_name" |
| 125 |
} |
| 126 |
|
| 127 |
# If they don't have a preferred editor set, then use emacs |
| 128 |
if test -z "$VISUAL" |
| 129 |
then |
| 130 |
if test -z "$EDITOR" |
| 131 |
then |
| 132 |
EDIT=vi |
| 133 |
else |
| 134 |
EDIT="$EDITOR" |
| 135 |
fi |
| 136 |
else |
| 137 |
EDIT="$VISUAL" |
| 138 |
VISUALSET="true" |
| 139 |
fi |
| 140 |
|
| 141 |
#which_1 $EDIT |
| 142 |
used_editor=`which_1 $EDIT` |
| 143 |
|
| 144 |
echo "test -x $used_editor" |
| 145 |
if test -x "$used_editor" |
| 146 |
then |
| 147 |
echo "Using editor $used_editor"; |
| 148 |
change_editor |
| 149 |
sleep 2 |
| 150 |
else |
| 151 |
echo "Could not find a text editor. (tried $EDIT)" |
| 152 |
change_editor |
| 153 |
exit 1 |
| 154 |
fi |
| 155 |
|
| 156 |
# Find out some information. |
| 157 |
SYSTEM=`( test -f /bin/uname && /bin/uname -a ) || \ |
| 158 |
( test -f /usr/bin/uname && /usr/bin/uname -a ) || echo ""` |
| 159 |
ARCH=`test -f /bin/arch && /bin/arch` |
| 160 |
MACHINE=`test -f /bin/machine && /bin/machine` |
| 161 |
FILE_PATHS= |
| 162 |
|
| 163 |
for cmd in ra make gmake gcc cc |
| 164 |
do |
| 165 |
file=`which_1 $cmd` |
| 166 |
if test $? = 0 |
| 167 |
then |
| 168 |
if test $cmd = "ra" |
| 169 |
then |
| 170 |
RA_INFO=`$file -h 2>&1 | grep -i version 2>&1` |
| 171 |
elif test $cmd = "gcc" |
| 172 |
then |
| 173 |
GCC_INFO=`$file -v 2>&1` |
| 174 |
fi |
| 175 |
FILE_PATHS="$FILE_PATHS $file" |
| 176 |
fi |
| 177 |
done |
| 178 |
|
| 179 |
PKG_CONFIG=`which pkg-config` |
| 180 |
PKG_INFO="" |
| 181 |
|
| 182 |
if test -f $PKG_CONFIG; then |
| 183 |
PKG_INFO=`$PKG_CONFIG argus-clients --cflags --libs` |
| 184 |
fi |
| 185 |
|
| 186 |
|
| 187 |
SUBJECT_C="ArgusClientBug <50 character or so descriptive subject here (for reference)>" |
| 188 |
ORGANIZATION_C='<organization of PR author (multiple lines)>' |
| 189 |
LICENCE_C='[none | licence | email support | extended email support ]' |
| 190 |
SYNOPSIS_C='<synopsis of the problem (one line)>' |
| 191 |
SEVERITY_C='<[ non-critical | serious | critical ] (one line)>' |
| 192 |
PRIORITY_C='<[ low | medium | high ] (one line)>' |
| 193 |
CLASS_C='<[ install-bug | sw-bug | doc-bug | change-request | support ] (one line)>' |
| 194 |
PRODUCT_C='<[ ra | rabins | racluster | raconvert | racount | radark | radump | raevent | rafiteraddr | ragraph | rahisto | rahosts | ralabel | ranonyize | rapath | raplot | rapolicy | rasports | raservices | rasort | rasplit | rasql | rasqlcheckconf | rasqlinsert | rasqltimeindex | rastream | rastrip | ratimerange | ratop | ratree | rauserdata ] (one line)>' |
| 195 |
RELEASE_C='<release number or tag (one line)>' |
| 196 |
ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>' |
| 197 |
DESCRIPTION_C='<precise description of the problem (multiple lines)>' |
| 198 |
INSTALL_C='<if install-bug, please include ./configure output below>' |
| 199 |
HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>' |
| 200 |
FIX_C='<how to correct or work around the problem, if known (multiple lines)>' |
| 201 |
|
| 202 |
|
| 203 |
cat > $TEMP <<EOF |
| 204 |
SEND-PR: -*- send-pr -*- |
| 205 |
SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as |
| 206 |
SEND-PR: will all comments (text enclosed in \`<' and \`>'). |
| 207 |
SEND-PR: |
| 208 |
From: ${USER} |
| 209 |
To: ${BUGADDR} |
| 210 |
Subject: $SUBJECT_C |
| 211 |
|
| 212 |
>Description: |
| 213 |
$DESCRIPTION_C |
| 214 |
$INSTALL_C |
| 215 |
|
| 216 |
>How-To-Repeat: |
| 217 |
$HOW_TO_REPEAT_C |
| 218 |
|
| 219 |
>Fix: |
| 220 |
$FIX_C |
| 221 |
|
| 222 |
>Submitter-Id: <submitter ID> |
| 223 |
>Originator: ${ORIGINATOR} |
| 224 |
>Organization: |
| 225 |
${ORGANIZATION- $ORGANIZATION_C} |
| 226 |
>Argus support: $LICENCE_C |
| 227 |
>Release: argus-${VERSION} |
| 228 |
>Product: $PRODUCT_C |
| 229 |
>Synopsis: $SYNOPSIS_C |
| 230 |
>Class: $CLASS_C |
| 231 |
>Severity: $SEVERITY_C |
| 232 |
>Priority: $PRIORITY_C |
| 233 |
|
| 234 |
>Environment: $ENVIRONMENT_C |
| 235 |
|
| 236 |
`test -n "$SYSTEM" && echo "System: $SYSTEM"` |
| 237 |
`test -n "$ARCH" && echo "Arch: $ARCH"` |
| 238 |
`test -n "$MACHINE" && echo "Mach: $MACHINE"` |
| 239 |
`test -n "$FILE_PATHS" && echo "Paths: $FILE_PATHS"` |
| 240 |
|
| 241 |
`test -n "$RA_INFO" && echo "RA: $RA_INFO"` |
| 242 |
|
| 243 |
`test -n "$PKG_INFO" && echo "PKG: $PKG_INFO"` |
| 244 |
|
| 245 |
`test -n "$GCC_INFO" && echo "GCC: $GCC_INFO"` |
| 246 |
|
| 247 |
`test -n "$LIBC_INFO" && echo "LIBC: $LIBC_INFO"` |
| 248 |
|
| 249 |
EOF |
| 250 |
|
| 251 |
chmod u+w $TEMP |
| 252 |
cp $TEMP $TEMP.x |
| 253 |
|
| 254 |
eval $EDIT $TEMP |
| 255 |
|
| 256 |
if cmp -s $TEMP $TEMP.x |
| 257 |
then |
| 258 |
echo "File not changed, no bug report submitted." |
| 259 |
echo "File saved as /tmp/argus-bugreport-template." |
| 260 |
mv $TEMP /tmp/argus-bugreport-template |
| 261 |
exit 1 |
| 262 |
fi |
| 263 |
|
| 264 |
# |
| 265 |
# Check the enumeration fields |
| 266 |
|
| 267 |
# This is a "sed-subroutine" with one keyword parameter |
| 268 |
# (with workaround for Sun sed bug) |
| 269 |
# |
| 270 |
SED_CMD=' |
| 271 |
/$PATTERN/{ |
| 272 |
s||| |
| 273 |
s|<.*>|| |
| 274 |
s|^[ ]*|| |
| 275 |
s|[ ]*$|| |
| 276 |
p |
| 277 |
q |
| 278 |
}' |
| 279 |
|
| 280 |
|
| 281 |
while :; do |
| 282 |
CNT=0 |
| 283 |
|
| 284 |
# |
| 285 |
# 1) Severity |
| 286 |
# |
| 287 |
PATTERN=">Severity:" |
| 288 |
SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP` |
| 289 |
case "$SEVERITY" in |
| 290 |
""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;; |
| 291 |
*) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'." |
| 292 |
esac |
| 293 |
# |
| 294 |
# 2) Priority |
| 295 |
# |
| 296 |
PATTERN=">Priority:" |
| 297 |
PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP` |
| 298 |
case "$PRIORITY" in |
| 299 |
""|low|medium|high) CNT=`expr $CNT + 1` ;; |
| 300 |
*) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'." |
| 301 |
esac |
| 302 |
# |
| 303 |
# 3) Class |
| 304 |
# |
| 305 |
PATTERN=">Class:" |
| 306 |
CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP` |
| 307 |
case "$CLASS" in |
| 308 |
""|install-bug|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;; |
| 309 |
*) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'." |
| 310 |
esac |
| 311 |
|
| 312 |
# |
| 313 |
# 4) Synopsis |
| 314 |
# |
| 315 |
VALUE=`grep "^>Synopsis:" $TEMP | sed 's/>Synopsis:[ ]*//'` |
| 316 |
case "$VALUE" in |
| 317 |
"$SYNOPSIS_C") echo "$COMMAND: \`$VALUE' is not a valid value for \`Synopsis'." ;; |
| 318 |
*) CNT=`expr $CNT + 1` |
| 319 |
esac |
| 320 |
|
| 321 |
test $CNT -lt 4 && |
| 322 |
echo "Errors were found with the problem report." |
| 323 |
|
| 324 |
|
| 325 |
# Check if subject of mail was changed, if not, use Synopsis field |
| 326 |
# |
| 327 |
subject=`grep "^Subject" $TEMP| sed 's/^Subject:[ ]*//'` |
| 328 |
if [ X"$subject" = X"$SUBJECT_C" -o X"$subject" = X"$SYNOPSIS_C" ]; then |
| 329 |
subject=`grep Synopsis $TEMP | sed 's/>Synopsis:[ ]*//'` |
| 330 |
sed "s/^Subject:[ ]*.*/Subject: $subject/" $TEMP > $TEMP.tmp |
| 331 |
mv -f $TEMP.tmp $TEMP |
| 332 |
fi |
| 333 |
|
| 334 |
while :; do |
| 335 |
$ECHON1 "a)bort, e)dit or s)end? $ECHON2" |
| 336 |
read input |
| 337 |
case "$input" in |
| 338 |
a*) |
| 339 |
echo "$COMMAND: problem report saved in $HOME/dead.argusclientbug." |
| 340 |
cat $TEMP >> $HOME/dead.argusclientbug |
| 341 |
xs=1; exit |
| 342 |
;; |
| 343 |
e*) |
| 344 |
eval $EDIT $TEMP |
| 345 |
continue 2 |
| 346 |
;; |
| 347 |
s*) |
| 348 |
break 2 |
| 349 |
;; |
| 350 |
esac |
| 351 |
done |
| 352 |
done |
| 353 |
# |
| 354 |
# Remove comments and send the problem report |
| 355 |
# (we have to use patterns, where the comment contains regex chars) |
| 356 |
# |
| 357 |
# /^>Originator:/s;$ORIGINATOR;; |
| 358 |
sed -e " |
| 359 |
/^SEND-PR:/d |
| 360 |
/^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;; |
| 361 |
/^>Confidential:/s;<.*>;; |
| 362 |
/^>Synopsis:/s;$SYNOPSIS_C;; |
| 363 |
/^>Severity:/s;<.*>;; |
| 364 |
/^>Priority:/s;<.*>;; |
| 365 |
/^>Class:/s;<.*>;; |
| 366 |
/^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;; |
| 367 |
/^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;; |
| 368 |
/^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;; |
| 369 |
/^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;; |
| 370 |
/^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;; |
| 371 |
" $TEMP > $TEMP.x |
| 372 |
|
| 373 |
if $MAIL_AGENT < $TEMP.x |
| 374 |
then |
| 375 |
echo "$COMMAND: problem report sent" |
| 376 |
xs=0; exit |
| 377 |
else |
| 378 |
echo "$COMMAND: mysterious mail failure, report not sent." |
| 379 |
echo "$COMMAND: problem report saved in $HOME/dead.argusclientbug." |
| 380 |
cat $TEMP >> $HOME/dead.argusclientbug |
| 381 |
fi |
| 382 |
|
| 383 |
exit 0 |