#!/bin/bash # # Stabilise an ebuild in cvs with a bug-number and ebuild-atom given # Version: 1.0 # # Copyright (C) 2007 Lars Weiler # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # Thanks to # Aron Griffis for his rc()-function # Robin H. Johnson for his earch-script # kojiro on IRC for the ebuild with Atom Version regexp # Options can alse be hardcoded in this script CVSDIR="" ARCH="" BUGZ_USER="" BUGZ_PASSWORD="" PATH=/usr/local/bin:/usr/bin:/bin die() { echo $1 > /dev/stderr exit -1 } print_usage() { echo "Usage: $(basename ${0}) [-a arch] [-c cvs-dir] [-u username]" echo " [-p password] [-y] bug-number [ebuild with Atom Version]" echo echo "Make an ebuild stable for a given arch and change the related bug." echo echo "Options:" echo " -a Set the architecture" echo " -c Path to the gentoo-x86 repository" echo " -u User name for Bugzilla" echo " -p Password for Bugzilla" echo " -q Quickrun: always choose the default answer on" echo " questions. Useful for scripting." } splitpackage() { case $1 in section) echo ${2%/*} ;; name) tmp=${2#*/} echo ${tmp%-[0-9]*} ;; ebuild) echo ${2#*/} ;; esac } # rc-function stolen from Aron Griffis in http://archives.gentoo.org/gentoo-dev/msg_122004.xml rc() { declare msg if [[ -n $* ]]; then msg="$*" echo "* Using msg from command-line" >&2 else msg=$(perl &2 return 1 fi echo "* Parsed msg from ChangeLog" >&2 fi echo "----------" >&2 echo "$msg" >&2 echo "----------" >&2 repoman commit -m "$msg" || return 1 if [[ -x /usr/bin/eviewcvs ]]; then local f entry=$(perl -00ne '/^ \d/ and print, last' ChangeLog) entry=${entry%%:*} entry=${entry##*>} entry=${entry//,/ } for f in $entry; do [[ $f == -* ]] && continue f=${f#+} echo "$f" done | xargs -n1 eviewcvs fi } ### main routine ### # get the arguments while getopts "a:c:u:p:yh" OPTION do case "${OPTION}" in a) ARCH="$OPTARG" ;; c) CVSDIR="$OPTARG" ;; u) BUGZ_USERNAME="$OPTARG" ;; p) BUGZ_PASSWORD="$OPTARG" ;; q) quickrun="y" ;; h) print_usage; exit 0 ;; esac done shift $((OPTIND -1)) if [[ $# -lt 1 ]]; then print_usage die fi # check if we have an arch given if [[ -z "$ARCH" ]]; then print_usage die "Please set your arch." fi # check for the CVSDIR if [[ -z "$CVSDIR" ]]; then print_usage die "Please set the path to your gentoo-x86 repository." fi # check the bug-number case ${1} in *[!0-9]*|"") print_usage die "Argument 1 must be a bug-number." ;; esac bugz_number=${1} # without pybugz, a second argument is mandatory if [[ -x /usr/bin/bugz ]]; then bugz=y bugz_info=$(bugz get ${bugz_number} -n) echo "${bugz_info}" if [[ $quickrun != "y" ]]; then read -p "Do you want to work on this bug? [Y/n]" BUGOK case ${BUGOK} in q|n|N) die "Quitting" ;; esac fi fi # check if a package is given with a second argument # or strip it from the bug's summary # clean out some unneeded and common extensions to the package-name if [[ $# -gt 1 ]]; then package=${2} package=${package##*[>|=|<|~]} package=${package%.ebuild} elif [[ "${bugz}" == "y" ]]; then summary=$(echo "${bugz_info}" | egrep "^Title" | cut -d: -f2) # a great regexp to match an ebuild with Atom Version package=$(egrep -o '(>=|>|=|<=|<|~)?[[:alnum:]]+-[[:alnum:]]+/[-.[:alnum:]]+' <<< ${summary}) package=${package##*[>|=|<|~]} package=${package%.ebuild} else die "No package was given or www-client/pybugz is not installed." fi # check if package exists package_section="$(splitpackage section ${package})" package_name="$(splitpackage name ${package})" ebuild="$(splitpackage ebuild ${package}).ebuild" cd "${CVSDIR}/${package_section}/${package_name}" || die "Path to ebuild does not exist." if [[ ! -e ${ebuild} ]]; then die "${ebuild} does not exist!" fi # update via cvs and remove conflicting files cvs up -CdP rm -f .\#* # show current status of all ebuilds if [[ -x /usr/bin/earch || -x /usr/local/bin/earch ]]; then PORTDIR="${CVSDIR}" earch fi # now, the workhorse, which makes my fingers happy if [[ ${quickrun} != "y" ]]; then read -p "Stabilise $(basename ${package}) for ${ARCH}? [Y/n]" STABILISE case ${STABILISE} in q|n|N) die "Quitting" ;; esac fi ekeyword ${ARCH} $(basename ${ebuild}) echangelog "Stable on ${ARCH}; bug #${bugz_number}." rc # function from above if [[ "${bugz}" == "y" ]]; then # add a comment to the bug and remove the arch if [[ -n "${BUGZ_USER}" && -n "${BUGZ_PASSWORD}" ]]; then bugz -u ${BUGZ_USER} -p ${BUGZ_PASSWORD} modify ${bugz_number} --comment="${ARCH} stable." --remove-cc=${ARCH}@gentoo.org else bugz modify ${bugz_number} --comment="${ARCH} stable." --remove-cc=${ARCH}@gentoo.org fi # show the Assignee and CCs to choose if the bug can be closed echo "* Checking bugs' Assignee and CCs" echo "${bugz_info}" | egrep "^Assignee" echo "${bugz_info}" | egrep "^CC" | grep -v "${ARCH}@gentoo.org" # strip the arch, as we don't refetch the bugs' information if [[ ${quickrun} != "y" ]]; then read -p "* Do you want to close the bug? [y/N]" BUGZCLOSE case ${BUGZCLOSE} in y|Y) if [[ -n "${BUGZ_USER}" && -n "${BUGZ_PASSWORD}" ]]; then bugz -u ${BUGZ_USER} -p ${BUGZ_PASSWORD} modify ${bugz_number} --comment="Closing, since all arches are done." --fixed else bugz modify ${bugz_number} --comment="Closing, since all arches are done." --fixed fi ;; esac fi fi # return to the path from where the script was called cd "$OLDPWD" echo "All done."