Gheek.net

June 26, 2008

rancid-rev_sh.txt

Filed under: rancid, shell scripts — lancevermilion @ 10:58 am

shell script to diff rancid configs in cvs

#!/bin/bash

# rancid-rev  -  for use with rancid implementation.
#  -- mikeb 10/05/00
#  -- lancev 01/12/06

CVSROOT='/usr/local/rancid/var/CVS';
export CVSROOT;

cd /usr/local/rancid/var/networking

if [ -z "$1" ]; then
  while [ -z "$router" ]; do
    echo -n "Router name: "
    read router
  done
else
  router=`echo $1 | sed 's/.abc.com//g'`
  router="$1"
fi

#if [ -z "$2" ]; then
#  while [ -z "$date" ]; do
#    echo -n "Date (YYYY-MM-DD): "
#    read date
#  done
#else
#  date="$2"
#fi

if [ -z "$2" ]; then
#cvs history -D $date -e -a -w $router | ( while read a
cvs history -e -a -w $router | ( while read a
do
  if [ ! -z "`echo $a | cut -f6 -d' ' | grep \"[0-9]\.[0-9][0-9]\"`" ]; then
    echo $a | sed 's/^.\ //'
  fi
done ) | egrep -v "configs$" | sort
cvsdisplayed="yes"

echo -n "Enter 1st revision number: "
while [ -z "$rev" ]; do
  read rev
done
else
  rev=$2
fi

if [ -z "$3" ]; then
  echo -n "Enter a 2nd revision number (y/N): "
  read rev2ans
  if [ "$rev2ans" = "y" ]; then
    if [ -z "$cvsdisplayed" ]; then
      cvs history -e -a -w $router | ( while read a
      do
        if [ ! -z "`echo $a | cut -f6 -d' ' | grep \"[0-9]\.[0-9][0-9]\"`" ]; then
          echo $a | sed 's/^.\ //'
        fi
      done ) | egrep -v "configs$" | sort
    fi
    echo -n "Enter 2nd revision number: "
    while [ -z "$rev2" ]; do
      read rev2
    done
  fi
else
  rev2=$3
fi

cd configs/
if [ -z "$rev2" ]; then
  cvs diff -Naur $rev $router | more
else
  cvs diff -r $rev -r $rev2 $router | more
fi

#
# Currently it will only build a config from
# the 1st rev against the current config in cvs.
#
echo -n "Build config based on diff? (y/N): "
read build
if [ "$build" = "y" ]; then
  cp $router $HOME
  cvs diff -r $rev $router | ( cd $HOME; patch -R )
  echo "Config based on revision $rev in $HOME/$router"
fi
Advertisement

Create a free website or blog at WordPress.com.