Re: I need your shell expertise.



I have hacked at the script a bit, and have removed all the bashisms I
could find (well I got it to run correctly using ash on my linux box).

It no longer looks up the debian package database for information.  Now it
tries to call a program in the package with the --version argument to work
out what version of a package is installed.

It also tries to send relevant config files with the report.  This also
needs to be thought out a little more, as it requires the bug script to be
updated as packages change.  (Also the config files may not be that useful
-- I am not sure what to do).

As with the original debian bug script, you can pass the -p argument to
get it to just print the report (for debugging purposes), or -d to send it
to your local machine instead of bugs.gnome.org.

These changes probably make the script more portable, but it still needs
to be tested a bit.

James Henstridge.

--
Email: james@daa.com.au
WWW:   http://www.daa.com.au/~james/


On Wed, 3 Feb 1999, Miguel de Icaza wrote:

> 
> Hello guys,
> 
>    I have this program for reporting bugs to the bug tracking system
> that Vincent sent me from Debian.  It is a bash2 script, and we need
> this to work on bash1 and regular /bin/sh.
> 
>    So I need someone that knows shell to help us converting this
> program to regular shell and adapt it from its debian roots to the
> gnome setup (basically, replace "Debian" with "GNOME" and use
> bugs.gnome.org as the machine that drives the bug tracking system).
> 
>    Here is the program.
> 
> best wishes,
> Miguel.
> 
#!/bin/sh
#
# gnome-bug 1.0: Generates a bug report (based on debian bug 3.1.7)
#
# Christoph Lameter, October 26, 1996
#
# Modified by Nicolás Lichtmaier
#
# Modified by James Henstridge (4-Feb-1999) for GNOME use, to remove
#   need for bash and to make it less debian centric.
#

# a new line character
nl='
'
# find out if echo -n works ...
if echo -n testing | sed s/-n/xn/ | grep xn > /dev/null; then
    echo_n=echo
else
    echo_n="echo -n"
fi

# deduce email address ...
if [ -n "$EMAIL" ]; then
    CC="$EMAIL"
else
    if [ -f /etc/mailname ]; then
	host=`cat /etc/mailname`
    else
	host=`hostname`
    fi
    CC="`id -un`"
    CC=`sed -ne "s/^$CC:[^:]*:[^:]*:[^:]*:\\([^,:]*\\),*:.*/\\1/p" \
	< /etc/passwd`" <$CC@$host>"
fi

FROM="$CC"
if [ "`which realpath 2> /dev/null`" = "" ]; then
    REALPATH=realp
else
    REALPATH=realpath
fi

realp()
{
    fname="$1"
    # follow link
    while [ -L "$fname" ]; do
	fname="`ls -l $fname`"
	fname=`echo "$fname" | sed 's/^.*> //'`
    done
    echo $fname
}

sendhelp()
{
echo "bug v3.1.7"
echo "Usage: $1 [options] <packagename> [<text>]
A script to ease the reporting of bugs.

Options:
    -c        Do  not  include  configuration  files  in  the bug
              report.
    -d        Debug.  Dont send the mail to the bug tracking sys­
              tem, send it to postmaster@localhost instead.
    -f        <packagename> is a file belonging to the package
              and bug will search for it.
    -H special_header
              Adds  a  custom  header  to  generated mail. Can be
              repeated to add multiple custom headers.
    -m        Submit a \"maintonly\" bug report. Only sent  to  the
              maintainer not to the mailing list.
    -p        print. Do not send the bug report instead output it
              on stdout so that it can be redirected into a file.
    -q        Submit a quiet bug report (Just register. No e-mail
              forwarding to anyone)
    -s text   Set the Subject of the bug  report.  Otherwise  bug
              will ask for a short description of the problem.
    -x        Do not send a CC to the submitter of the bugreport
    -h        Shows this text.

Please don't report several unrelated bugs - especially ones in
different packages - in one message."
	exit 0
}

if [ "$1" = "--help" ]; then sendhelp ; fi

while [ $# -ne 0 ]; do
    arg=$1

    case "$arg" in
	-c) NOCONFIG=1 ;;
	-d) DEBUG=1 ;;
	-f) SEARCH=1 ;;
	--help) sendhelp $0 ;;
	-h) sendhelp $0 ;;
	-H) if [ $# -lt 2 ]; then
		echo "-H requires an argument" >&1
		exit 1
	    fi
	    if [ -z "$CUSTOM_HEADER" ]; then
		CUSTOM_HEADER="$2"
	    else
		CUSTOM_HEADER="$CUSTOM_HEADER$nl$2"
	    fi
	    shift ;;
	-m) MAINT=1 ;;
	-p) PRINT=1 ;;
	-q) QUIET=1 ;;
	-s) if [ $# -lt 2 ]; then
		echo "-s requires an argument" >&1
		exit 1
	    fi
	    SUBJECT="$2"
	    shift ;;
	-v) echo "gnome-bug 1.0" >&2
	    exit 1 ;;
	-x) CC="" ;;
	--) break ;;
	-*) echo "Usage: $0 [options] <packagename> [<text>] ..." >&2
	    exit 1 ;;
	*)  break;
    esac

    shift
