Whamcloud - gitweb
- bring in akpm's patch management scripts and a first cut at
[fs/lustre-release.git] / lustre / kernel_patches / prepare_tree.sh
1 #!/bin/bash
2
3 die() {
4         echo -e $* >&2
5         echo aborting.. >&2
6         exit 1
7 }
8
9 canon() {
10         cd $1
11         CANON=$PWD
12         cd -
13 }
14
15 canon $(dirname $0)
16 MYDIR=$CANON
17
18 while [ ${#*} -gt 1 ]; do
19         case "$1" in
20                 -t)
21                         shift;
22                         TREE=$1
23                         ;;
24                 -s)
25                         shift;
26                         SERIES=$1
27                         ;;
28                 *)
29                         die "unknown argument $1"
30                         break;
31                         ;;
32         esac
33         shift;
34 done
35
36 [ -z "$TREE" -o -z "$SERIES" ] && die "I need a tree and series:\n\t$0 -t kernel_dir -s series_name"
37 [ ! -d $TREE ] && die "kernel tree '$TREE' isn't a directory"
38 SERIES=$(basename $SERIES)
39 [ ! -f $MYDIR/series/$SERIES ] && die "no series file '$SERIES'"
40
41 canon $TREE
42 TREE=$CANON
43
44 # patch scripts wants a relative path from the linux tree to
45 # its patch pile :(
46
47 MY=$(echo $MYDIR | sed -e 's_^/__')
48 TR=$(echo $TREE | sed -e 's_^/__')
49
50 while true ; do
51         M=$(echo $MY | cut -d/ -f 1)
52         T=$(echo $TR | cut -d/ -f 1)
53
54         if [ $M != $T ]; then
55                 break;
56         fi
57
58         MY=$(echo $MY | cut -d/ -f 2-)
59         TR=$(echo $TR | cut -d/ -f 2-)
60 done
61
62 [ $MY == $MYDIR ] && die "bad! $MY == $MYDIR" 
63
64 REVERSE=$(revpath $TR)${MY}
65 ABSINO=$(stat $MYDIR | awk '($3 == "Inode:") {print $4}')
66 REVINO=`(cd $TREE ; stat $REVERSE | awk '($3 == "Inode:") {print $4}')`
67
68 [ $ABSINO != $REVINO ] && die "inodes differ, my reverse path is bad?"
69
70 echo export PATCHSCRIPTS=$REVERSE
71
72 cd $TREE
73 ln -sf $REVERSE/series/$SERIES series
74
75 PATH_ELEMENTS=$(echo $PATH | sed -e 's/:/ /g')
76
77 NEW_PATH=$MYDIR/scripts
78
79 for p in $PATH_ELEMENTS; do
80         if echo $p | grep kernel_patches/scripts > /dev/null 2>&1 ; then
81                 continue;
82         fi
83         NEW_PATH="$NEW_PATH:$p"
84 done
85
86 echo export PATH=$NEW_PATH
87
88 echo "'$TREE' successfully setup" >&2