cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
import=$HOME/import-$module-$date
-
function message () {
echo -n '-------------------- '
echo $@
if [ -d "$dir" ] ; then echo n ; else echo y ; fi
}
+function svn_dir_needs_revert () {
+ dir=$1; shift
+ output=$(svn status $dir 2>&1)
+ if [ -n "$output" ] ; then echo y ; else echo n ; fi
+}
+
+##############################
+# guess spec files and extract from there
+# search for <module.spec> otherwise expects a single *.spec file
+function figure_module_spec () {
+ src=$1; shift
+ module=$1; shift
+ if [ -f $src/$module.spec ] ; then
+ echo $src/$module.spec
+ else
+ nbspecs=$(ls $src/*.spec | wc -l)
+ if [ $nbspecs = 1 ] ; then
+ echo $(ls $src/*.spec)
+ else
+ echo "$0: could not guess spec file in $src"
+ exit 1
+ fi
+ fi
+}
+
+function extract_from_spec () {
+ specfile=$1; shift
+ varname=$1; shift
+ if [ ! -f $specfile ] ; then
+ echo "Could not locate $specfile -- exiting"
+ exit 1
+ fi
+ line=$(grep "^%define[ \t][ \t]*$varname" $specfile)
+ value=$(echo $line | sed -e "s,%define[ \t][ \t]*$varname[ \t][ \t]*,,")
+ echo $value
+}
+
+function patch_in_spec () {
+ specfile=$1; shift
+ varname=$1; shift
+ value=$1; shift
+
+ ### sed -i unsupported on MACOS
+ sed -e "s,^%define[ \t][ \t]*$varname[ \t].*$,%define $varname $value," $specfile > ${specfile}.new
+ mv ${specfile}.new $specfile
+}
+
##############################
##############################
##############################
-cat <<EOF
+function print_warning () {
+
+ cat <<EOF
####### WARNING
this script is quite rough and should be used with care
cvs=$cvs
date=$date
import=$import
+tagwork=$tagwork
+tagtrunk=$tagtrunk
####### WARNING
EOF
+}
function run_test () {
message Hi there
exit 0
}
-# checks current status
-echo "------------------------------ Checking $module/imports/import-$previous"
-[ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] && echo WARNING : import-$previous not found
+function import_usage () {
+ echo "Usage: $0"
+ echo "All parameters to be entered in the source file for now - sorry"
+ exit 1
+}
-echo ''
+function import_module () {
-# snapshot current status
-prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
-run_prompt $prompt "Creating snapshot of current status" \
- svn copy $svn/$module/trunk $svn/$module/imports/before-$next
+ [[ -n "$@" ]] && import_usage
-# init import dir from previous import
-prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
-run_prompt $prompt "Preparing import-$next from import-$previous" \
- svn copy $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
+ print_warning
-####
-run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
- mkdir -p $import/$module/imports
+ # checks current status
+ echo "------------------------------ Checking $module/imports/import-$previous"
+ [ -z "$(svn_url_check $svn/$module/imports/import-$previous)" ] && echo WARNING : import-$previous not found
+
+ echo ''
+
+ # snapshot current status
+ prompt=$(svn_url_needs_creation $svn/$module/imports/before-$next)
+ run_prompt $prompt "Creating snapshot of current status" \
+ svn copy $svn/$module/trunk $svn/$module/imports/before-$next
-###
-run_prompt $(dir_needs_creation $import/$module/imports/import-$next) "Checking out import-$next for applying changes" \
- svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
+ # init import dir from previous import
+ prompt=$(svn_url_needs_creation $svn/$module/imports/import-$next)
+ run_prompt $prompt "Preparing import-$next from import-$previous" \
+ svn copy $svn/$module/imports/import-$previous $svn/$module/imports/import-$next
-run "Going there" \
- cd $import/$module/imports
+ ####
+ run_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
+ mkdir -p $import/$module/imports
-message 'NOTE: the way we merge changes right below might need to be tested/improved'
+ ###
+ run_prompt $(dir_needs_creation $import/$module/imports/import-$next) \
+ "Checking out import-$next for applying changes" \
+ svn co $svn/$module/imports/import-$next $import/$module/imports/import-$next
-run_prompt n "Incorporating changes since import-$previous in import-$next" \
- cvs -d $cvs export -r $cvstag -d import-$next $module
+ run "Going there" \
+ cd $import/$module/imports
-run "Going to import-$next" \
- cd $import/$module/imports/import-$next
+ message 'NOTE: the way we merge changes right below might need to be tested/improved'
-run_loop "Check the changes in import-$next -- no conflict expected" svn status $import/$module/imports/import-$next
+ run_prompt n "Incorporating changes since import-$previous in import-$next" \
+ cvs -d $cvs export -r $cvstag -d import-$next $module
-run_prompt n "CHECKING IN changes in import-$next" \
- svn ci -m "Changes since $previous"
+ run "Going to import-$next" \
+ cd $import/$module/imports/import-$next
-###
-run "Going to $import/$module" \
- cd $import/$module
+ run_loop "Check the changes in import-$next -- no conflict expected" \
+ svn status $import/$module/imports/import-$next
-run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
- svn co $svn/$module/trunk
+ run_prompt n "CHECKING IN changes in import-$next" \
+ svn ci -m "Changes since $previous"
-run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
- svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
+ ###
+ run "Going to $import/$module" \
+ cd $import/$module
-run_loop "Check the changes in trunk -- conflicts should get resolved" svn status trunk
+ run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
+ svn co $svn/$module/trunk
-run_prompt n "CHECKING IN changes in trunk" \
- svn ci -m "Merged changes from import-$previous to import-$next"
+ run_prompt n "Merging changes from import-$previous to import-$next into trunk" \
+ svn merge $svn/$module/imports/import-$previous $svn/$module/imports/import-$next trunk
-prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
-run_prompt $prompt "Backing up into after-$next" \
- svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
+ run_loop "Check the changes in trunk -- conflicts should get resolved" \
+ svn status trunk
-run_prompt n "Want to rename $import as $import-to-trash" \
- mv $import $import-totrash
+ run_prompt n "CHECKING IN changes in trunk" \
+ svn ci -m "Merged changes from import-$previous to import-$next"
-echo 'Done'
-exit 0
+ prompt=$(svn_url_needs_creation $svn/$module/imports/after-$next)
+ run_prompt $prompt "Backing up into after-$next" \
+ svn copy $svn/$module/$trunk $svn/$module/imports/after-$next
+
+ run_prompt n "Want to rename $import as $import-to-trash" \
+ mv $import $import-totrash
+
+ echo 'Done'
+}
+
+function tag_usage () {
+ echo "Usage: $0 module"
+ exit 1
+}
+
+function tag_module () {
+
+ [[ -z "$@" ]] && tag_usage
+ module=$1; shift
+ tagwork=$HOME/tags/$module
+ tagtrunk=$HOME/tags/$module/trunk
+ [[ -n "$@" ]] && tag_usage
+
+ echo 'Tagging' $module
+
+ run_prompt $(dir_needs_creation $tagwork) "Creating $tagwork" \
+ mkdir -p $tagwork
+
+ run_prompt $(dir_needs_creation $tagtrunk) "Checking out $tagtrunk" \
+ svn co $svn/$module/trunk $tagtrunk
+
+ run_prompt y "Updating $tagtrunk" \
+ svn up $tagtrunk
+
+ run_prompt $(svn_dir_needs_revert $tagtrunk) "Reverting $tagtrunk for safety " \
+ svn revert -R $tagtrunk
+
+ run "cd $tagtrunk" \
+ cd $tagtrunk
+
+ ### extracting current version info
+ spec=$(figure_module_spec $tagtrunk $module)
+ version=$(extract_from_spec $spec version)
+ subversion=$(extract_from_spec $spec subversion)
+ newsubversion=$(($subversion+1))
+
+ message "FOUND spec=$spec version=$version subversion=$subversion"
+
+ # check that the tags relating to subversion and newsubversion does (resp. does not) exist
+ oldtag=$svn/$module/tags/$module-${version}.${subversion}
+ newtag=$svn/$module/tags/$module-${version}.${newsubversion}
+
+ echo -n "Checking tags status ..."
+ old_check=$(svn_url_check $oldtag)
+ if [ -z "$old_check" ] ; then
+ echo "Former tag does not exist -- exiting"
+ echo "URL was $oldtag"
+ exit 1
+ fi
+ echo -n " old tag OK ... "
+
+ new_check=$(svn_url_check $newtag)
+ if [ -n "$new_check" ] ; then
+ echo "New tag does exist -- exiting"
+ echo "URL was $newtag"
+ exit 1
+ fi
+ echo " new tag OK"
+
+ patch_in_spec $spec subversion $newsubversion
+
+ run_loop "Checking differences" \
+ svn diff $tagtrunk
+
+ run_prompt y "Display differences from previous tag" \
+ svn diff $oldtag $svn/$module/trunk
+
+ run_prompt y "Committing changes in $tagtrunk" \
+ svn ci --editor-cmd=vi $tagtrunk
+
+ # putting spaces in the message does not work
+ run_prompt y "Creating tag $newtag" \
+ svn copy --message "$module-${version}.${newsubversion}" $svn/$module/trunk $newtag
+
+ echo "This command does not handle changes in onelab-tags.mk - yet"
+
+
+}
+
+case $0 in
+ *import-module*)
+ import_module $@;;
+ *tag-module*)
+ tag_module $@;;
+ *test*)
+ x=$(figure_module_spec $@) ; echo $x;;
+ *)
+ echo "Unsupported command $0" ; exit 0
+ esac