]> oss.titaniummirror.com Git - tinyos-utils.git/blobdiff - tinyos-mirror.sh
tos-maketags: support for VARIANT and SENSORBOARD
[tinyos-utils.git] / tinyos-mirror.sh
index d0f66045e3aa1315c4b5b90a9c811d0c94ed63a1..d459503af2742b51b4941e5bc803e14acd590e72 100755 (executable)
@@ -1,10 +1,16 @@
 #!/bin/bash
 # tinyos-mirror.sh - Maintain a local git mirror of the tinyos CVS repository.
 #
+# ------
+# NOTE: On or shortly after 2010-07-12, the official TinyOS repository was
+# migrated from CVS to Subversion, at http://tinyos-main.googlecode.com/svn.
+# As of this writing, tinyos-2.x-contrib remains hosted on CVS at sf.net.
+# ------
+#
 # 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
-#      tinyos-2.x -> tinyos-2.x.git
+#      # (don't need) tinyos-1.x -> tinyos-1.x.git
+#      # (deprecated) tinyos-2.x -> tinyos-2.x.git
 #      tinyos-2.x-contrib -> tinyos-2.x-contrib.git
 #
 # The utility actually allows both for creation and update of the local
 
 # Ensure these variables are correct for your installation
 
-MODULES="tinyos-1.x tinyos-2.x tinyos-2.x-contrib"
+MODULES="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
+
+# Uncomment this or export DEBUG=-v in your shell to get verbose output
+#DEBUG=-v
 
 # 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 -az $DEBUG --delete --no-g --chmod=Dg+s,Du+w $links $filters \
+       $UPCVSRSYNC/ $CVSROOT
     if [ $? -ne 0 ]; then
        echo "rsync failed"
        exit 1
     fi
 }
 
-locks_present()
-{
-    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
@@ -135,50 +145,41 @@ do_bare()
            fi
            echo "Mirror of the $i CVS module" > $i.git/description
 
-           # This line allows us to do cvsimport directly into this git repo,
-           # as git-cvsimport doesn't know how to work with bare repos.
+           # git-cvsimport doesn't know how to work with bare repos, so
+           # create in each repo a .git that is a symlink to itself.
            ln -s ../$i.git $i.git/.git
        fi
     done
 }
 
-do_import()
+locks_present()
 {
-    # Now, do the imports.  We limit the number of commits to prevent memory
-    # leaks from taking out the VE.  This command is incremental, just adding
-    # new commits since the last run.
-    if [ ! -d $GITBASE/cvsimports ]; then
-       rm -rf $GITBASE/cvsimports
-       mkdir $GITBASE/cvsimports
-       chgrp repo $GITBASE/cvsimports
-       chmod 755 $GITBASE/cvsimports
-       chmod g+s $GITBASE/cvsimports
+    # $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
-    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
-       fi
-    done
 }
 
-do_push()
+do_import()
 {
-    # Now we need to push the new commits in each of the import repos into the
-    # bare repos which are the pseudo-centralized shared repos.
-    cd $GITBASE/cvsimports
+    # Now, do the imports.  We limit the number of commits to prevent memory
+    # leaks from taking out the VE.  This command is incremental, just adding
+    # new commits since the last run.
+    cd $GITBASE
     for i in $MODULES; do
-       echo "Push git import module cvsimports/$i-import -> $i.git"
-       git --git-dir=$i-import/.git push --mirror ../$i.git/
-       if [ $? -ne 0 ]; then
-           echo "git push failed"
-           exit 1
+       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 $DEBUG -o master -d $CVSROOT -C $i.git -i -k \
+                   -L2000 $i
+           if [ $? -ne 0 ]; then
+               echo "cvsimport failed"
+               exit 1
+           fi
        fi
     done
 }
@@ -191,10 +192,11 @@ do_import_cvsdirect()
     # memory  leaks from taking out the VE.  This command is incremental, just
     # adding new commits since the last run.
 
+    echo "Importing directly from remote CVS repository"
     cd $GITBASE
     for i in $MODULES; do
        echo "Update from CVS module DIRECT $i -> git"
-       git cvsimport -v -o master -d $UPCVSROOT -C $i.git -i -k -L2000 $i
+       git cvsimport $DEBUG -o master -d $UPCVSROOT -C $i.git -i -k -L2000 $i
        if [ $? -ne 0 ]; then
            echo "cvsimport failed"
            exit 1
@@ -206,13 +208,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
+    echo "Importing from local copy of remote CVS repository"
+    do_bare
+    do_import
 }
 
 do_import_cvslocal()
@@ -231,6 +229,7 @@ do_import_git()
     # tinyos-1.x is 14 months old when the last update was 3/17/09, and
     # tinyos-2.x-contrib.git is 5 months old when the last update was 4/7/09.
 
+    echo "Importing from remote git repositories"
     fail=0
     cd $GITBASE
     for i in $MODULES; do
@@ -261,8 +260,37 @@ 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
+    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
@@ -283,7 +311,7 @@ done
 if [ -n "$opt_modules" ]; then
     MODULES="$opt_modules"
 fi
-echo "Updating modules $MODULES"
+echo "Updating modules: $MODULES"
 
 if [ "$option" = "--cvsdirect" ]; then
     do_import_cvsdirect
@@ -294,6 +322,9 @@ elif [ "$option" = "--localonly" ]; then
 elif [ "$option" = "--rsynconly" ]; then
     do_rsync
 else
+    echo "$0: incorrect usage" >&2
+    exit 1
     do_import_git
 fi
+echo "Import actions complete."
 exit 0