8 #### REVIEW this carefully
10 cvstag=planetlab-4_0-rc3
11 previous=002-rc3-2007-05-02
12 next=003-${cvstag}-${date}
15 svn="svn+ssh://thierry@svn.one-lab.org/svn"
16 cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
17 import=$HOME/import-$module-$date
20 echo -n '-------------------- '
22 echo -n 'Enter return to proceed .. '
27 echo -n '-------------------- '
36 function run_prompt () {
42 *) label="y/n (no default)" ;;
45 echo -n '-------------------- '
49 echo -n "want to run $@ $label ? "
51 [ -z "$answer" ] && answer=$default
63 echo 'Please enter y or n'
69 function run_loop () {
72 echo -n '-------------------- '
79 [ -z "$answer" ] && answer=n
88 ### echoes OK on stdout if url exists
89 function svn_url_check () {
91 svn list $url &> /dev/null && echo OK
94 ### return 'y' or 'n' for being used as prompt
95 function svn_url_needs_creation () {
97 if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi
100 function dir_needs_creation () {
102 if [ -d "$dir" ] ; then echo n ; else echo y ; fi
105 function svn_dir_needs_revert () {
107 output=$(svn status $dir 2>&1)
108 if [ -n "$output" ] ; then echo y ; else echo n ; fi
111 function svn_file_needs_commit () {
113 output=$(svn status $dir 2>&1)
114 if [ -n "$output" ] ; then echo y ; else echo n ; fi
117 ##############################
118 # guess spec files and extract from there
119 # search for <module.spec> otherwise expects a single *.spec file
120 function figure_module_spec () {
123 if [ -f $src/$module.spec ] ; then
124 echo $src/$module.spec
126 nbspecs=$(ls $src/*.spec | wc -l)
127 if [ $nbspecs = 1 ] ; then
128 echo $(ls $src/*.spec)
130 echo "$0: could not guess spec file in $src"
136 function extract_from_spec () {
139 if [ ! -f $specfile ] ; then
140 echo "Could not locate $specfile -- exiting"
143 line=$(grep "^%define[ \t][ \t]*$varname" $specfile)
144 value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,")
148 function patch_in_spec () {
153 ### sed -i unsupported on MACOS
154 sed -e "s,^%define[ \t][ \t]*$varname[ \t].*$,%define $varname $value," $specfile > ${specfile}.new
155 mv ${specfile}.new $specfile
158 ##############################
159 ##############################
160 ##############################
162 function print_warning () {
167 this script is quite rough and should be used with care
169 I am slowly trying to automate this painful process,
171 so again : USE WITH CARE
189 function run_test () {
191 run_prompt n "going to /etc" cd /etc
192 run_prompt y "going to /etc" cd /etc
193 run_prompt y "Cleaning up /foobar" rmdir /foobar
194 run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar
195 run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var
196 run_prompt y "Cleaning up /foobar" rmdir /foobar
198 run_loop "Check this and that" ls -ls passwd
199 run "Listing passwd" ls -ls passwd
203 function import_usage () {
205 echo "All parameters to be entered in the source file for now - sorry"
209 function import_module () {
211 [[ -n "$@" ]] && import_usage
215 # checks current status
216 echo "------------------------------ Checking $module/imports/import-$previous"
217 [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] && echo WARNING : import-$previous not found
221 # snapshot current status
222 prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
223 run_prompt $prompt "Creating snapshot of current status" \
224 svn copy $svn/$module/trunk $svn/$module/imports/before-$next
226 # init import dir from previous import
227 prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
228 run_prompt $prompt "Preparing import-$next from import-$previous" \
229 svn copy $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
232 run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
233 mkdir -p $import/$module/imports
236 run_prompt $(dir_needs_creation $import/$module/imports/import-$next) \
237 "Checking out import-$next for applying changes" \
238 svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
241 cd $import/$module/imports
243 message 'NOTE: the way we merge changes right below might need to be tested/improved'
245 run_prompt n "Incorporating changes since import-$previous in import-$next" \
246 cvs -d $cvs export -r $cvstag -d import-$next $module
248 run "Going to import-$next" \
249 cd $import/$module/imports/import-$next
251 run_loop "Check the changes in import-$next -- no conflict expected" \
252 svn status $import/$module/imports/import-$next
254 run_prompt n "CHECKING IN changes in import-$next" \
255 svn ci -m "Changes since $previous"
258 run "Going to $import/$module" \
261 run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
262 svn co $svn/$module/trunk
264 run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
265 svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
267 run_loop "Check the changes in trunk -- conflicts should get resolved" \
270 run_prompt n "CHECKING IN changes in trunk" \
271 svn ci -m "Merged changes from import-$previous to import-$next"
273 prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
274 run_prompt $prompt "Backing up into after-$next" \
275 svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
277 run_prompt n "Want to rename $import as $import-to-trash" \
278 mv $import $import-totrash
283 function tag_usage () {
284 echo "Usage: $0 module"
288 function tag_module () {
290 [[ -z "$@" ]] && tag_usage
292 tagwork=$HOME/tags/$module
293 tagtrunk=$HOME/tags/$module/trunk
294 [[ -n "$@" ]] && tag_usage
296 echo 'Tagging' $module
298 run_prompt $(dir_needs_creation $tagtrunk) "Checking out $tagtrunk" \
299 svn co $svn/$module/trunk $tagtrunk
301 run_prompt y "Updating $tagtrunk" \
304 run_prompt $(svn_dir_needs_revert $tagtrunk) "Reverting $tagtrunk for safety " \
305 svn revert -R $tagtrunk
310 ### extracting current version info
311 spec=$(figure_module_spec $tagtrunk $module)
312 version=$(extract_from_spec $spec version)
313 subversion=$(extract_from_spec $spec subversion)
314 newsubversion=$(($subversion+1))
316 message "FOUND spec=$spec version=$version subversion=$subversion"
318 # check that the tags relating to subversion and newsubversion does (resp. does not) exist
319 oldtag=$svn/$module/tags/$module-${version}.${subversion}
320 newtag=$svn/$module/tags/$module-${version}.${newsubversion}
322 echo -n "Checking tags status ..."
323 old_check=$(svn_url_check $oldtag)
324 if [ -z "$old_check" ] ; then
325 echo "Former tag does not exist -- exiting"
326 echo "URL was $oldtag"
329 echo -n " old tag OK ... "
331 new_check=$(svn_url_check $newtag)
332 if [ -n "$new_check" ] ; then
333 echo "New tag does exist -- exiting"
334 echo "URL was $newtag"
339 patch_in_spec $spec subversion $newsubversion
341 run_loop "Checking differences" \
344 run_prompt y "Display differences from previous tag" \
345 svn diff $oldtag $svn/$module/trunk
347 run_prompt y "Committing changes in $tagtrunk" \
348 svn ci --editor-cmd=vi $tagtrunk
350 # putting spaces in the message does not work
351 run_prompt y "Creating tag $newtag" \
352 svn copy --message "$module-${version}.${newsubversion}" $svn/$module/trunk $newtag
354 # make changes in build/*-tags.mk
355 tagbuild=$HOME/tags/build/trunk
356 oldname=$module-${version}.${subversion}
357 newname=$module-${version}.${newsubversion}
359 run_prompt $(dir_needs_creation $tagbuild) "Checking out $tagbuild" \
360 svn co $svn/$module/build $tagbuild
362 run_prompt y "Updating $tagbuild" \
365 run_prompt $(svn_dir_needs_revert $tagbuild) "Reverting $tagbuild for safety " \
366 svn revert -R $tagbuild
371 for tagsmk in *-tags.mk; do
372 echo "Managing $tagsmk"
373 sed -i -e "s,$oldname,$newname,g" $tagsmk
374 if [ $(svn_file_needs_commit $tagsmk) = "y" ] ; then
375 echo "Changes in $tagsmk"
377 run_prompt y "Adopt $newname in $tagsmk " \
378 svn commit -m"Adopting-$newname" $tagsmk
389 x=$(figure_module_spec $@) ; echo $x;;
391 echo "Unsupported command $0" ; exit 0