Whamcloud - gitweb
- tagging RC_CURRENT
[fs/lustre-release.git] / lustre / kernel_patches / scripts / pstatus
1 #!/bin/sh
2
3 # print out patch status.  Usage: pstatus [ patchfile ... ]
4 #
5 # Stephen Cameron <steve.cameron@hp.com>
6 #
7
8 . patchfns >/dev/null || . /usr/lib/patch-scripts/patchfns >/dev/null || { \
9         echo "Impossible to find my library 'patchfns'."
10         echo "Check your install, or go to the right directory"
11         exit 1
12 }
13
14 if [ ! -f ./series ]
15 then
16         echo "./series does not exist." 1>&2
17         exit 1
18 fi
19
20 if [ ! -d ./patches ]
21 then
22         echo "Directory ./patches does not exist." 1>&2
23         exit 1
24 fi
25
26
27 PATCHLIST="$*"
28 if [ "$PATCHLIST" = "" ]
29 then
30         series_optimize=yes
31         PATCHLIST=`cat series | sed -e 's/[.]patch[     ]*$//'`
32         SORTSERIES=`mktemp /tmp/ser.XXXXXX` || exit 1 
33         SORTPATCHES=`mktemp /tmp/pat.XXXXXX` || exit 1
34         sed -e 's/^[    ]//' -e 's/[.]patch[    ]*$//' < series | \
35                 sort > $SORTSERIES 
36         exists="`echo $P/patches/*.patch 2>/dev/null`"
37         if [ "$exists" != "$P/patches/*.patch" ]
38         then
39                 ls -1 $P/patches/*.patch | sed -e 's/^.*\/patches\///' \
40                         -e 's/[.]patch[         ]*$//' | sort > $SORTPATCHES
41                 PATCHLIST="$PATCHLIST"" `comm -1 -3 $SORTSERIES $SORTPATCHES`"
42         fi
43         rm -f $SORTPATCHES $SORTSERIES
44 else
45         series_optimize=no
46 fi
47
48 NSERIES=`wc -l series | awk '{ print $1; }'`
49 series=1
50 for PATCH_NAME in $PATCHLIST 
51 do
52         PATCH_NAME=$(stripit $PATCH_NAME)
53         # see if this patch even exists
54         if [ ! -f $P/patches/"$PATCH_NAME".patch ]
55         then
56                 echo "$PATCH_NAME does not exist."
57                 continue
58         fi
59         # see if this patch is applied
60         applied="-"
61         if [ -f applied-patches ]
62         then 
63                 grep '^'"$PATCH_NAME"'$' applied-patches > /dev/null
64                 if [ "$?" = "0" ]
65                 then
66                         applied="a"
67                 fi
68         fi
69
70         # figure the status of this patch, that is, 
71         # if it needs changelog, pcpatch, refpatch
72
73         stat=""
74         if [ ! -f $P/txt/"$PATCH_NAME".txt ]
75         then
76                 stat="changelog "
77         fi
78         if [ ! -f $P/pc/"$PATCH_NAME".pc ]
79         then
80                 stat="$stat""pcpatch "
81         elif [ "$applied" != '-' ]
82         then
83                 rpatch=n
84
85                 # for each file this patch touches
86                 for y in `cat $P/pc/"$PATCH_NAME".pc`
87                 do
88                         # is the patch adding the file?
89                         if [ ! -e "$y"'~'"$PATCH_NAME" -a -f "$y" ]
90                         then
91                                 # file is newer than the patch?
92                                 if [ "$y" -nt $P/patches/"$PATCH_NAME".patch ]
93                                 then
94                                         rpatch=y
95                                         stat="$stat""refpatch "
96                                         break
97                                 fi
98                         else
99                                 # modified file is newer than the patch?
100                                 if [ "$y"'~'"$PATCH_NAME" -nt \
101                                         $P/patches/"$PATCH_NAME".patch ]
102                                 then
103                                         rpatch=y
104                                         stat="$stat""refpatch "
105                                         break
106                                 fi
107                                 if [ "`toppatch`" = "$PATCH_NAME" -a \
108                                         "$y" -nt $P/patches/"$PATCH_NAME".patch ]
109                                 then
110                                         # toppatch, so check if the file 
111                                         # is newer than the patch?
112                                         rpatch=y
113                                         stat="$stat""refpatch "
114                                         break
115                                 fi
116                         fi
117                 done
118         fi
119         # check if they changed the changelog recently
120         if [ "$rpatch" = "n" -a -f $P/txt/"$PATCH_NAME".txt \
121                 -a $P/txt/"$PATCH_NAME".txt -nt \
122                 $P/patches/"$PATCH_NAME".patch ]
123         then
124                 rpatch=y
125                 stat="$stat""refpatch "
126         fi
127         if [ "$stat" != "" ]
128         then
129                 stat="Needs ""$stat"
130         fi
131
132         if [ "$series_optimize" != "yes" ]
133         then
134                 # have to find the series number the hard way.
135                 series=`grep -n '^'"$PATCH_NAME"'\.patch$' series |\
136                         awk -F: '{ printf "%d", $1}' `
137                 if [ "$series" = "" ]
138                 then
139                         series="?"
140                 fi
141         fi
142
143         echo "$series":"$applied":"$PATCH_NAME $stat"
144
145         if [ "$series_optimize" = "yes" ]
146         then
147                 if [ "$series" != "?" ]
148                 then
149                         series=`expr $series + 1`
150                         if [ $series -gt $NSERIES ]
151                         then 
152                                 series="?"
153                         fi
154                 fi
155         fi
156 done