reorder-patches revision 6260
d42d27ead91e470cb12986d928441e56c0f543caLennart Poettering#!/bin/bash
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering
f401e48c2db22ff9d1a05885b5599bebf19c2707Lennart Poetteringget_pnum () {
f401e48c2db22ff9d1a05885b5599bebf19c2707Lennart Poettering echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\2/'
7640a5de1b3ffe6547200ad204d14e4f067caf4fLennart Poettering}
1063dc3a525a87c0285e071794317f71724492feLennart Poettering
8e1bd70d4ce6d3881c1df6a6482643a2b3a69bb1Lennart Poetteringget_comp () {
8cf3a8a982661c0bb9b04ff27f6d486b38b1b35eLennart Poettering echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\1/'
de47ca9b50e8c05c9fc116ff37794e526bddf92eLennart Poettering}
e0e1580aae5913870933518f3cb7055730ce3a49Lennart Poettering
306a7fd82e790b3c00ba5cf806ccd6c0108061b5Lennart Poetteringget_pname () {
335aa753fa60ba0bb3c9fe679c761d5f1f3b1588Lennart Poettering echo $1 | sed -e 's/^\(.*\)-\([0-9][0-9]\)-\(.*\)$/\3/'
335aa753fa60ba0bb3c9fe679c761d5f1f3b1588Lennart Poettering}
335aa753fa60ba0bb3c9fe679c761d5f1f3b1588Lennart Poettering
3b63d2d31d0850bd7a81ab9b468218d2c4c461e8Lennart Poetteringrename () {
3b63d2d31d0850bd7a81ab9b468218d2c4c461e8Lennart Poettering mv $1 $2
46574a5b4afeac0c3f69f15ce47c460309cb9becLennart Poettering cvs -q remove $1
46574a5b4afeac0c3f69f15ce47c460309cb9becLennart Poettering cvs -q add $2
46574a5b4afeac0c3f69f15ce47c460309cb9becLennart Poettering if [ -f ../$3.spec ]; then
85ed27f699939f75b8422ae67e016bdf9f439da9Lennart Poettering perl -pi -e "s/Patch(.*):(\s*)$1/Patch\$1:\$2$2/" ../$3.spec
447be1550523114f96c7f9eacb9d6a1ff6ca4197Lennart Poettering else
c7b508592b28ee1e62350f0d249856811371f631Lennart Poettering echo "WARNING: $3.spec not found"
afbf835326b0cc05c282b43f14ed501977de2004Lennart Poettering fi
4bb2357f77c875976de5e238a5783e4e136b37b5Lennart Poettering}
4bb2357f77c875976de5e238a5783e4e136b37b5Lennart Poettering
93a45c562a1989dfbb2dd08c65f8a21b02959934Lennart Poettering# ask "question" variable_name "default answer"
addab137cd8d318e4f543ca56018ee23d51aaca9Lennart Poetteringask () {
b2423f1f436f847d9fc96a63679be2b5552b6bafLennart Poettering echo -n "$1"
449ddb2d23a63ca4c8cd70d13a070fba87c1fb30Lennart Poettering if [ ! -z $3 ]; then
97c4a07df982ee967705022feaba9be33947abf0Lennart Poettering echo -n " [$3]: "
b574fa098d2827359c31a2d922b729725a8c6c8cLennart Poettering else
f61448083198dc0e4e0d19a916bcd478336cc85dLennart Poettering echo -n ": "
6e200d55ae538fc29360cdaa9863f30cdddf58f3Lennart Poettering fi
6e200d55ae538fc29360cdaa9863f30cdddf58f3Lennart Poettering
dfac97b21e00cd3617ba817227db7b621841b5ccLennart Poettering read -e val
dfac97b21e00cd3617ba817227db7b621841b5ccLennart Poettering if [ "x$val" = x ]; then
5e6afdd3d359fc42de7ac432243e98673577e81fLennart Poettering eval "$2=\"$3\""
cd6d0a456bc9c45fa79316fc5896e4a3ae75a30bLennart Poettering else
cd6d0a456bc9c45fa79316fc5896e4a3ae75a30bLennart Poettering eval "$2=\"$val\""
c24eb49e6aecd6de2ad450083e826d4c9d9c75b6Lennart Poettering fi
151b190e79e64824552e01849352ca8f6ac7dedbLennart Poettering}
# ask_yes_no "question" variable_name "default answer"
ask_yes_no () {
yes_no_repeat=yes
while [ $yes_no_repeat = yes ]; do
yes_no_repeat=no
ask "${@}"
eval "the_ans=\"\$$2\""
case "$the_ans" in
[yY]|[yY][eE][sS] )
eval "$2=yes"
;;
[nN]|[nN][oO] )
eval "$2=no"
;;
* )
echo "Please answer yes or no"
yes_no_repeat=yes
esac
done
}
usage () {
echo "Usage: $0 [options] [component...]"
echo
echo "Run this script in the patches subdirectory to reorder"
echo "the patch numbers to be continuous and starting from 01"
echo
echo "If no components are specified, it'll check all of them."
echo "It does not change the Patch<n> and %patch<n> numbers"
echo "in the spec files, but updates the file names with the"
echo "new patch numbers."
echo
echo "Options:"
echo
echo " -f, --force don't ask for confirmation"
echo " -h, --help print this usage info"
}
FORCE=0
while [ $# -gt 0 ]; do
case $1 in
-f|--force )
FORCE=1
;;
-h|--help )
usage
exit 0
;;
-* )
echo "Unknown option: $1"
usage
exit 1
;;
* )
break
esac
done
mybasename=$(basename $(pwd))
if [ $mybasename != patches ]; then
echo "Run this script in the patches subdirectory"
exit 1
fi
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