8 #### REVIEW this carefully
9 # to be provided on the command line
10 #cvstag=planetlab-4_0-rc3
13 svn="svn+ssh://thierry@svn.one-lab.org/svn"
14 cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
29 # returns 1 for true and 0 for no
30 function my_prompt () {
34 y|Y) label="[y]/n" ; retcod=1 ;;
35 n|N) label="y/[n]" ; retcod=0 ;;
36 *) label="y/n (no default)" ;;
41 echo -n "$question $label ? "
49 return $retcod ; break ;;
51 echo 'Please enter y or n' ;;
56 function run_prompt () {
59 prompt_message="want to run $@"
62 my_prompt "$default" "$prompt_message"
63 if [ "$?" == 1 ] ; then
70 function run_loop () {
78 my_prompt $default "OK"
79 if [ "$?" == 1 ] ; then
85 ### echoes OK on stdout if url exists
86 function svn_url_check () {
88 svn list $url &> /dev/null && echo OK
91 ### return 'y' or 'n' for being used as prompt
92 function svn_url_needs_creation () {
94 if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi
97 function dir_needs_creation () {
99 if [ -d "$dir" ] ; then echo n ; else echo y ; fi
102 function svn_dir_needs_revert () {
104 output=$(svn status $dir 2>&1)
105 if [ -n "$output" ] ; then echo y ; else echo n ; fi
108 function svn_file_needs_commit () {
110 output=$(svn status $dir 2>&1)
111 if [ -n "$output" ] ; then echo y ; else echo n ; fi
114 ##############################
115 # guess spec files and extract from there
116 # search for <module.spec> otherwise expects a single *.spec file
117 function figure_module_spec () {
120 if [ -f $src/$module.spec ] ; then
121 echo $src/$module.spec
123 nbspecs=$(ls $src/*.spec | wc -l)
124 if [ $nbspecs = 1 ] ; then
125 echo $(ls $src/*.spec)
127 echo "$0: could not guess spec file in $src"
133 function extract_from_spec () {
136 if [ ! -f $specfile ] ; then
137 echo "Could not locate $specfile -- exiting"
140 line=$(grep "^%define[ \t][ \t]*$varname" $specfile)
141 value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,")
145 function patch_in_spec () {
150 ### sed -i unsupported on MACOS
151 sed -e "s,^%define[ \t][ \t]*$varname[ \t].*$,%define $varname $value," $specfile > ${specfile}.new
152 mv ${specfile}.new $specfile
155 ##############################
156 ##############################
157 ##############################
159 function print_warning () {
164 this script is quite rough and should be used with care
166 I am slowly trying to automate this painful process,
168 so again : USE WITH CARE
170 ========== Your input :
173 ========== Hard-wired :
176 ========== Computed :
186 function run_test () {
188 run_prompt n "going to /etc" cd /etc
189 run_prompt y "going to /etc" cd /etc
190 run_prompt y "Cleaning up /foobar" rmdir /foobar
191 run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar
192 run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var
193 run_prompt y "Cleaning up /foobar" rmdir /foobar
195 run_loop y "Check this and that" ls -ls passwd
196 run "Listing passwd" ls -ls passwd
200 function figure_last_import () {
202 last_import=$(svn list $svn/$module/imports | grep '^import-' | sort | tail -1 | sed -e s,import-,, -e s,/,,g )
206 function figure_next_import () {
207 last_import=$1; shift
208 current_index=$(echo $last_import | sed -e 's,-.*,,')
209 # remove leading 0 that confuse printf (takes it as octal)
210 decimal_index=$(echo $current_index | sed 's,^0*,,' )
211 next_index=$(printf "%03d" $(($decimal_index+1)))
212 echo ${next_index}-${cvstag}-${date}
215 function import_usage () {
216 echo "Usage: $0 module tag"
217 echo "All other parameters to be entered in the source file for now - sorry"
221 function import_module () {
223 [[ -z "$@" ]] && import_usage
225 [[ -z "$@" ]] && import_usage
227 [[ -n "$@" ]] && import_usage
228 import=$HOME/import-$module-$date
230 echo -n 'Figuring previous import ..'
231 previous=$(figure_last_import $module)
232 next=$(figure_next_import $previous)
233 echo " found $previous - next=$next"
237 # checks current status
238 echo -n "-------------------- Checking $module/imports/import-$previous "
239 if [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] ; then
240 echo FATAL : import-$previous not found
245 # snapshot current status
246 prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
247 run_prompt $prompt "Creating snapshot of current status" \
248 svn copy -mBefore-${next} $svn/$module/trunk $svn/$module/imports/before-$next
250 # init import dir from previous import
251 prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
252 run_prompt $prompt "Preparing import-$next from import-$previous" \
253 svn copy -mCreation-from-import-${previous} $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
256 run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
257 mkdir -p $import/$module/imports
260 run_prompt $(dir_needs_creation $import/$module/imports/import-$next) \
261 "Checking out import-$next for applying changes" \
262 svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
265 cd $import/$module/imports
267 message 'NOTE: the way we merge changes right below might need to be tested/improved'
269 run_prompt n "Incorporating changes since import-$previous in import-$next" \
270 cvs -d $cvs export -r $cvstag -d import-$next $module
272 run "Going to import-$next" \
273 cd $import/$module/imports/import-$next
275 run_loop n "Check the changes in import-$next -- no conflict expected" \
276 svn status $import/$module/imports/import-$next
278 run_prompt n "CHECKING IN imported changes in import-$next" \
279 svn ci -mApplied-changes-since-$previous
282 run "Going to $import/$module" \
285 run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
286 svn co $svn/$module/trunk
288 run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
289 svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
291 run_loop n "CHECK CHANGES in $import/$module/trunk -- conflicts should get resolved" \
294 run_prompt n "CHECKING IN changes in trunk" \
295 svn ci -m "Merged changes from import-$previous to import-$next"
297 prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
298 run_prompt $prompt "Backing up into after-$next" \
299 svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
301 run_prompt n "Want to rename $import as $import-to-trash" \
302 mv $import $import-totrash
307 ##############################
308 function tag_usage () {
309 echo "Usage: $0 module"
313 function tag_module () {
315 [[ -z "$@" ]] && tag_usage
317 tagwork=$HOME/tags/$module
318 tagtrunk=$HOME/tags/$module/trunk
319 [[ -n "$@" ]] && tag_usage
321 echo 'Tagging' $module
323 run_prompt $(dir_needs_creation $tagtrunk) "Checking out $tagtrunk" \
324 svn co $svn/$module/trunk $tagtrunk
326 run_prompt y "Updating $tagtrunk" \
329 run_prompt $(svn_dir_needs_revert $tagtrunk) "Reverting $tagtrunk for safety " \
330 svn revert -R $tagtrunk
335 ### extracting current version info
336 spec=$(figure_module_spec $tagtrunk $module)
337 version=$(extract_from_spec $spec version)
338 subversion=$(extract_from_spec $spec subversion)
339 newsubversion=$(($subversion+1))
341 message "FOUND spec=$spec version=$version subversion=$subversion"
343 # check that the tags relating to subversion and newsubversion does (resp. does not) exist
344 oldtag=$svn/$module/tags/$module-${version}.${subversion}
345 newtag=$svn/$module/tags/$module-${version}.${newsubversion}
347 echo -n "Checking tags status ..."
348 old_check=$(svn_url_check $oldtag)
349 if [ -z "$old_check" ] ; then
350 echo "Former tag does not exist -- exiting"
351 echo "URL was $oldtag"
354 echo -n " old tag OK ... "
356 new_check=$(svn_url_check $newtag)
357 if [ -n "$new_check" ] ; then
358 echo "New tag does exist -- exiting"
359 echo "URL was $newtag"
364 patch_in_spec $spec subversion $newsubversion
366 run_loop y "Checking differences" \
369 run_prompt n "Display differences from previous tag" \
370 svn diff $oldtag $svn/$module/trunk
372 run_prompt y "Committing changes in $tagtrunk" \
373 svn ci --editor-cmd=vi $tagtrunk
375 # putting spaces in the message does not work
376 run_prompt y "Creating tag $newtag" \
377 svn copy --message "$module-${version}.${newsubversion}" $svn/$module/trunk $newtag
379 # make changes in build/*-tags.mk
380 tagbuild=$HOME/tags/build/trunk
381 oldname=$module-${version}.${subversion}
382 newname=$module-${version}.${newsubversion}
384 run_prompt $(dir_needs_creation $tagbuild) "Checking out $tagbuild" \
385 svn co $svn/$module/build $tagbuild
387 run_prompt y "Updating $tagbuild" \
390 run_prompt $(svn_dir_needs_revert $tagbuild) "Reverting $tagbuild for safety " \
391 svn revert -R $tagbuild
396 # committing tags files
398 for tagsmk in *-tags.mk; do
399 echo "=== Managing $tagsmk"
400 sed -i -e "s,$oldname,$newname,g" $tagsmk
401 if [ $(svn_file_needs_commit $tagsmk) = "y" ] ; then
402 echo "Changes in $tagsmk"
404 my_prompt y "Adopt $newname in $tagsmk"
405 if [ "$?" == 1 ] ; then
406 files_to_commit="$files_to_commit $tagsmk"
410 if [ -n "$files_to_commit" ] ; then
411 command="svn commit -mAdopting-$newname $files_to_commit"
412 run "Committing selected tags files" $command
417 function diff_modules () {
418 for module in "$@" ; do
419 tagtrunk=$HOME/tags/$module/trunk
420 echo "--------------------Checking $module"
421 run_prompt y "Updating $tagwork" svn update $tagtrunk
422 ### extracting current version info
423 spec=$(figure_module_spec $tagtrunk $module)
424 version=$(extract_from_spec $spec version)
425 subversion=$(extract_from_spec $spec subversion)
427 echo "FOUND spec=$spec version=$version subversion=$subversion"
429 lasttag=$svn/$module/tags/$module-${version}.${subversion}
430 trunk=$svn/$module/trunk
432 run_prompt y "Diffing : < last tag -- trunk >" svn diff $lasttag $trunk
446 # my_prompt $@ ; echo "result=$?";;
449 echo "Unsupported command $0" ; exit 0