summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2007-03-29 09:44:10 -0500
committerJeffrey C. Ollie <jeff@ocjtech.us>2008-02-13 14:50:29 -0600
commita7804ee1e93db466896e57683c44a3cd81c4290b (patch)
tree6893ba33fff9a6fb3fa62afa9d15155286ab56c8
parent1e2093ce37e6905b9a4f34c153949fe523866c07 (diff)
downloadrancid-a7804ee1e93db466896e57683c44a3cd81c4290b.zip
rancid-a7804ee1e93db466896e57683c44a3cd81c4290b.tar.gz
rancid-a7804ee1e93db466896e57683c44a3cd81c4290b.tar.xz
More work on git.
-rw-r--r--bin/control_rancid.in149
-rw-r--r--bin/rancid-cvs.in116
2 files changed, 190 insertions, 75 deletions
diff --git a/bin/control_rancid.in b/bin/control_rancid.in
index 705c3e1..fc8ce14 100644
--- a/bin/control_rancid.in
+++ b/bin/control_rancid.in
@@ -158,6 +158,7 @@ then
rm -f .cvsignore
cat >.cvsignore <<EOF
.cvsignore
+.gitignore
routers.all
routers.down
routers.up
@@ -175,6 +176,7 @@ then
cp .cvsignore .gitignore
fi
+### FIXME: if $RCSSYS = git do we need to do anything here?
if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
# do cvs update of router.db in case anyone has fiddled.
$RCSSYS update router.db > $TMP 2>&1
@@ -302,13 +304,25 @@ then
IFS=$OFS
router=$1
+ message='new router'
touch $router
- if [ $RCSSYS = cvs ] ; then
- cvs add -ko $router
- elif [ $RCSSYS = svn ]; then
- svn add $router
- fi
- $RCSSYS commit -m 'new router' $router
+ case $rcssys in
+ cvs )
+ cvs add -ko $router
+ cvs commit -m $message $router
+ ;;
+ svn )
+ svn add $router
+ svn commit -m $message $router
+ ;;
+ git )
+ (
+ flock -x 200
+ git add $router
+ git commit -m $message
+ ) 200>$BASEDIR/.lockfile
+ ;;
+ esac
echo "Added $router"
done
echo
@@ -333,33 +347,56 @@ trap 'rm -fr $TMP;' 1 2 15
cd $DIR/configs
# check for 'up' routers missing in RCS. no idea how this happens to some folks
for router in `cut -d: -f1 ../routers.up` ; do
- if [ $RCSSYS = cvs ] ; then
- cvs status $router | grep -i 'status: unknown' > /dev/null 2>&1
- elif [ $RCSSYS = cvs ]; then
- svn status $router | grep '^?' > /dev/null 2>&1
- else
- true
- fi
- if [ $? -eq 0 ]; then
- touch $router
- if [ $RCSSYS = cvs ] ; then
- cvs add -ko $router
- else
- svn add $router
- fi
- echo "$RCSSYS added missing router $router"
- fi
+ case $RCSSYS in
+ cvs )
+ cvs status $router | grep -i 'status: unknown' > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ touch $router
+ cvs add -ko $router
+ echo "$RCSSYS added missing router $router"
+ fi
+ ;;
+ svn )
+ svn status $router | grep '^?' > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ touch $router
+ svn add $router
+ echo "$RCSSYS added missing router $router"
+ fi
+ ;;
+ git )
+ git ls-files $router > /dev/null 2>&1
+ if [ $? -eq 1 ]; then
+ touch $router
+ (
+ flock -x 200
+ git add $router
+ git commit -m "added missing router $router"
+ ) 200>$BASEDIR/.lockfile
+ echo "$RCSSYS added missing router $router"
+ fi
+ ;;
+ esac
done
echo
# delete configs from RCS for routers not listed in routers.up.
-for router in `find . \( -name \*.new -prune -o -name CVS -prune -o -name .svn -prune \) -o -type f -print | sed -e 's/^.\///'` ; do
+for router in `find . \( -name \*.new -prune -o -name CVS -prune -o -name .svn -prune -o -name .git -prune \) -o -type f -print | sed -e 's/^.\///'` ; do
grep -i "^$router:" ../router.db > /dev/null 2>&1
if [ $? -eq 1 ]; then
rm -f $router
- if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
- $RCSSYS delete $router
- fi
- $RCSSYS commit -m 'deleted router' $router
+ case $RCSSYS in
+ cvs | svn )
+ $RCSSYS delete $router
+ $RCSSYS commit -m "deleted router $router" $router
+ ;;
+ git )
+ (
+ flock -x 200
+ git rm $router
+ git commit -m "deleted router $router"
+ ) 200>$BASEDIR/.lockfile
+ ;;
+ esac
echo "Deleted $router"
fi
done
@@ -369,7 +406,19 @@ cd $DIR
if [ ! -s routers.up ]
then
# commit router.db
- $RCSSYS commit -m updates router.db
+ message="updates"
+ case $RCSSYS in
+ cvs | svn )
+ $RCSSYS commit -m $message router.db
+ ;;
+ git )
+ (
+ flock -x 200
+ git add router.db
+ git commit -m $message
+ ) 200>$BASEDIR/.lockfile
+ ;;
+ esac
exit;
fi
@@ -457,14 +506,18 @@ done
# Diff the directory and then checkin.
trap 'rm -fr $TMP $TMP.diff $DIR/routers.single;' 1 2 15
cd $DIR
-if [ $RCSSYS = "cvs" ] ; then
- cvs -f @DIFF_CMD@ -ko | sed -e '/^RCS file: /d' -e '/^--- /d' \
- -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
-elif [ $RCSSYS = "svn" ]; then
- svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
-else
- git diff $GROUP/configs | sed -e '/^diff /d' -e '/^index /'d -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
-fi
+case $RCSSYS in
+ cvs )
+ cvs -f @DIFF_CMD@ -ko | sed -e '/^RCS file: /d' -e '/^--- /d' \
+ -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
+ ;;
+ svn )
+ svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
+ ;;
+ git )
+ git diff $GROUP/configs | sed -e '/^diff /d' -e '/^index /'d -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
+ ;;
+esac
if [ $alt_mailrcpt -eq 1 ] ; then
subject="router config diffs - courtesy of $mailrcpt"
@@ -472,20 +525,24 @@ else
subject="router config diffs"
fi
if [ "X$device" != "X" ] ; then
- if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
- $RCSSYS commit -m "updates - courtesy of $mailrcpt"
- else
- git commit -m "updates - courtesy of $mailrcpt" $GROUP/configs
- fi
+ message="updates - courtesy of $mailrcpt"
subject="$GROUP/$device $subject"
else
- if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
- $RCSSYS commit -m "updates"
- else
- git commit -m "updates" $GROUP/configs
- fi
+ message="updates"
subject="$GROUP $subject"
fi
+case $RCSSYS in
+ cvs | svn )
+ $RCSSYS commit -m $message
+ ;;
+ git )
+ (
+ flock -x 200
+ git add $GROUP/configs
+ git commit -m $message
+ ) 200>$BASEDIR/.lockfile
+ ;;
+esac
# Mail out the diffs (if there are any).
if [ -s $TMP.diff ]
diff --git a/bin/rancid-cvs.in b/bin/rancid-cvs.in
index 3943348..3891d98 100644
--- a/bin/rancid-cvs.in
+++ b/bin/rancid-cvs.in
@@ -87,21 +87,44 @@ cd $BASEDIR
# RCS system
RCSSYS=${RCSSYS:=cvs};
-if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" -a $RCSSYS != "git" ] ; then
- echo "$RCSSYS is not a valid value for RCSSYS."
- exit 1
-fi
+case $RCSSYS in
+ cvs | svn )
+ # we're good
+ ;;
+ git )
+ # force $CVSROOT
+ CVSROOT=$BASEDIR/.git
+ ;;
+ * )
+ echo "$RCSSYS is not a valid value for RCSSYS."
+ exit 1
+ ;;
+esac
# Top level CVS stuff
if [ ! -d $CVSROOT ]; then
- if [ $RCSSYS = cvs ]; then
- cvs -d $CVSROOT init
- elif [ $RCSSYS = svn ]; then
- svnadmin create $CVSROOT @SVN_FSTYPE@
- else
- # git does not use $CVSROOT, instead configs are stored in $BASEDIR
- git init
- echo "logs" >> .gitignore
+ case $RCSSYS in
+ cvs )
+ cvs -d $CVSROOT init
+ ;;
+ svn )
+ svnadmin create $CVSROOT @SVN_FSTYPE@
+ ;;
+ git )
+ # git does not use $CVSROOT, instead configs are stored in $BASEDIR
+ (
+ flock -x 200
+ git init
+ rm -f .gitignore
+ echo "/logs" >> .gitignore
+ echo "/.lockfile" >> .gitignore
+ echo "*~" >> .gitignore
+ echo ".#*" >> .gitignore
+ echo ".cvsignore" >> .gitignore
+ echo "*.new" >> .gitignore
+ git add .gitignore
+ git commit -m "Initializing repository."
+ ) 200>$BASEDIR/.lockfile
fi
fi
@@ -127,23 +150,48 @@ do
if [ ! -d $DIR ]; then
mkdir -p $DIR
cd $DIR
- if [ $RCSSYS = cvs ]; then
- cvs import -m "$GROUP" $GROUP new rancid
- cd $BASEDIR
- cvs checkout $GROUP
- elif [ $RCSSYS = svn ]; then
- svn import -m "$GROUP" . file://$CVSROOT/$GROUP
- cd $BASEDIR
- svn checkout file://$CVSROOT/$GROUP $GROUP
- fi
+ case $RCSSYS in
+ cvs )
+ cvs import -m "$GROUP" $GROUP new rancid
+ cd $BASEDIR
+ cvs checkout $GROUP
+ ;;
+ svn )
+ svn import -m "$GROUP" . file://$CVSROOT/$GROUP
+ cd $BASEDIR
+ svn checkout file://$CVSROOT/$GROUP $GROUP
+ ;;
+ git )
+ cd $BASEDIR
+ echo "$GROUP/routers.all" >> .gitignore
+ echo "$GROUP/routers.down" >> .gitignore
+ echo "$GROUP/routers.up" >> .gitignore
+ echo "$GROUP/routers.mail" >> .gitignore
+ echo "$GROUP/routers.added" >> .gitignore
+ echo "$GROUP/routers.deleted" >> .gitignore
+ echo "$GROUP/routers.single" >> .gitignore
+ echo "$GROUP/routers.up.missed" >> .gitignore
+ echo "$GROUP/routers.failed" >> .gitignore
+ (
+ flock -x 200
+ git add .gitignore
+ git commit -m "Update .gitignore"
+ ) 200>$BASEDIR/.lockfile
+ ;;
+ esac
fi
cd $DIR
if [ ! -d configs ]; then
mkdir configs
- if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
- $RCSSYS add configs
- $RCSSYS commit -m 'new' configs
- fi
+ case $RCSSYS in
+ cvs | svn )
+ $RCSSYS add configs
+ $RCSSYS commit -m 'new' configs
+ ;;
+ git )
+ # nothing to be done here
+ ;;
+ esac
fi
# main files
@@ -158,9 +206,19 @@ do
fi
if [ ! -f router.db ]; then
touch router.db
- if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then
- $RCSSYS add router.db
- fi
- $RCSSYS commit -m 'new' router.db
+ case $RCSSYS in
+ cvs | svn )
+ $RCSSYS add router.db
+ $RCSSYS commit -m 'new' router.db
+ ;;
+ git )
+ git add
+ (
+ flock -x 200
+ git add router.db
+ git commit -m "Initializing $GROUP"
+ ) 200>$BASEDIR/.lockfile
+ ;;
+ esac
fi
done