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