Whamcloud - gitweb
b=19026
[fs/lustre-release.git] / lustrecvs
1 #!/bin/bash
2
3 LC_COLLATE="C"
4 progname="${0##*/}"
5
6 warn ()
7 {
8     [ "$1" ] && echo >&2
9     [ "$1" ] && echo "$progname: $1" >&2
10     [ "$1" ] && echo >&2
11 }
12
13 fatal ()
14 {
15     warn "$2"
16     exit "$1"
17 }
18
19 usage ()
20 {
21     cat <<EOF
22 Usage: $progname <lustretag> <pindate>
23   where <lustretag> is a tag of the lustre-core module
24   and <pindate> is an optional quoted timestamp suitable for cvs -D
25 EOF
26 }
27
28 if [ -z "$LUSTRECVS_UPDATED" ] ; then
29     echo "$progname: updating lustrecvs"
30
31     # If checking out a specific tag, make sure all of the files here are also
32     # checked out with the same tag to avoid later changes breaking things.
33     case "$1" in
34     v*|b_release_*) TAG="-r $1" ;;
35     esac
36
37     cvs update -l $TAG
38     export LUSTRECVS_UPDATED=yes
39     exec "$0" "$@"
40 fi
41
42 [ "$1" = "-r" ] && shift
43
44 buildtag="HEAD"
45 lustretag="$1"
46 shift
47 pindate=$1
48 shift
49
50 if [ "$*" ] ; then
51     usage >&2
52     exit 1
53 fi
54
55 case "$lustretag" in
56     '')
57         warn "a lustretag is required."
58         usage >&2
59         exit 1
60         ;;
61     --help | -h)
62         usage
63         exit 0
64         ;;
65
66     # this is the branch table
67     # keep this list sorted alphabetically!
68
69     # These use special build directories 
70
71     # Maintenance mode -- isolate build system changes
72     b1_4*) buildtag="b1_4" ;;
73
74     # Maintenance mode -- isolate build system changes
75     b1_6*) buildtag="b1_6" ;;
76
77     b_release_1_4_6-patchless) buildtag="b1_4" ;;
78     b_release_1_4_7-test) buildtag="b_release_1_4_7" ;;
79
80     b_release*) buildtag=$lustretag ;;
81
82     b_uoss) buildtag=$lustretag ;;
83
84     # These releases did not get build tagged for them because they
85     # this build system didn't exist when they were tagged
86     v1_2_8|v1_4_0) 
87         buildtag="b1_4"
88         ;;
89     
90     v*) buildtag=$lustretag ;;
91
92     # this is the branch table
93     # keep this list sorted alphabetically!
94
95     *_gate) buildtag="b_build_gate" ;;
96
97     *)
98         buildtag="HEAD"
99         ;;
100 esac
101
102 error_modules=
103 cvs_cmd ()
104 {
105     dir="$1"
106     module="$2"
107     tag="$3"
108     cotag=""
109     update=""
110
111     if [ "$tag" = "HEAD" ] ; then
112         cotag=""
113         uptag="-A"
114     elif [ "$tag" ] ; then
115         cotag="-r $tag"
116         uptag="-r $tag"
117     else
118         # silently skip if no tag was specified
119         return
120     fi
121
122     # create a cvs date format that will survive shell expansion
123     if [ -n "$pindate" ]; then
124         datecmd=$(date -u +%s -d "$pindate")
125         datecmd="-D @$datecmd"
126     else
127         datecmd=""
128     fi
129
130     if [ -d "$dir" ] ; then
131         echo "$progname: Updating $dir to $tag"
132         ( cd "$dir" && cvs up $datecmd -dAP $uptag )
133     else
134         echo "$progname: Checking out $dir from $tag"
135         cvs co $datecmd -P $cotag -d "$dir" "$module"
136     fi
137     if [ $? != 0 ] ; then
138         error_modules="$dir $error_modules"
139     fi
140 }
141
142 hg_cmd ()
143 {
144     dir="$1"
145     base_url="$2"
146     repository="$3"
147
148     if [ ! "$repository" ]; then
149         return
150     fi
151
152     if ! which hg &> /dev/null; then
153     cat <<EOF
154
155 Error: Mercurial is missing, try 'yum install mercurial', 'apt-get install
156 mercurial' or try http://rpmfind.net/linux/rpm2html/search.php?query=mercurial
157 EOF
158         error_modules="$dir $error_modules"
159         return
160     fi
161
162     url="$base_url/$repository"
163
164     # create a cvs date format that will survive shell expansion
165     if [ -n "$pindate" ]; then
166         datecmd=$(date -u +%s -d "$pindate")
167         datecmd="-d \"$datecmd 0\""
168     else
169         datecmd=""
170     fi
171
172     if [ -d "$dir" ]; then
173         echo "$progname: Updating $dir"
174         if [ -f "$dir/update.sh" ]; then
175             ( cd "$dir" && ./update.sh $datecmd )
176         else
177             ( cd "$dir" && hg pull && hg update $datecmd )
178         fi
179     else
180         echo "$progname: Checking out $dir"
181         hg clone $url $dir
182         if [ -f "$dir/setup.sh" ]; then
183             ( cd "$dir" && ./setup.sh $datecmd )
184         else
185             ( cd "$dir" && hg update $datecmd )
186         fi
187     fi
188
189     if [ $? != 0 ] ; then
190         error_modules="$dir $error_modules"
191     fi
192 }
193
194 cvs_cmd build lustre-build "$buildtag"
195
196 if [ -f build/buildcvs ] ; then
197     . build/buildcvs
198 else
199     fatal 1 "build/buildcvs does not exist; not updating other modules."
200 fi
201
202 if [ "$error_modules" ] ; then
203     fatal 1 "There were errors checking out the following directories: $error_modules"
204 fi