summaryrefslogtreecommitdiffstats
path: root/bin/control_rancid.in
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2001-02-05 17:47:18 +0000
committerTar Committer <tar@ocjtech.us>2001-02-05 17:47:18 +0000
commitb88919bea4b222a616adbdd2b82fc262a14afc8d (patch)
treea75da71b0e2f905f35d2d7cbfd161df97a3d2c63 /bin/control_rancid.in
parent25c2b7c2c8a333b276c3499bcce004137d4b4fe0 (diff)
downloadrancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.tar.gz
rancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.tar.xz
rancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.zip
Imported from rancid-2.1.tar.gz.rancid-2.1
Diffstat (limited to 'bin/control_rancid.in')
-rwxr-xr-xbin/control_rancid.in64
1 files changed, 40 insertions, 24 deletions
diff --git a/bin/control_rancid.in b/bin/control_rancid.in
index 2acecc7..58f6211 100755
--- a/bin/control_rancid.in
+++ b/bin/control_rancid.in
@@ -28,38 +28,61 @@ if [ $# -lt 1 ]; then
else
GROUP=$1
fi
-TMP=/var/tmp/rancid.$GROUP.$$
DIR=$BASEDIR/$GROUP
+TMP=${TMPDIR:=/tmp}/rancid.$GROUP.$$
+trap 'rm -fr $TMP;' 1 2 15
# Bail if we do not have the necessary info to run
if [ ! -d $DIR ]
then
+ echo "$DIR does not exist."
+ echo "Run bin/create_cvs $GROUP to make all of the needed directories."
(
echo "$DIR does not exist."
- ) | Mail -s "no $GROUP directory" rancid-admin-$GROUP
+ echo "Run bin/create_cvs $GROUP to make all of the needed directories."
+ ) | Mail -s "no $GROUP directory" @MAILPLUS@admin-$GROUP
exit 1
fi
+
+# do cvs update of router.db in case anyone has fiddled.
+cd $DIR
+cvs update router.db > $TMP 2>&1
+grep "^C" $TMP > /dev/null
+if [ $? -eq 0 ] ; then
+ echo "There were CVS conflicts during update."
+ echo ""
+ cat $TMP
+ rm -f $TMP
+ exit 1
+fi
+rm -f $TMP
+
if [ ! -f $DIR/router.db ]
then
(
echo "$DIR/router.db does not exist."
- ) | Mail -s "no $GROUP/router.db file" rancid-admin-$GROUP
+ ) | Mail -s "no $GROUP/router.db file" @MAILPLUS@admin-$GROUP
exit 1;
elif [ ! -s $DIR/router.db ]
then
exit
fi
-# generate the list of routers we should try to fetch
+# generate the list of all, up, & down routers
cd $DIR
+trap 'rm -fr routers.db routers.all.new routers.down.new routers.up.new \
+ $TMP;' 1 2 15
grep -v '^#' router.db > routers.db
cut -d: -f1,2 routers.db | sort -u > routers.all.new
+if [ ! -f routers.all ] ; then touch routers.all; fi
diff routers.all routers.all.new > /dev/null 2>&1; RALL=$?
-@PERLV_PATH@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n")
+@PERLV@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n")
if ($F[2] =~ /^down$/i);}' routers.db | sort -u > routers.down.new
+if [ ! -f routers.down ] ; then touch routers.down; fi
diff routers.down routers.down.new > /dev/null 2>&1; RDOWN=$?
-@PERLV_PATH@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n")
+@PERLV@ -F: -ane '{($F[0] =~ tr@A-Z@a-z@,print "$F[0]:$F[1]\n")
if ($F[2] =~ /^up$/i);}' routers.db | sort -u > routers.up.new
+if [ ! -f routers.up ] ; then touch routers.up; fi
diff routers.up routers.up.new > /dev/null 2>&1; RUP=$?
if [ $RALL -ne 0 -o $RDOWN -ne 0 -o $RUP -ne 0 ]
@@ -96,7 +119,7 @@ then
) > routers.mail
if [ -s routers.mail ] ; then
- Mail -s "changes in $GROUP routers" rancid-admin-$GROUP < routers.mail
+ Mail -s "changes in $GROUP routers" @MAILPLUS@admin-$GROUP < routers.mail
fi
rm -f routers.mail
@@ -124,11 +147,12 @@ mv routers.all.new routers.all
mv routers.down.new routers.down
mv routers.up.new routers.up
rm -f routers.db
+trap 'rm -fr $TMP;' 1 2 15
# cvs delete configs for routers not listed in routers.up.
cd $DIR/configs
for router in `find . \( -name \*.new -prune -o -name CVS -prune \) -o -type f -print | sed -e 's/^.\///'` ; do
- grep "^$router:" ../router.db > /dev/null 2>&1
+ grep -i "^$router:" ../router.db > /dev/null 2>&1
if [ $? -eq 1 ]; then
rm -f $router
cvs delete $router
@@ -207,26 +231,17 @@ rename 's/.new$//' *.new
# This has been different for different machines...
# Diff the directory and then checkin.
+trap 'rm -fr $TMP $TMP.diff;' 1 2 15
cd $DIR
-#cvs diff -c3 >$TMP.diff
-#cvs diff -C 3 >$TMP.diff
-# Change the output of a unified diff to make it a bit more readable.
-cat > $TMP.sedf << EOF
-/^RCS file: /d
-#/^retrieving revision /d
-/^--- /d
-/^+++ /d
-s/^\([-+ ]\)/\1 /
-EOF
-cvs -f diff -u -4 | sed -f $TMP.sedf >$TMP.diff
-rm -f $TMP.sedf
+cvs -f @DIFF_CMD@ | sed -e '/^RCS file: /d' -e '/^--- /d' \
+ -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
cvs commit -m updates
# Mail out the diffs (if there are any).
if [ -s $TMP.diff ]; then
sendmail -t <<EMAIL
-To: rancid-$GROUP
+To: @MAILPLUS@$GROUP
Subject: $GROUP router config diffs
Precedence: bulk
@@ -241,7 +256,7 @@ rm -f $DIR/routers.failed
if [ "X$OLDTIME" = "X" ] ; then
OLDTIME=24
fi
-@PERLV_PATH@ -F: -ane "{\$t = (stat(\$F[0]))[9]; print \`ls -ld \$F[0]\`
+@PERLV@ -F: -ane "{\$t = (stat(\$F[0]))[9]; print \`ls -ld \$F[0]\`
if (time() - \$t >= $OLDTIME*60*60);}" $DIR/routers.up | sort -u > $DIR/routers.failed
if [ -s $DIR/routers.failed ]
then
@@ -252,8 +267,9 @@ than $OLDTIME hours.
END
cat $DIR/routers.failed
- ) | Mail -s "config fetcher problems - $GROUP" rancid-admin-$GROUP
+ ) | Mail -s "config fetcher problems - $GROUP" @MAILPLUS@admin-$GROUP
fi
# Cleanup
-rm -f $TMP.diff $TMP.lst
+rm -f $TMP.diff
+trap '' 1 2 15