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