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 ##############################
112 # guess spec files and extract from there
113 # search for <module.spec> otherwise expects a single *.spec file
114 function figure_module_spec () {
117 if [ -f $src/$module.spec ] ; then
118 echo $src/$module.spec
120 nbspecs=$(ls $src/*.spec | wc -l)
121 if [ $nbspecs = 1 ] ; then
122 echo $(ls $src/*.spec)
124 echo "$0: could not guess spec file in $src"
130 function extract_from_spec () {
133 if [ ! -f $specfile ] ; then
134 echo "Could not locate $specfile -- exiting"
137 line=$(grep "^%define[ \t][ \t]*$varname" $specfile)
138 value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,")
142 function patch_in_spec () {
147 ### sed -i unsupported on MACOS
148 sed -e "s,^%define[ \t][ \t]*$varname[ \t].*$,%define $varname $value," $specfile > ${specfile}.new
149 mv ${specfile}.new $specfile
152 ##############################
153 ##############################
154 ##############################
156 function print_warning () {
161 this script is quite rough and should be used with care
163 I am slowly trying to automate this painful process,
165 so again : USE WITH CARE
183 function run_test () {
185 run_prompt n "going to /etc" cd /etc
186 run_prompt y "going to /etc" cd /etc
187 run_prompt y "Cleaning up /foobar" rmdir /foobar
188 run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar
189 run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var
190 run_prompt y "Cleaning up /foobar" rmdir /foobar
192 run_loop "Check this and that" ls -ls passwd
193 run "Listing passwd" ls -ls passwd
197 function import_usage () {
199 echo "All parameters to be entered in the source file for now - sorry"
203 function import_module () {
205 [[ -n "$@" ]] && import_usage
209 # checks current status
210 echo "------------------------------ Checking $module/imports/import-$previous"
211 [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] && echo WARNING : import-$previous not found
215 # snapshot current status
216 prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
217 run_prompt $prompt "Creating snapshot of current status" \
218 svn copy $svn/$module/trunk $svn/$module/imports/before-$next
220 # init import dir from previous import
221 prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
222 run_prompt $prompt "Preparing import-$next from import-$previous" \
223 svn copy $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
226 run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
227 mkdir -p $import/$module/imports
230 run_prompt $(dir_needs_creation $import/$module/imports/import-$next) \
231 "Checking out import-$next for applying changes" \
232 svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
235 cd $import/$module/imports
237 message 'NOTE: the way we merge changes right below might need to be tested/improved'
239 run_prompt n "Incorporating changes since import-$previous in import-$next" \
240 cvs -d $cvs export -r $cvstag -d import-$next $module
242 run "Going to import-$next" \
243 cd $import/$module/imports/import-$next
245 run_loop "Check the changes in import-$next -- no conflict expected" \
246 svn status $import/$module/imports/import-$next
248 run_prompt n "CHECKING IN changes in import-$next" \
249 svn ci -m "Changes since $previous"
252 run "Going to $import/$module" \
255 run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
256 svn co $svn/$module/trunk
258 run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
259 svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
261 run_loop "Check the changes in trunk -- conflicts should get resolved" \
264 run_prompt n "CHECKING IN changes in trunk" \
265 svn ci -m "Merged changes from import-$previous to import-$next"
267 prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
268 run_prompt $prompt "Backing up into after-$next" \
269 svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
271 run_prompt n "Want to rename $import as $import-to-trash" \
272 mv $import $import-totrash
277 function tag_usage () {
278 echo "Usage: $0 module"
282 function tag_module () {
284 [[ -z "$@" ]] && tag_usage
286 tagwork=$HOME/tags/$module
287 tagtrunk=$HOME/tags/$module/trunk
288 [[ -n "$@" ]] && tag_usage
290 echo 'Tagging' $module
292 run_prompt $(dir_needs_creation $tagwork) "Creating $tagwork" \
295 run_prompt $(dir_needs_creation $tagtrunk) "Checking out $tagtrunk" \
296 svn co $svn/$module/trunk $tagtrunk
298 run_prompt y "Updating $tagtrunk" \
301 run_prompt $(svn_dir_needs_revert $tagtrunk) "Reverting $tagtrunk for safety " \
302 svn revert -R $tagtrunk
307 ### extracting current version info
308 spec=$(figure_module_spec $tagtrunk $module)
309 version=$(extract_from_spec $spec version)
310 subversion=$(extract_from_spec $spec subversion)
311 newsubversion=$(($subversion+1))
313 message "FOUND spec=$spec version=$version subversion=$subversion"
315 # check that the tags relating to subversion and newsubversion does (resp. does not) exist
316 oldtag=$svn/$module/tags/$module-${version}.${subversion}
317 newtag=$svn/$module/tags/$module-${version}.${newsubversion}
319 echo -n "Checking tags status ..."
320 old_check=$(svn_url_check $oldtag)
321 if [ -z "$old_check" ] ; then
322 echo "Former tag does not exist -- exiting"
323 echo "URL was $oldtag"
326 echo -n " old tag OK ... "
328 new_check=$(svn_url_check $newtag)
329 if [ -n "$new_check" ] ; then
330 echo "New tag does exist -- exiting"
331 echo "URL was $newtag"
336 patch_in_spec $spec subversion $newsubversion
338 run_loop "Checking differences" \
341 run_prompt y "Display differences from previous tag" \
342 svn diff $oldtag $svn/$module/trunk
344 run_prompt y "Committing changes in $tagtrunk" \
345 svn ci --editor-cmd=vi $tagtrunk
347 # putting spaces in the message does not work
348 run_prompt y "Creating tag $newtag" \
349 svn copy --message "$module-${version}.${newsubversion}" $svn/$module/trunk $newtag
351 echo "This command does not handle changes in onelab-tags.mk - yet"
362 x=$(figure_module_spec $@) ; echo $x;;
364 echo "Unsupported command $0" ; exit 0