8 #### REVIEW this carefully
9 cvstag=planetlab-4_0-rc3
12 svn="svn+ssh://thierry@svn.one-lab.org/svn"
13 cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
16 echo -n '-------------------- '
18 echo -n 'Enter return to proceed .. '
23 echo -n '-------------------- '
32 function run_prompt () {
38 *) label="y/n (no default)" ;;
41 echo -n '-------------------- '
45 echo -n "want to run $@ $label ? "
47 [ -z "$answer" ] && answer=$default
59 echo 'Please enter y or n'
65 function run_loop () {
68 echo -n '-------------------- '
75 [ -z "$answer" ] && answer=n
84 ### echoes OK on stdout if url exists
85 function svn_url_check () {
87 svn list $url &> /dev/null && echo OK
90 ### return 'y' or 'n' for being used as prompt
91 function svn_url_needs_creation () {
93 if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi
96 function dir_needs_creation () {
98 if [ -d "$dir" ] ; then echo n ; else echo y ; fi
101 function svn_dir_needs_revert () {
103 output=$(svn status $dir 2>&1)
104 if [ -n "$output" ] ; then echo y ; else echo n ; fi
107 function svn_file_needs_commit () {
109 output=$(svn status $dir 2>&1)
110 if [ -n "$output" ] ; then echo y ; else echo n ; fi
113 ##############################
114 # guess spec files and extract from there
115 # search for <module.spec> otherwise expects a single *.spec file
116 function figure_module_spec () {
119 if [ -f $src/$module.spec ] ; then
120 echo $src/$module.spec
122 nbspecs=$(ls $src/*.spec | wc -l)
123 if [ $nbspecs = 1 ] ; then
124 echo $(ls $src/*.spec)
126 echo "$0: could not guess spec file in $src"
132 function extract_from_spec () {
135 if [ ! -f $specfile ] ; then
136 echo "Could not locate $specfile -- exiting"
139 line=$(grep "^%define[ \t][ \t]*$varname" $specfile)
140 value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,")
144 function patch_in_spec () {
149 ### sed -i unsupported on MACOS
150 sed -e "s,^%define[ \t][ \t]*$varname[ \t].*$,%define $varname $value," $specfile > ${specfile}.new
151 mv ${specfile}.new $specfile
154 ##############################
155 ##############################
156 ##############################
158 function print_warning () {
163 this script is quite rough and should be used with care
165 I am slowly trying to automate this painful process,
167 so again : USE WITH CARE
169 ========== Your input :
171 ========== Hard-wired :
175 ========== Computed :
185 function run_test () {
187 run_prompt n "going to /etc" cd /etc
188 run_prompt y "going to /etc" cd /etc
189 run_prompt y "Cleaning up /foobar" rmdir /foobar
190 run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar
191 run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var
192 run_prompt y "Cleaning up /foobar" rmdir /foobar
194 run_loop "Check this and that" ls -ls passwd
195 run "Listing passwd" ls -ls passwd
199 function figure_last_import () {
201 last_import=$(svn list $svn/$module/imports | grep '^import-' | sort | tail -1 | sed -e s,import-,, -e s,/,,g )
205 function figure_next_import () {
206 last_import=$1; shift
207 current_index=$(echo $last_import | sed -e 's,-.*,,')
208 # remove leading 0 that confuse printf (takes it as octal)
209 decimal_index=$(echo $current_index | sed 's,^0*,,' )
210 next_index=$(printf "%03d" $(($decimal_index+1)))
211 echo ${next_index}-${cvstag}-${date}
214 function import_usage () {
215 echo "Usage: $0 module"
216 echo "All other parameters to be entered in the source file for now - sorry"
220 function import_module () {
222 [[ -z "$@" ]] && import_usage
224 import=$HOME/import-$module-$date
225 [[ -n "$@" ]] && import_usage
227 echo -n 'Figuring previous import ..'
228 previous=$(figure_last_import $module)
229 next=$(figure_next_import $previous)
230 echo " found $previous - next=$next"
234 # checks current status
235 echo -n "-------------------- Checking $module/imports/import-$previous "
236 if [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] ; then
237 echo FATAL : import-$previous not found
242 # snapshot current status
243 prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
244 run_prompt $prompt "Creating snapshot of current status" \
245 svn copy -mBefore-${next} $svn/$module/trunk $svn/$module/imports/before-$next
247 # init import dir from previous import
248 prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
249 run_prompt $prompt "Preparing import-$next from import-$previous" \
250 svn copy -mCreation-from-import-${previous} $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
253 run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
254 mkdir -p $import/$module/imports
257 run_prompt $(dir_needs_creation $import/$module/imports/import-$next) \
258 "Checking out import-$next for applying changes" \
259 svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
262 cd $import/$module/imports
264 message 'NOTE: the way we merge changes right below might need to be tested/improved'
266 run_prompt n "Incorporating changes since import-$previous in import-$next" \
267 cvs -d $cvs export -r $cvstag -d import-$next $module
269 run "Going to import-$next" \
270 cd $import/$module/imports/import-$next
272 run_loop "Check the changes in import-$next -- no conflict expected" \
273 svn status $import/$module/imports/import-$next
275 run_prompt n "CHECKING IN imported changes in import-$next" \
276 svn ci -mApplied-changes-since-$previous
279 run "Going to $import/$module" \
282 run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
283 svn co $svn/$module/trunk
285 run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
286 svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
288 run_loop "CHECK CHANGES in $import/$module/trunk -- conflicts should get resolved" \
291 run_prompt n "CHECKING IN changes in trunk" \
292 svn ci -m "Merged changes from import-$previous to import-$next"
294 prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
295 run_prompt $prompt "Backing up into after-$next" \
296 svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
298 run_prompt n "Want to rename $import as $import-to-trash" \
299 mv $import $import-totrash
304 ##############################
305 function tag_usage () {
306 echo "Usage: $0 module"
310 function tag_module () {
312 [[ -z "$@" ]] && tag_usage
314 tagwork=$HOME/tags/$module
315 tagtrunk=$HOME/tags/$module/trunk
316 [[ -n "$@" ]] && tag_usage
318 echo 'Tagging' $module
320 run_prompt $(dir_needs_creation $tagtrunk) "Checking out $tagtrunk" \
321 svn co $svn/$module/trunk $tagtrunk
323 run_prompt y "Updating $tagtrunk" \
326 run_prompt $(svn_dir_needs_revert $tagtrunk) "Reverting $tagtrunk for safety " \
327 svn revert -R $tagtrunk
332 ### extracting current version info
333 spec=$(figure_module_spec $tagtrunk $module)
334 version=$(extract_from_spec $spec version)
335 subversion=$(extract_from_spec $spec subversion)
336 newsubversion=$(($subversion+1))
338 message "FOUND spec=$spec version=$version subversion=$subversion"
340 # check that the tags relating to subversion and newsubversion does (resp. does not) exist
341 oldtag=$svn/$module/tags/$module-${version}.${subversion}
342 newtag=$svn/$module/tags/$module-${version}.${newsubversion}
344 echo -n "Checking tags status ..."
345 old_check=$(svn_url_check $oldtag)
346 if [ -z "$old_check" ] ; then
347 echo "Former tag does not exist -- exiting"
348 echo "URL was $oldtag"
351 echo -n " old tag OK ... "
353 new_check=$(svn_url_check $newtag)
354 if [ -n "$new_check" ] ; then
355 echo "New tag does exist -- exiting"
356 echo "URL was $newtag"
361 patch_in_spec $spec subversion $newsubversion
363 run_loop "Checking differences" \
366 run_prompt y "Display differences from previous tag" \
367 svn diff $oldtag $svn/$module/trunk
369 run_prompt y "Committing changes in $tagtrunk" \
370 svn ci --editor-cmd=vi $tagtrunk
372 # putting spaces in the message does not work
373 run_prompt y "Creating tag $newtag" \
374 svn copy --message "$module-${version}.${newsubversion}" $svn/$module/trunk $newtag
376 # make changes in build/*-tags.mk
377 tagbuild=$HOME/tags/build/trunk
378 oldname=$module-${version}.${subversion}
379 newname=$module-${version}.${newsubversion}
381 run_prompt $(dir_needs_creation $tagbuild) "Checking out $tagbuild" \
382 svn co $svn/$module/build $tagbuild
384 run_prompt y "Updating $tagbuild" \
387 run_prompt $(svn_dir_needs_revert $tagbuild) "Reverting $tagbuild for safety " \
388 svn revert -R $tagbuild
393 for tagsmk in *-tags.mk; do
394 echo "Managing $tagsmk"
395 sed -i -e "s,$oldname,$newname,g" $tagsmk
396 if [ $(svn_file_needs_commit $tagsmk) = "y" ] ; then
397 echo "Changes in $tagsmk"
399 run_prompt y "Adopt $newname in $tagsmk " \
400 svn commit -m"Adopting-$newname" $tagsmk
406 function diff_modules () {
407 for module in "$@" ; do
408 tagtrunk=$HOME/tags/$module/trunk
409 echo "--------------------Checking $module"
410 run_prompt y "Updating $tagwork" svn update $tagtrunk
411 ### extracting current version info
412 spec=$(figure_module_spec $tagtrunk $module)
413 version=$(extract_from_spec $spec version)
414 subversion=$(extract_from_spec $spec subversion)
416 echo "FOUND spec=$spec version=$version subversion=$subversion"
418 lasttag=$svn/$module/tags/$module-${version}.${subversion}
419 trunk=$svn/$module/trunk
421 run_prompt y "Diffing : < last tag -- trunk >" svn diff $lasttag $trunk
435 x=$(figure_module_spec $@) ; echo $x;;
437 echo "Unsupported command $0" ; exit 0