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