Whamcloud - gitweb
LU-3208 tests: Fix typo in replay-single/70b
[fs/lustre-release.git] / lustre / kernel_patches / scripts / rpatch
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 # do_remove()
10 # {
11 #       if patch -R -p1 -s -i $P/patches/"$1".patch
12 #       then
13 #               true
14 #       else
15 #               echo SOMETHING WENT WRONG
16 #               exit 1
17 #       fi
18 # }
19
20 do_remove()
21 {
22         FILES=$(cat $P/pc/$1.pc)
23         for file in $FILES ; do
24             base_dir=`pwd`      
25             if [ -L "$file"~"orig" ]; then
26                 if [ `readlink "$file"~"orig"` = "$base_dir/""$file"~"$1" ]; then
27                     rm -rf "$file"~"orig"
28                 fi
29             fi 
30             if [ -f "$file"~"$1" ]; then
31                 mv -f "$file"~"$1" "$file"
32             else
33                 rm -f "$file"
34             fi
35         done
36         true
37 }
38
39 kill_old_ones()
40 {
41         FILES=$(cat $P/pc/$1.pc)
42         for file in $FILES
43         do
44                 rm -f "$file"~"$1"
45         done
46 }
47
48 usage()
49 {
50         echo "Usage: rpatch patchname"
51         exit 1
52 }
53
54 if [ $# == 0 ]
55 then
56         usage
57 fi
58
59 PATCH_NAME=$(stripit $1)
60
61 warn_top_current
62 if is_applied "$PATCH_NAME"
63 then
64 #       if can_remove "$PATCH_NAME"
65 #       then
66                 if [ ! -f $P/pc/$PATCH_NAME.pc ]; then
67                         exit 1
68                 fi
69                 do_remove "$PATCH_NAME"
70                 kill_old_ones "$PATCH_NAME"
71                 remove_from_db "$PATCH_NAME"
72 #       else
73 #               echo "$PATCH_NAME" does not remove cleanly
74 #               exit 1
75 #       fi
76 else
77         echo "$PATCH_NAME" is not applied
78         exit 1
79 fi
80
81 top=$(top_patch)
82 if [ x"$top" == x ]
83 then
84         msg="no patches applied"
85 else
86         msg="now at $top"
87 fi
88
89 echo Removed $PATCH_NAME, $msg
90