#
# 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
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
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
}
{
# 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()
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
elif [ "$option" = "--rsynconly" ]; then
do_rsync
else
+ echo "$0: incorrect usage" >&2
+ exit 1
do_import_git
fi
exit 0