]> oss.titaniummirror.com Git - tinyos-utils.git/commitdiff
Several improvements to tinyos-mirror.sh
authorR. Steve McKown <rsmckown@gmail.com>
Thu, 9 Apr 2009 20:11:30 +0000 (20:11 +0000)
committerR. Steve McKown <rsmckown@gmail.com>
Thu, 9 Apr 2009 20:11:30 +0000 (20:11 +0000)
* Do not run a default operation if no --option flag set
* No longer replicate tinyos-1.x by default.  We don't need it.
* Smarten up rsync so that it only replicates those parts of the remote CVS
  that are relevant to the modules provided on the command line, or the
  default modules.
* Replace occurrences of $CVSBASE/tinyos with $CVSROOT.
* Put rotation of multiple remote CVS (hard-linked) backups into its own
  function so it can in the future be optionally be disabled.
* Make the locks_present work on a per CVS module basis, so one module won't
  be prevented an import because of a lock in a different module.
* Add a .git/description to the repositories, for a description that will show
  up in gitweb.
* Add an env_ok function to test for the existence of the base directories and
  their permissions.

tinyos-mirror.sh

index d556b50163fcfb1d7b952797cbf45f522b22465c..9c4f5c184ff0b7cc46bb92082782e23248c22db2 100755 (executable)
@@ -3,7 +3,7 @@
 #
 # This utility allows updating a local mirror of the TinyOS CVS modules as
 # a set of three git repositories, one per notable CVS module:
-#      tinyos-1.x -> tinyos-1.x.git
+#      # (don't need) tinyos-1.x -> tinyos-1.x.git
 #      tinyos-2.x -> tinyos-2.x.git
 #      tinyos-2.x-contrib -> tinyos-2.x-contrib.git
 #
 
 # Ensure these variables are correct for your installation
 
-MODULES="tinyos-1.x tinyos-2.x tinyos-2.x-contrib"
+MODULES="tinyos-2.x tinyos-2.x-contrib"
 GITBASE=/var/lib/git
 UPGITBASE=git://hinrg.cs.hju.edu/git
 CVSBASE=/var/lib/cvs
+CVSREPO=tinyos
+CVSROOT=$CVSBASE/$CVSREPO
 UPCVSROOT=:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos
-UPCVSRSYNC=rsync://tinyos.cvs.sourceforge.net/cvsroot/tinyos/
+UPCVSRSYNC=rsync://tinyos.cvs.sourceforge.net/cvsroot/tinyos
 
 # There should be no need to change anything below this line
 
-do_rsync()
+do_backups()
 {
-    echo "Update local CVS mirror via rsync"
+    echo "Rotate local CVS mirror backups"
     links=""
-    if [ -d $CVSBASE/tinyos ]; then
-       if [ -d $CVSBASE/tinyos.backup ]; then
-           if [ -d $CVSBASE/tinyos.backup2 ]; then
-               echo "Mv $CVSBASE/tinyos.backup2 $CVSBASE/tinyos.backup3"
-               mv $CVSBASE/tinyos.backup2 $CVSBASE/tinyos.backup3
+    if [ -d $CVSROOT ]; then
+       if [ -d $CVSROOT.backup ]; then
+           if [ -d $CVSROOT.backup2 ]; then
+               echo "Mv $CVSROOT.backup2 $CVSROOT.backup3"
+               mv $CVSROOT.backup2 $CVSROOT.backup3
            fi
-           echo "Mv $CVSBASE/tinyos.backup $CVSBASE/tinyos.backup2"
-           mv $CVSBASE/tinyos.backup $CVSBASE/tinyos.backup2
-           links="--link-dest=$CVSBASE/tinyos.backup2 $links"
+           echo "Mv $CVSROOT.backup $CVSROOT.backup2"
+           mv $CVSROOT.backup $CVSROOT.backup2
+           links="--link-dest=$CVSROOT.backup2 $links"
        fi
-       echo "Mv $CVSBASE/tinyos -> $CVSBASE/tinyos.backup"
-       mv $CVSBASE/tinyos $CVSBASE/tinyos.backup
-       links="--link-dest=$CVSBASE/tinyos.backup $links"
-       if [ -d $CVSBASE/tinyos.backup3 ]; then
-           echo "Mv $CVSBASE/tinyos.backup3 -> $CVSBASE/tinyos"
-           mv $CVSBASE/tinyos.backup3 $CVSBASE/tinyos
+       echo "Mv $CVSROOT -> $CVSROOT.backup"
+       mv $CVSROOT $CVSROOT.backup
+       links="--link-dest=$CVSROOT.backup $links"
+       if [ -d $CVSROOT.backup3 ]; then
+           echo "Mv $CVSROOT.backup3 -> $CVSROOT"
+           mv $CVSROOT.backup3 $CVSROOT
        fi
     else
-       echo "Cp $CVSBASE/tinyos.backup3 $CVSBASE/tinyos.backup"
-       cp -al $CVSBASE/tinyos.backup $CVS/tinyos # ok to fail
+       echo "Cp $CVSROOT.backup3 $CVSROOT.backup"
+       cp -al $CVSROOT.backup $CVSROOT 2>/dev/null # ok if it errors
     fi
-    echo "Rsync from sourceforge -> $CVSBASE/tinyos"
+}
+
+do_rsync()
+{
+    do_backups
+    echo "Rsync from sourceforge -> $CVSROOT"
     echo "    links: $links"
-    rsync -avz --delete --no-g --chmod=Dg+s,Du+w $links \
-       --exclude "CVSROOT/CVS" \
-       $UPCVSRSYNC $CVSBASE/tinyos/
+    filters="--exclude '/CVSROOT/CVS'"
+    for i in CVSROOT Attic $MODULES; do
+       filters="$filters --include '/$i' --include '/$i/**'"
+    done
+    filters="$filters --exclude '/**'"
+    eval rsync -avz --delete --no-g --chmod=Dg+s,Du+w $links $filters $UPCVSRSYNC/ $CVSROOT
     if [ $? -ne 0 ]; then
        echo "rsync failed"
        exit 1
     fi
 }
 