done

PACKAGE="$1"
shift || :

if [ "`id -u`" = "0" ]; then
    echo "$0: Filing bug reports with superuser priviledges is insecure and not supported." >&2
    exit 1
fi

# XXXX FIXME: how should the search bit work.  We can't use dpkg's database,
# since this script has to be useful on more than just debian.
if [ "$SEARCH" ]; then
	echo "Search not supported."
	exit 1
#	if [ -z "$PACKAGE" ]; then
#		echo "$0: Must specify file name when using -f." 2>&2
#		exit 1
#	fi
#	FILE=`$REALPATH "$PACKAGE"`
#	test "$PRINT" || echo -n "Searching for package containing ${FILE}..."
#	if [ "$FILE" = "" ]; then
#		echo
#		echo "$0: Must include parameter when using -f." 2>&2
#		exit 1
#	fi
#	if [ ! -e "$FILE" ]; then
#		echo
#		echo "$0: File \`$FILE' not found." 2>&2
#		exit 1	
#	fi
#	PACKAGE=`grep -l ^${FILE}\$ /var/lib/dpkg/info/*.list | head -1`
#	if [ -z "$PACKAGE" ]; then
#		echo
#		echo "$0: File \`$FILE' can't be found in any installed package." >&2
#		exit 1
#	fi
#       PACKAGE=`echo $PACKAGE | sed -e 's/^.*\///' -e 's/\.list$//'`
#	test "$PRINT" || echo "done."
#	if [ -z "$PRINT" ]; then
#		echo "\`$FILE' found in package \`$PACKAGE'"
#		read -ep "Submit bug for this package? [Y|n] "
#		if [ "${REPLY:0:1}" = "${YESNO:2:1}" -o "${REPLY:0:1}" = "${YESNO:3:1}" ]; then
#			exit 0
#		fi
#	fi
fi

if [ "$PACKAGE" = "" ]; then
    echo "Please state in which package you have found a problem, or...
type one of these bug categories:

general          General problems
bugs.gnome.org   Bug tracking system
lists.gnome.org  Gnome mailing lists
www.gnome.org    Gnome web site"
    echo
    $echo_n "package? "
    read  PACKAGE
    if [ "$PACKAGE" = "" ]; then
	echo "Canceled!"
	exit 0
    fi
fi

case "$PACKAGE" in
    *\ *)
	echo "$0: Package name goes first, bug report last." >&2
	exit 1 ;;
    *)  ;;
esac

case "$PACKAGE" in
    *[A-Z]*)
	echo "$0: Package name shouldn't have upper case letters in it" >&2
	exit 1 ;;
    *) ;;
esac

# check if package name characters are OK
if [ -n "`echo $PACKAGE | sed s/[-a-z0-9.+]//g`" ]; then
    echo "$0: Invalid package name." >&2
    exit 1
fi

if [ "$EDITOR" = "" ]; then
    EDITOR="$VISUAL"
    if [ "$EDITOR" = "" ]; then
	if [ -x /usr/bin/editor ]; then
	    EDITOR="`$REALPATH /usr/bin/editor`"
	else
	    if [ "`which vi 2>/dev/null`" = "" ]; then
		echo "$0: Cannot locate a texteditor." >&2
		exit 1
	    fi
		EDITOR="vi"
	fi
    fi
fi

setversion()
{
    case "$PACKAGE" in
	gnome-libs)
	    if [ -n "`which gnome-config 2>/dev/null`" ]; then
		VERSION="`gnome-config --version`"
	    fi ;;
	gnome-core)
	    if [ -n "`which pane 2>/dev/null`" ]; then
		VERSION="`panel --version | sed s/panel/core/`"
	    fi ;;
	mc|gmc)
	    if [ -n "`which gmc 2>/dev/null`" ]; then
		VERSION="`gmc --version`"
	    fi;;
	# XXXX FIXME: need more auto version checks in here
	*) ;;
    esac
    if [ -z "$VERSION" ]; then
	$echo_n "Enter the version of $PACKAGE you are using: "
	read VERSION
    fi
}

setsubject()
{
    if [ "$SUBJECT" = "" ]; then
	while [ "$SUBJECT" = "" ]; do
	    echo "Please describe your problems using $PACKAGE in one line."
	    read SUBJECT ;
	done
	SUBJECT="$PACKAGE: $SUBJECT"
    fi
}

