Cross Reference: /solaris-desktop/scripts/reorder-patches
reorder-patches revision 8055
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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 () {
6260N/A mv $1 $2
8055N/A svn rename $1 $2
6260N/A if [ -f ../$3.spec ]; then
6260N/A perl -pi -e "s/Patch(.*):(\s*)$1/Patch\$1:\$2$2/" ../$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