-locks_present()
-{
-    # git-cvsimport by default skips commits that are not at least 10 minutes
-    # old to try to prevent importing partial commits.  However, because
-    # rsync may take a long time to run, this doesn't really work.  So we look
-    # for lock files and don't sync if they exist.
-    #
-    # For the sf.net tinyos repo, lock files are created with a permissions
-    # level that prevents them from being read by the remote rsync, causing
-    # rsync to error.  For the current configuration of the upstream CVS in
-    # this case, we never really get to test the mettle of this function.
-
-    lines=$(find . -name "#cvs*" | wc -l)
-    if [ $lines -gt 0 ]; then
-       return 0 # locks are present
-    else
-       return 1 # no locks present
-    fi
-}
-
 do_bare()
 {
     # Ensure the bare repos are present
@@ -152,6 +142,17 @@ do_bare()
     done
 }
 
+locks_present()
+{
+    # $1 is the local CVS module to check
+    lines=$(find "$CVSROOT/$1" -name "#cvs*" | wc -l)
+    if [ $lines -gt 0 ]; then
+       return 0 # locks are present
+    else
+       return 1 # no locks present
+    fi
+}
+
 do_import()
 {
     # Now, do the imports.  We limit the number of commits to prevent memory
@@ -166,14 +167,19 @@ do_import()
     fi
     cd $GITBASE/cvsimports
     for i in $MODULES; do
-       echo "Import cvs module $i -> git"
-       git cvsimport -v -o master -d $CVSBASE/tinyos -C $i-import -i -k $i
-       if [ $? -ne 0 ]; then
-           echo "cvsimport failed"
-           exit 1
-       fi
-       if [ ! -f $i-import/.git/description ]; then
-           echo "Mirror of the $i CVS module" > $i.git/description
+       if locks_present $i; then
+           echo "SKIP cvs module $i; locks present in the CVS repo."
+       else
+           echo "Import cvs module $i -> git"
+           git cvsimport -v -o master -d $CVSROOT -C $i-import -i -k \
+                   -L2000 $i
+           if [ $? -ne 0 ]; then
+               echo "cvsimport failed"
+               exit 1
+           fi
+           if [ ! -f $i-import/.git/description ]; then
+               echo "Mirror of the $i CVS module" > $i-import/.git/description
+           fi
        fi
     done
 }
@@ -216,13 +222,9 @@ do_import_localonly()
 {
     # Do the cvs-gitimports from the local CVS.
 
-    if locks_present; then
-       echo "Locks present in the CVS upstream.  We won't import this time."
-    else
-       do_bare
-       do_import
-       do_push
-    fi
+    do_bare
+    do_import
+    do_push
 }
 
 do_import_cvslocal()
@@ -271,8 +273,41 @@ do_import_git()
     fi
 }
 
+env_ok()
+{
+    ret=0
+    if [ ! -d "$GITBASE" ]; then
+       echo "$GITBASE is not a directory" >&2
+       ret=1
+    else
+       if [ $(ls -ld $GITBASE | awk '{ print $1 }') != "drwxr-sr-x" ]; then
+           echo "$GITBASE must have permissions drwxr-sr-x" >&2
+           ret=1
+       fi
+       if [ ! -d "$GITBASE/cvsimports" ]; then
+           echo "$GITBASE/cvsimports is not a directory" >&2
+           ret=1
+       fi
+    fi
+    if [ ! -d "$CVSBASE" ]; then
+       echo "$CVSBASE is not a directory" >&2
+       ret=1
+    else
+       if [ $(ls -ld $CVSBASE | awk '{ print $1 }') != "drwxr-sr-x" ]; then
+           echo "$CVSBASE must have permissions drwxr-sr-x" >&2
+           ret=1
+       fi
+    fi
+    return $ret
+}
+
 # MAIN
 
+if ! env_ok; then
+    echo "$0: no work done" >&2
+    exit 1
+fi
+
 unset option
 unset opt_modules
 while [ -n "$1" ]; do
@@ -304,6 +339,8 @@ elif [ "$option" = "--localonly" ]; then
 elif [ "$option" = "--rsynconly" ]; then
     do_rsync
 else
+    echo "$0: incorrect usage" >&2
+    exit 1
     do_import_git
 fi
 exit 0