#!/bin/sh # # change the >Responsible: of all non-closed reports. # Author: Hans-Albert.Schneider@mchp.siemens.de # Copyright (C) Infineon Technologies AG, 2002 # usage="usage: $0 -d gnats_root old_responsible new_responsible reason" # Check usage if [ $# -lt 5 ] then echo $usage >&2 exit 1 fi if [ "x$1" = "x-d" ] then if [ "x$2" = "x" ] then echo $usage >&2 exit 1 else gnatsroot="$2" fi else echo $usage >&2 exit 1 fi if [ "x$3" = "x" -o "x$4" = "x" -o "x$5" = "x" ] then echo $usage >&2 exit 1 fi oldresp="$3" newresp="$4" reason="$5" if [ ! -f "$gnatsroot/gnats-adm/index" ] then echo $usage >&2 echo "Cannot find index file $gnatsroot/gnats-adm/index" >&2 exit 1 fi resp_file=$gnatsroot/gnats-adm/responsible if grep "^${oldresp}:" "$resp_file" then : OK else echo "Warning: '${oldresp}' not listed in $resp_file" >&2 # No exit here; we are going to replace her/him anyway. fi if grep "^${newresp}:" "$resp_file" then : OK else echo $usage >&2 echo "Warning: New responsible '${newresp}' not listed in $resp_file" >&2 exit 1 fi pr_list=`awk '-F|' '$3 == resp && $4 != "closed" {print $1}' resp="${oldresp}" $gnatsroot/gnats-adm/index` if [ "x$pr_list" = "x" ] then echo "No reports for '${oldresp}' found." exit 0 fi echo "Responsible" | grep -i "${oldresp}" >/dev/null if [ $? -eq 0 ] then echo "Sorry, but the name of the new responsible, '${newresp}'," >&2 echo "is a substring of the word 'Responsible'." >&2 echo "This script cannot deal with that case; it would mess up" >&2 echo "your reports." >&2 echo "Please do the assignment manually." >&2 exit 2 fi # # End of usage checking # # Create a temporary file to be used as the EDITOR environment variable. # Make sure it belongs to us, and nobody else can modify it. # tmp=${TMPDIR:-/tmp}/chresp$$ [ -f "$tmp" ] && rm -f "$tmp" [ -f "$tmp" ] && echo "Cannot rm $tmp" >&2 && exit 2 touch "$tmp" || echo "Cannot create $tmp" >&2 [ -f "$tmp" ] || exit 2 chmod 700 "$tmp" cat >"$tmp" <Responsible:/ s/${oldresp}/${newresp}/'; echo w) | ed "'$1' >> "$tmp" EDITOR="$tmp" export EDITOR unset VISUAL for id in $pr_list do echo "Changing PR# $id ..." echo "$reason" | edit-pr -d "$gnatsroot" $id done rm -f "$tmp"