6260N/A#!/bin/bash
6260N/A
6260N/Aget_pnum () {
6260N/A echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\2/'
6260N/A}
6260N/A
6260N/Aget_comp () {
6260N/A echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\1/'
6260N/A}
6260N/A
6260N/Aget_pname () {
6260N/A echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\3/'
6260N/A}
6260N/A
6260N/Arename () {
8055N/A svn rename $1 $2
10143N/A if [ -f ../base-specs/$3.spec ]; then
10143N/A perl -pi -e "s/Patch(.*):(\s*)$1/Patch\$1:\$2$2/" ../base-specs/$3.spec
6260N/A else
6260N/A echo "WARNING: $3.spec not found"
6260N/A fi
6260N/A}
6260N/A
6260N/A# ask "question" variable_name "default answer"
6260N/Aask () {
6260N/A echo -n "$1"
6260N/A if [ ! -z $3 ]; then
6260N/A echo -n " [$3]: "
6260N/A else
6260N/A echo -n ": "
6260N/A fi
6260N/A
6260N/A read -e val
6260N/A if [ "x$val" = x ]; then
6260N/A eval "$2=\"$3\""
6260N/A else
6260N/A eval "$2=\"$val\""
6260N/A fi
6260N/A}
6260N/A
6260N/A# ask_yes_no "question" variable_name "default answer"
6260N/Aask_yes_no () {
6260N/A yes_no_repeat=yes
6260N/A while [ $yes_no_repeat = yes ]; do
6260N/A yes_no_repeat=no
6260N/A ask "${@}"
6260N/A eval "the_ans=\"\$$2\""
6260N/A case "$the_ans" in
6260N/A [yY]|[yY][eE][sS] )
6260N/A eval "$2=yes"
6260N/A ;;
6260N/A [nN]|[nN][oO] )
6260N/A eval "$2=no"
6260N/A ;;
6260N/A * )
6260N/A echo "Please answer yes or no"
6260N/A yes_no_repeat=yes
6260N/A esac
6260N/A done
6260N/A}
6260N/A
6260N/Ausage () {
6260N/A echo "Usage: $0 [options] [component...]"
6260N/A echo
6260N/A echo "Run this script in the patches subdirectory to reorder"
6260N/A echo "the patch numbers to be continuous and starting from 01"
6260N/A echo
6260N/A echo "If no components are specified, it'll check all of them."
6260N/A echo "It does not change the Patch<n> and %patch<n> numbers"
6260N/A echo "in the spec files, but updates the file names with the"
6260N/A echo "new patch numbers."
6260N/A echo
6260N/A echo "Options:"
6260N/A echo
6260N/A echo " -f, --force don't ask for confirmation"
6260N/A echo " -h, --help print this usage info"
6260N/A}
6260N/A
6260N/AFORCE=0
6260N/Awhile [ $# -gt 0 ]; do
6260N/A case $1 in
6260N/A -f|--force )
6260N/A FORCE=1
6260N/A ;;
6260N/A -h|--help )
6260N/A usage
6260N/A exit 0
6260N/A ;;
6260N/A -* )
6260N/A echo "Unknown option: $1"
6260N/A usage
6260N/A exit 1
6260N/A ;;
6260N/A * )
6260N/A break
6260N/A esac
6260N/Adone
6260N/A
6260N/Amybasename=$(basename $(pwd))
6260N/A
6260N/Aif [ $mybasename != patches ]; then
6260N/A echo "Run this script in the patches subdirectory"
6260N/A exit 1
6260N/Afi
6260N/A
6260N/Aif [ $# -gt 0 ]; then
6260N/A PLIST=
6260N/A for comp in $*; do
6260N/A comp_PLIST=$(eval echo $comp-[0-9][0-9]-*.diff)
6260N/A n_p_1st=$(echo $comp_PLIST | cut -f1 -d' ')
6260N/A if [ -f $n_p_1st ]; then
6260N/A PLIST="$PLIST $comp_PLIST"
6260N/A else
6260N/A echo "No patches found for component $comp"
6260N/A fi
6260N/A done
6260N/Aelse
6260N/A PLIST=$(eval echo *-[0-9][0-9]-*.diff)
6260N/Afi
6260N/A
6260N/Aprev_comp=xxNoNexx
6260N/Apatches_renamed=0
6260N/Afor patch in $PLIST; do
6260N/A comp=`get_comp $patch`
6260N/A pnum=`get_pnum $patch`
6260N/A pname=`get_pname $patch`
6260N/A
6260N/A if [ $comp != $prev_comp ]; then
6260N/A ord=01
6260N/A if [ $prev_comp != xxNoNexx -a $patches_renamed = 0 ]; then
6260N/A echo "No patches need renumbering for component $prev_comp"
6260N/A fi
6260N/A patches_renamed=0
6260N/A else
6260N/A ord=`expr $ord + 1`
6260N/A ord=`echo 0$ord | sed -e 's/.*\(..\)$/\1/'`
6260N/A fi
6260N/A
6260N/A if [ $pnum != $ord ]; then
6260N/A if [ $FORCE = 0 ]; then
6260N/A ask_yes_no "Rename $patch to $comp-$ord-$pname?" ans "yes"
6260N/A if [ $ans = yes ]; then
6260N/A rename $patch $comp-$ord-$pname $comp
6260N/A fi
6260N/A else
6260N/A rename $patch $comp-$ord-$pname $comp
6260N/A fi
6260N/A fi
6260N/A prev_comp=$comp
6260N/Adone
6260N/Aif [ $prev_comp != xxNoNexx -a $patches_renamed = 0 ]; then
6260N/A echo "No patches need renumbering for component $prev_comp"
6260N/Afi