]> oss.titaniummirror.com Git - tinyos-utils.git/blobdiff - tinyos-mirror.sh
Several improvements to tinyos-mirror.sh
[tinyos-utils.git] / tinyos-mirror.sh
index 1f75bdcab9ca2e593a7d6d1ced986734c264f04a..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
 #
@@ -34,7 +34,7 @@
 #
 # Usage:
 #
-# tinyos-mirror.sh [--cvslocal|--cvsdirect|--localonly] [module [module ...]]
+# tinyos-mirror.sh [--cvslocal|--cvsdirect|--localonly|--rsynconly] [module [module ...]]
 #    No --xxx option implies update from upstream git.
 #    No module(s) implies update of all as defined in $MODULES.
 #
@@ -44,6 +44,8 @@
 # 2. To create or update the local git repos from the upstream CVS source,
 #    which may be more definitive but much slower, run tinyos-mirror.sh with
 #    the --cvslocal option.
+#      --rsynconly does only the rsync update of the remote CVS to local CVS.
+#      --localonly does everything of --cvslocal except the rsync.
 #
 # 3. To update (not create!) the local git repos from the upstream CVS source
 #    directly via pserver (see the UPCVSROOT variable), then run the
 #    perhaps faster than option #2 above if relatively few changesets have
 #    been added upstream since the last invocation of tinyos-mirror.sh.
 #
-# 4. If you just wish to update the final git repositories with the interim
-#    git repositories created by --cvslocal, then give --localonly.  You can
-#    do a full recreate of the final git repo this way by first removing it,
-#    from /var/lib/git/<module>.git.  --localonly only updates the final git
-#    module to the state of the /var/lib/git/cvsimports/<module>-import repo.
-#
 # It should be possible to invoke tinyos-mirror.sh using different update
 # methods without creating problems.  We have tested creating and initially
 # populating the local git repos using --cvslocal and then following with
 
 # 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-p --no-g --chmod=Dg+s,Du+w,Fu+w $links \
-       $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()
-{
-    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
@@ -136,6 +133,7 @@ do_bare()
                echo "git init failed"
                exit 1
            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.
@@ -144,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
@@ -158,12 +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 \
-           -L2000 $i
-       if [ $? -ne 0 ]; then
-           echo "cvsimport 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 -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
 }
@@ -202,19 +218,22 @@ do_import_cvsdirect()
     done
 }
 
+do_import_localonly()
+{
+    # Do the cvs-gitimports from the local CVS.
+
+    do_bare
+    do_import
+    do_push
+}
+
 do_import_cvslocal()
 {
     # Do the imports by first using rsync to sync a local CVS from sf.net,
     # then do cvs-gitimports from the local CVS.
 
     do_rsync
-    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_import_localonly
 }
 
 do_import_git()
@@ -241,7 +260,7 @@ do_import_git()
            ln -s ../$i.git $i.git/.git
        else
            echo "Pull gitupstream -> $i.git"
-           git --git-dir=$i.git fetch $UPGITBASE/$i.git
+           git --git-dir=$i.git fetch $UPGITBASE/$i.git master:master
            if [ $? -ne 0 ]; then
                echo "git fetch failed"
                fail=$(($fail + 1))
@@ -254,13 +273,46 @@ 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
     if echo "$1" | grep -q -- "--"; then
-       if [ "$1" = "--cvslocal" -o "$1" = "--cvsdirect" ]; then
+       if [ "$1" = "--cvslocal" -o "$1" = "--cvsdirect" -o "$1" = "--localonly" -o "$1" = "--rsynconly" ]; then
            if [ -z "$option" ]; then
                option=$1
            fi
@@ -283,8 +335,12 @@ if [ "$option" = "--cvsdirect" ]; then
 elif [ "$option" = "--cvslocal" ]; then
     do_import_cvslocal
 elif [ "$option" = "--localonly" ]; then
-    do_push
+    do_import_localonly
+elif [ "$option" = "--rsynconly" ]; then
+    do_rsync
 else
+    echo "$0: incorrect usage" >&2
+    exit 1
     do_import_git
 fi
 exit 0