From 1e2093ce37e6905b9a4f34c153949fe523866c07 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 29 Mar 2007 01:13:02 -0500 Subject: First attempt at adding git support. --- bin/control_rancid.in | 55 ++++++++++++++++++++++++++++++++++++--------------- bin/rancid-cvs.in | 20 +++++++++++++------ 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/bin/control_rancid.in b/bin/control_rancid.in index 13b15f8..705c3e1 100644 --- a/bin/control_rancid.in +++ b/bin/control_rancid.in @@ -112,7 +112,7 @@ unset noclobber > /dev/null 2>&1 # RCS system RCSSYS=${RCSSYS:=cvs}; -if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then +if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" -s $RCSSYS != "git" ] ; then echo "$RCSSYS is not a valid value for RCSSYS." exit 1 fi @@ -168,17 +168,26 @@ EOF fi fi -# do cvs update of router.db in case anyone has fiddled. -$RCSSYS update router.db > $TMP 2>&1 -grep "^C" $TMP > /dev/null -if [ $? -eq 0 ] ; then - echo "There were $RCSSYS conflicts during update." - echo "" - cat $TMP +# create a .cvsignore +if [ ! -f .cvsignore ] +then + rm -f .cvsignore + cp .cvsignore .gitignore +fi + +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 + grep "^C" $TMP > /dev/null + if [ $? -eq 0 ] ; then + echo "There were $RCSSYS conflicts during update." + echo "" + cat $TMP + rm -f $TMP + exit 1 + fi rm -f $TMP - exit 1 fi -rm -f $TMP if [ ! -f $DIR/router.db ] then @@ -296,7 +305,7 @@ then touch $router if [ $RCSSYS = cvs ] ; then cvs add -ko $router - else + elif [ $RCSSYS = svn ]; then svn add $router fi $RCSSYS commit -m 'new router' $router @@ -326,8 +335,10 @@ cd $DIR/configs for router in `cut -d: -f1 ../routers.up` ; do if [ $RCSSYS = cvs ] ; then cvs status $router | grep -i 'status: unknown' > /dev/null 2>&1 - else + elif [ $RCSSYS = cvs ]; then svn status $router | grep '^?' > /dev/null 2>&1 + else + true fi if [ $? -eq 0 ]; then touch $router @@ -345,7 +356,9 @@ for router in `find . \( -name \*.new -prune -o -name CVS -prune -o -name .svn - grep -i "^$router:" ../router.db > /dev/null 2>&1 if [ $? -eq 1 ]; then rm -f $router - $RCSSYS delete $router + if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then + $RCSSYS delete $router + fi $RCSSYS commit -m 'deleted router' $router echo "Deleted $router" fi @@ -447,8 +460,10 @@ 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 -else +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 if [ $alt_mailrcpt -eq 1 ] ; then @@ -457,10 +472,18 @@ else subject="router config diffs" fi if [ "X$device" != "X" ] ; then - $RCSSYS commit -m "updates - courtesy of $mailrcpt" + 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 subject="$GROUP/$device $subject" else - $RCSSYS commit -m updates + if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then + $RCSSYS commit -m "updates" + else + git commit -m "updates" $GROUP/configs + fi subject="$GROUP $subject" fi diff --git a/bin/rancid-cvs.in b/bin/rancid-cvs.in index 86ca065..3943348 100644 --- a/bin/rancid-cvs.in +++ b/bin/rancid-cvs.in @@ -87,7 +87,7 @@ cd $BASEDIR # RCS system RCSSYS=${RCSSYS:=cvs}; -if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then +if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" -a $RCSSYS != "git" ] ; then echo "$RCSSYS is not a valid value for RCSSYS." exit 1 fi @@ -96,8 +96,12 @@ fi if [ ! -d $CVSROOT ]; then if [ $RCSSYS = cvs ]; then cvs -d $CVSROOT init - else + 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 fi fi @@ -127,7 +131,7 @@ do cvs import -m "$GROUP" $GROUP new rancid cd $BASEDIR cvs checkout $GROUP - else + elif [ $RCSSYS = svn ]; then svn import -m "$GROUP" . file://$CVSROOT/$GROUP cd $BASEDIR svn checkout file://$CVSROOT/$GROUP $GROUP @@ -136,8 +140,10 @@ do cd $DIR if [ ! -d configs ]; then mkdir configs - $RCSSYS add configs - $RCSSYS commit -m 'new' configs + if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then + $RCSSYS add configs + $RCSSYS commit -m 'new' configs + fi fi # main files @@ -152,7 +158,9 @@ do fi if [ ! -f router.db ]; then touch router.db - $RCSSYS add router.db + if [ $RCSSYS = cvs -o $RCSSYS = svn ]; then + $RCSSYS add router.db + fi $RCSSYS commit -m 'new' router.db fi done -- cgit