Gentoo bug reporter

Helps reporting Gentoo GNU/Linux package compilation errors
JCZD Gentoo Bash

gentoo-bug-reporter is a simple script that gathers useful information when a Gentoo ebuild (package) fails to build.

#!/bin/bash

echo "usage: $0 category/ebuild-version::repos"

#read -p "chmod -R a+rX /var/tmp/portage/${1}"
#read -p "chmod -R a+rwX /var/tmp/portage/${1}/temp/"

URL='http://example.com/paste/'
DEST='user@example.com:/var/www/html/paste/'	# needs to end with /

#CMD="emerge $?"

CATEGORY=`echo $1|cut -f 1 -d '/'`
EBUILD=`echo $1|cut -f 2 -d '/' | cut -f 1 -d ':'`
REPOS=`echo $1|cut -f 2 -d '/' | cut -f 3 -d ':'`
d=/tmp/$EBUILD
mkdir $d
f=$d/index.html
TITLE="Gentoo bug report for ${EBUILD}"

echo "<html><head><title>${TITLE}</title></head><body><h1>${TITLE}</h1>" >$f
echo "`LANG=C date`<br/><br/>" >>$f

echo -e "\n<h3>$ emerge -pqv =${EBUILD}::${REPOS}</h3>\n<pre>" >> $f
emerge -pqv =${EBUILD}::${REPOS} >> $f
echo -e "</pre><h3>$ emerge --info =${EBUILD}::${REPOS}</h3>\n<pre>" >> $f
emerge --info =${EBUILD}::${REPOS} >> $f
echo "</pre><h3>Other relevant files</h3><ul>" >>$f

gzip /var/tmp/portage/${CATEGORY}/${EBUILD}/temp/build.log
mv /var/tmp/portage/${CATEGORY}/${EBUILD}/temp/build.log.gz $d/
echo "<li><a href='build.log.gz'>/var/tmp/portage/${CATEGORY}/${EBUILD}/temp/build.log</a></li>" >>$f
#bpaste upload $f > /tmp/url0

gzip /var/tmp/portage/${CATEGORY}/${EBUILD}/temp/environment
mv /var/tmp/portage/${CATEGORY}/${EBUILD}/temp/environment.gz $d/
echo "<li><a href='environment.gz'>/var/tmp/portage/${CATEGORY}/${EBUILD}/temp/environment</a></li>" >>$f
#bpaste upload $f > /tmp/url1

echo "</ul></body></html>" >>$f

scp -r $d ${DEST}
#echo "Your bug report for ${EBUILD} is available at `bpaste upload $f`"
echo "Your bug report for ${EBUILD} is available at ${URL}${EBUILD}/"

rm -rf $d