template()
{
    cat <<EOF
Subject: $SUBJECT
Package: $PACKAGE
Version: $VERSION

$*

-- System Information
Kernel Version: `uname -a`
EOF
    # XXXX FIXME: how do we get useful information about other systems?
    if [ -f /etc/debian_version ]; then
	echo "Debian Release: `cat /etc/debian_version`"
    fi
    if [ -f /etc/redhat-release ]; then
	echo "Redhat Release: `cat /etc/redhat-release`"
    fi
    echo
}

configfiles()
{
    # this is a likely config filename
    echo $PACKAGE
    # XXXX FIXME: we need to know more config file names
    case "$1" in
	gnumeric) echo Gnumeric ;;
	gnome-libs) echo Gnome ;;
	gnome-core) (cd $HOME/.gnome && echo panel.d/*/panel || :)
	    echo GnomeHelp ;;
	control-center) echo control-center ;;
	gnome-pim) echo calendar GnomeCard ;;
	mc|gmc) echo mc gmc ;;
	*) ;;
    esac
}

SIGNINT=2
trap 'echo "$0 interrupted." ; rm -f $TEMPS ; exit 0' $SIGINT

#TEMP1=$(tempfile -pbug)
TEMP1=/tmp/gnome-bug-template.$$
TEMPS=$TEMP1

setversion
setsubject
template "$*" >$TEMP1

if [ -z "$NOCONFIG" ]; then
    for conf in `configfiles $PACKAGE`; do
	if [ -f $HOME/.gnome/$conf ]; then
	    echo "--- Begin ~/.gnome/$conf" >> $TEMP1
	    cat $HOME/.gnome/$conf >> $TEMP1
	    echo "--- End ~/.gnome/$conf$nl" >> $TEMP1
	fi
    done
fi

if [ -z "$PRINT" ]; then
    X=""
    while [ "$X" = "" ]; do
	TEMPBACKUP=gnome-bug-backup.$$
	TEMPS="$TEMPS $TEMPBACKUP"
	cp $TEMP1 $TEMPBACKUP
	EDNAME=`echo $EDITOR | sed -e 's/^.*\///' -e 's/ .*$//'`
	if [ "$EDNAME" = "joe" ]; then
	    IFJOE="-skiptop 1"
	    echo "Reporting bug for package: $PACKAGE $VERSION"
	    echo -ne \\033[2J\\033[1\;1H
	fi
	if [ "$EDNAME" = "joe" -o \
	    "$EDNAME" = "jed" -o \
	    "$EDNAME" = "emacs" -o \
	    "$EDNAME" = "vi" ]; then
	    EDITARGS="+5"
	fi
	$EDITOR $IFJOE $EDITARGS $TEMP1 ||
	{
	    echo "Editor Aborted: No Bug report sent"
	    rm $TEMP1 $TEMPBACKUP
	    exit 1
	}

	if cmp $TEMP1 $TEMPBACKUP >/dev/null; then
	    echo "No changes: No Bug report sent."
	    rm $TEMP1 $TEMPBACKUP
	    exit 1;
	fi
	$echo_n "Do you really want to submit this bug report? [Y|n] "
	read KEY
	case "$KEY" in
	    y|Y|yes|YES|Yes) ;;
	    *) exit 0 ;;
	esac
	rm $TEMPBACKUP
	X="`head -1 $TEMP1 | sed s/^Subject:\ //'`"
    done
    SUBJECT=$X
else
    if [ "$SUBJECT" = "" ]; then
	SUBJECT="$PACKAGE $VERSION"
    fi
fi

if [ "$PRINT" ]; then
    cat $TEMP1
    rm $TEMP1
    exit 0
fi

MADDR="submit@bugs.gnome.org"

if [ "$QUIET" ]; then
    MADDR="quiet@bugs.gnome.org"
fi

if [ "$MAINT" ]; then
    MADDR="maintonly@bugs.gnome.org"
fi

if [ "$DEBUG" ]; then
    MADDR="postmaster@localhost"
fi

{
    echo "From: $FROM"
    echo "Subject: $SUBJECT"
    echo "To: $MADDR"
    test "$CC" && echo "Bcc: $CC"
    echo "X-Mailer: bug 3.1.7"
    test "$REPLYTO" && echo "Reply-To: $REPLYTO"
    if [ -n "$CUSTOM_HEADER" ]; then
	echo "$CUSTOM_HEADER"
    fi
    echo
    sed <$TEMP1 -e "1d"
} |
{
    {
	test -x /usr/sbin/sendmail && /usr/sbin/sendmail -t
    } ||
    { 
	tee /var/tmp/${PACKAGE}.bug | grep -q zazazaz
	echo "Bug report saved in /var/tmp/${PACKAGE}.bug"
    }
}

rm $TEMP1
echo "Bug Report submitted to $MADDR $CC

If you want to submit further information about this bug please wait
to receive the bug number by e-mail. Then mail any extra information to
nnnn@bugs.gnome.org, where nnnn is the bug number."


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]