Whamcloud - gitweb
LU-9019 mdt: use 64-bit timestamps for rename stats
[fs/lustre-release.git] / debian / linux-patch-lustre.unpatch
1 #! /bin/bash
2 set -x
3
4 if ! [ -d kernel -a -d Documentation ]
5 then
6     echo >&2 "Not in kernel top level directory. Exiting"
7     exit 1
8 fi
9 TOPPATCHDIR=/usr/src/kernel-patches/lustre
10 ARCHITECTURE=`dpkg --print-installation-architecture`
11
12 QUILT="quilt --quiltrc /dev/null"
13 export QUILT_PATCHES="$TOPPATCHDIR/patches"
14
15 if ! [ -f debian/APPLIED_all_lustre ]; then
16   echo >&2 "Lustre patch not applied."
17   exit 0
18 fi
19 VERSION=$(grep ^VERSION Makefile 2>/dev/null | \
20         sed -e 's/[^0-9]*\([0-9]*\)/\1/')
21 PATCHLEVEL=$( grep ^PATCHLEVEL Makefile 2>/dev/null | \
22         sed -e 's/[^0-9]*\([0-9]*\)/\1/')
23 SUBLEVEL=$(grep ^SUBLEVEL Makefile 2>/dev/null | \
24         sed -e 's/[^0-9]*\([0-9]*\)/\1/')
25 #EXTRAVERSION=$(grep ^EXTRAVERSION Makefile | head -1 2>/dev/null | \
26 #        sed -e 's/EXTRAVERSION =[       ]*\([^  ]*\)$/\1/')
27 #KERNELBRANCHLET=${VERSION}.${PATCHLEVEL}.${SUBLEVEL}
28 #KERNELRELEASE=${KERNELBRANCHLET}${EXTRAVERSION}
29 KERNELRELEASE=${VERSION}.${PATCHLEVEL}.${SUBLEVEL}
30
31 # Check for depends on lustre
32 if grep -l "^DEPENDS=.*[' ]all/unpatch/lustre[' ]" debian/APPLIED_* >/dev/null 2>/dev/null; then
33     # There are patches depending on this one, to be removed before.
34     # the dep will be removed by the last of those other patches.
35     echo >&2 "NOT unpatching \"Lustre Filesystem patch for the Linux kernel\" since other patches still rely on it"
36     exit 0
37 fi
38
39 if ! [ -d debian/APPLIED_all_lustre_tmp/.pc.lustre ]; then
40   cat >&2 <<EOF
41 ERROR: .pc directory missing for unpatching. I strongly suggest
42 you remove this kernel tree and unpack a clean one.
43 EOF
44   exit 1
45 fi
46
47 if ! [ -e debian/APPLIED_all_lustre_tmp/series.lustre ]; then
48   cat >&2 <<EOF
49 ERROR: series file missing for unpatching. I strongly suggest
50 you remove this kernel tree and unpack a clean one.
51 EOF
52   exit 1
53 fi
54
55 cleanup() {
56   echo >&2 Cleaning up
57   if [ -e series ]; then
58     echo >&2 Removing series file
59     rm series
60   fi
61   if [ -e debian/APPLIED_all_lustre_tmp/series.orig ]; then
62     echo >&1 Restoring orig series file
63     mv debian/APPLIED_all_lustre_tmp/series.orig series
64   fi
65   if [ -e .pc ]; then
66     echo >&2 Removing .pc dir
67     rm -r .pc
68   fi
69   if [ -e debian/APPLIED_all_lustre_tmp/.pc.orig ]; then
70     echo >&2 Restoring orig .pc dir
71     mv debian/APPLIED_all_lustre_tmp/.pc.orig .pc
72   fi
73 }
74
75 if [ -e series ]; then
76   echo >&2 Preserving existing series file
77   mv series debian/APPLIED_all_lustre_tmp/series.orig
78 fi
79 if [ -e .pc ]; then
80   echo >&2 Preserving existing .pc dir
81   mv .pc debian/APPLIED_all_lustre_tmp/.pc.orig
82 fi
83
84 trap cleanup EXIT
85
86 echo >&2 Restoring lustre quilt
87 mv debian/APPLIED_all_lustre_tmp/series.lustre series
88 mv debian/APPLIED_all_lustre_tmp/.pc.lustre .pc
89
90 echo >&2 Unpatching lustre patches
91 $QUILT pop -a
92 ERR=$?
93 if ! [ $ERR = 0 ]; then
94   cat >&2 <<EOF
95 ERROR: Lustre patches failed to unpatch. I strongly suggest
96 you remove this kernel tree and unpack a clean one.
97 EOF
98   cleanup
99   exit $ERR
100 fi
101
102 echo >&2 Removing lustre quilt
103 rm -rf .pc series
104 cleanup
105 rm debian/APPLIED_all_lustre debian/image.d/register-lustre
106
107 echo >&2 "\"Lustre Filesystem patch for the Linux kernel\" patch for $KVERSION removed successfully"
108
109 echo >&2 "Removing empty files:"
110 # make an exception for ./debian, or else the stamp files will go too.
111 find . -path ./debian -prune -o \
112        -type f -size 0 ! -name 'APPLIED*' -exec rm {} \; -print
113 echo >&2 "Done."
114
115 rmdir debian/image.d debian/APPLIED_all_lustre_tmp || true
116
117 echo >&2 "END unpatching lustre patch"