Whamcloud - gitweb
- tagging RC_CURRENT
[fs/lustre-release.git] / lustre / kernel_patches / scripts / import_patch
1 #!/bin/sh
2
3 . patchfns >/dev/null || . /usr/lib/patch-scripts/patchfns >/dev/null || { \
4         echo "Impossible to find my library 'patchfns'."
5         echo "Check your install, or go to the right directory"
6         exit 1
7 }
8
9 usage()
10 {
11         echo "usage: import_patch [ -p prefix-pattern ] patchfile [...]" 1>&2
12         exit 1
13 }
14
15 XPATTERN=""
16 if [ "$1" = "-p" ]
17 then
18         XPATTERN="$2"
19         shift; 
20         shift;
21 fi
22
23 if [ "$1" = "" ]
24 then
25         usage
26 fi
27
28 if [ ! -e applied-patches ]
29 then
30         touch applied-patches
31 fi
32
33 mkdir -p patches || exit 1
34 mkdir -p txt || exit 1
35 mkdir -p pc || exit 1
36
37 if [ ! -e ./series ]
38 then
39         touch ./series
40         if [ "$?" != "0" ]
41         then
42                 echo "Cannot create ./series" 1>&2
43                 exit 1
44         fi
45 fi
46
47 if [ ! -w ./series ]
48 then
49         echo "./series is not writable." 1>&2
50         exit 1
51 fi
52
53 PATTERN='s/^'"$XPATTERN"'//'
54 for x in $* 
55 do
56         if [ ! -r "$x" ]
57         then
58                 echo "$x does not exist, skipping." 1>&2
59                 continue
60         fi
61         patchname=`basename $x .bz2`
62         patchname=`basename $patchname .gz`
63         patchname=`basename $patchname .Z`
64         patchname=`basename $patchname .patch`
65         if is_applied $patchname
66         then
67                 echo $patchname is currently applied
68                 exit 1
69         fi
70         if [ "$XPATTERN" != "" ]
71         then
72                 patchname=`echo $patchname | sed -e "$PATTERN"`
73         fi
74         pname=$P/patches/"$patchname".patch
75         if [ -r "$pname" ]
76         then
77                 echo "$pname exists already, skipping." 1>&2
78                 continue
79         fi
80         case "$x" in
81         *.bz2) 
82                 bunzip2 < "$x" > "$pname"
83                 ;;
84         *.gz)
85                 gunzip < "$x" > "$pname"
86                 ;;
87         *.Z)    zcat < "$z" > "$pname"
88                 ;;
89         *)      
90                 cat "$x" > "$pname" || continue 
91                 ;;
92         esac
93         echo "$patchname".patch >> series
94         pcpatch "$pname"
95         extract_description < "$pname" >$P/txt/"$patchname".txt
96         grep '^[(]undescribed patch[)]$' < $P/txt/"$patchname".txt > /dev/null
97         if [ "$?" = "0" ]
98         then
99                 echo "Warning: $patchname has no description." 1>&2
100         fi
101 done
102