Whamcloud - gitweb
- tagging RC_CURRENT
[fs/lustre-release.git] / lustre / kernel_patches / scripts / apatch
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 do_apply()
9 {
10         FILES=$(cat $P/pc/$PATCH_NAME.pc)
11         for file in $FILES
12         do
13                 copy_file_to_bup $file $PATCH_NAME
14         done
15
16         silent=-s
17         if [ $opt_force != 0 ]
18         then
19                 silent=
20         fi
21
22         if patch -p1 $silent -i "$1" || [ $opt_force != 0 ]
23         then
24                 true
25         else
26                 echo SOMETHING WENT WRONG
27                 exit 1
28         fi
29 }
30
31 add_to_db()
32 {
33         basename "$1" >> "$DB"
34 }
35
36 usage()
37 {
38         echo "Usage: apatch patchname"
39         exit 1
40 }
41
42 opt_force=0
43 PATCH_NAMES=""
44
45 for i in $*
46 do
47         case "$i" in
48         -f)
49                 opt_force=1;;
50         *)
51                 PATCH_NAMES="$PATCH_NAMES $i"
52         esac
53 done
54
55 if [ x"$PATCH_NAMES" == x ]
56 then
57         usage
58 fi
59
60 apatch()
61 {
62         PATCH_NAME=$(stripit $1)
63
64         need_file_there $P/pc/$PATCH_NAME.pc
65
66         if is_applied "$PATCH_NAME"
67         then
68                 echo "$PATCH_NAME" is already applied
69                 exit 1
70         fi
71         
72         if [ $opt_force != 0 ]
73         then
74                 echo FORCING PATCH
75         fi
76
77         if [ $opt_force != 0 ] || can_apply $P/patches/"$PATCH_NAME".patch
78         then
79                 check_pc_match $P/patches/"$PATCH_NAME".patch $P/pc/"$PATCH_NAME".pc 
80                 do_apply $P/patches/"$PATCH_NAME".patch
81                 add_to_db "$PATCH_NAME"
82                 echo applied $PATCH_NAME
83                 echo
84         else
85                 echo "$PATCH_NAME" does not apply
86                 exit 1
87         fi
88 }
89
90 for i in $PATCH_NAMES
91 do
92         if ! apatch $i
93         then
94                 exit 1
95         fi
96 done
97