--- /dev/null
+#!/bin/bash
+#
+# $Id$
+#
+
+date=$(date +%Y-%m-%d)
+
+#### REVIEW this carefully
+module=new_plc_api
+cvstag=planetlab-4_0-rc3
+previous=002-rc3-2007-05-02
+next=003-${cvstag}-${date}
+
+####
+svn="svn+ssh://thierry@svn.one-lab.org/svn"
+cvs=":pserver:anon@cvs.planet-lab.org:/cvs"
+import=$HOME/import-$module-$date
+
+
+function message () {
+ echo -n '-------------------- '
+ echo $@
+ echo -n 'Enter return to proceed .. '
+ read x
+}
+
+function run () {
+ echo -n '-------------------- '
+ message="$1" ; shift
+ echo $message
+
+ echo -n 'PWD=' ; pwd
+ echo RUNNING $@
+ $@
+}
+
+function run_prompt () {
+ default="$1" ; shift
+ message="$1" ; shift
+ case "$default" in
+ y|Y) label="[y]/n" ;;
+ n|N) label="y/[n]" ;;
+ *) label="y/n (no default)" ;;
+ esac
+
+ echo -n '-------------------- '
+ echo $message
+
+ echo -n 'PWD= ' ; pwd
+ echo -n "want to run $@ $label ? "
+ read answer
+ [ -z "$answer" ] && answer=$default
+ while true; do
+ case $answer in
+ y|Y)
+ $@
+ break
+ ;;
+ n|N)
+ echo 'Skipped'
+ break
+ ;;
+ *)
+ echo 'Please enter y or n'
+ ;;
+ esac
+ done
+}
+
+function run_loop () {
+ message="$1" ; shift
+ while true; do
+ echo -n '-------------------- '
+ echo $message
+ echo -n PWD= ; pwd
+ echo Running $@
+ $@
+ echo -n 'OK ? y/[n] '
+ read answer
+ [ -z "$answer" ] && answer=n
+ case $answer in
+ y|Y)
+ break ;;
+ *) ;;
+ esac
+done
+}
+
+### echoes OK on stdout if url exists
+function svn_url_check () {
+ url=$1; shift
+ svn list $url &> /dev/null && echo OK
+}
+
+### return 'y' or 'n' for being used as prompt
+function svn_url_needs_creation () {
+ url=$1; shift
+ if [ -n "$(svn_url_check $url)" ] ; then echo n ; else echo y ; fi
+}
+
+function dir_needs_creation () {
+ dir=$1; shift
+ if [ -d "$dir" ] ; then echo n ; else echo y ; fi
+}
+
+##############################
+##############################
+##############################
+
+cat <<EOF
+####### WARNING
+
+ this script is quite rough and should be used with care
+
+ I am slowly trying to automate this painful process,
+
+ so again : USE WITH CARE
+
+module=$module
+previous=$previous
+next=$next
+cvstag=$cvstag
+
+svn=$svn
+cvs=$cvs
+date=$date
+import=$import
+####### WARNING
+
+EOF
+
+function run_test () {
+ message Hi there
+ run_prompt n "going to /etc" cd /etc
+ run_prompt y "going to /etc" cd /etc
+ run_prompt y "Cleaning up /foobar" rmdir /foobar
+ run_prompt $(dir_needs_creation /foobar) "create unexisting dir /foobar" mkdir /foobar
+ run_prompt $(dir_needs_creation /var) "create existing dir /var" mkdir /var
+ run_prompt y "Cleaning up /foobar" rmdir /foobar
+
+ run_loop "Check this and that" ls -ls passwd
+ run "Listing passwd" ls -ls passwd
+ 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
+
+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
+
+# 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_prompt $(dir_needs_creation $import/$module/imports) "Creating working dir " \
+ mkdir -p $import/$module/imports
+
+###
+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 "Going there" \
+ cd $import/$module/imports
+
+message 'NOTE: the way we merge changes right below might need to be tested/improved'
+
+run_prompt n "Incorporating changes since import-$previous in import-$next" \
+ cvs -d $cvs export -r $cvstag -d import-$next $module
+
+run "Going to import-$next" \
+ cd $import/$module/imports/import-$next
+
+run_loop "Check the changes in import-$next -- no conflict expected" svn status $import/$module/imports/import-$next
+
+run_prompt n "CHECKING IN changes in import-$next" \
+ svn ci -m "Changes since $previous"
+
+###
+run "Going to $import/$module" \
+ cd $import/$module
+
+run_prompt $(dir_needs_creation $svn/$module/trunk) "Checking out trunk for applying changes" \
+ svn co $svn/$module/trunk
+
+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_loop "Check the changes in trunk -- conflicts should get resolved" svn status trunk
+
+run_prompt n "CHECKING IN changes in trunk" \
+ svn ci -m "Merged changes from import-$previous to import-$next"
+
+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'
+exit 0