❦ 9 décembre 2013 11:09 CET, Vincent Bernat <ber...@debian.org> :
> I am opening this bug report just to run the idea with you. Would it > be possible to switch to the rancid-git fork [0] which adds git > support. It also covers CVS and SVN support as the regular rancid. > > I don't know why git support has not been integrated upstream. > > [0]: http://dotwaffle.github.io/rancid-git/ Attached is a patch to add git support to the current Debian package. I have just extracted what was related to git (and HTML emails) from dotwaffle repository. Feel free to use it (correct the version number in debian/changelog in this case).
>From 8bf03d1af29fdda4e3ee02ca6d9401483a6a6c92 Mon Sep 17 00:00:00 2001 From: Vincent Bernat <ber...@debian.org> Date: Mon, 9 Dec 2013 18:06:47 +0100 Subject: [PATCH] 23_git_support: add git support from Matthew Walster --- debian/changelog | 6 + debian/control | 8 +- debian/patches/23_git_support.patch | 1113 +++++++++++++++++++++++++++++++++++ debian/patches/series | 1 + 4 files changed, 1124 insertions(+), 4 deletions(-) create mode 100644 debian/patches/23_git_support.patch diff --git a/debian/changelog b/debian/changelog index 5a69477..c607335 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +rancid (2.3.8-7+git~0) UNRELEASED; urgency=low + + * 23_git_support: add git support from Matthew Walster + + -- Vincent Bernat <ber...@debian.org> Mon, 09 Dec 2013 18:04:30 +0100 + rancid (2.3.8-7) unstable; urgency=low * 22_juniper_timestamps: Remove lines from juniper configuration that diff --git a/debian/control b/debian/control index 577114e..3e2ddec 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: net Priority: optional Maintainer: Roland Rosenfeld <rol...@debian.org> Uploaders: Marc Haber <mh+debian-packa...@zugschlus.de> -Build-Depends: debhelper (>= 9), expect, perl, openssh-client, cvs, +Build-Depends: debhelper (>= 9), expect, perl, openssh-client, cvs, inetutils-ping [!s390x] | iputils-ping [s390x] | ping, po-debconf, exim4 | mail-transport-agent, telnet, automake Standards-Version: 3.9.4 @@ -14,7 +14,7 @@ Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/rancid.git Package: rancid Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, expect, perl, - cvs | subversion, passwd, openssh-client | ssh, inetutils-ping | ping, + cvs | subversion | git, passwd, openssh-client | ssh, inetutils-ping | ping, debconf (>= 0.2.26) | debconf-2.0, adduser, libperl4-corelibs-perl | perl (<< 5.12.3-7) Suggests: diffstat @@ -26,8 +26,8 @@ Description: Really Awesome New Cisco confIg Differ for managing router configurations. . Rancid monitors a router's (or device's) configuration, including - software and hardware (cards, serial numbers, etc), using CVS or - Subversion. + software and hardware (cards, serial numbers, etc), using CVS, + Subversion or Git. Package: rancid-cgi Architecture: all diff --git a/debian/patches/23_git_support.patch b/debian/patches/23_git_support.patch new file mode 100644 index 0000000..40c52c8 --- /dev/null +++ b/debian/patches/23_git_support.patch @@ -0,0 +1,1113 @@ +Description: Git support, extracted from Matthew Walster tree + For an unknown reason, this patchset is not pushed upstream. The two + trees are now diverging a bit. + . + This also happens to contain the possibility to send colorized diffs + with HTML emails. This is not strictly related to Git but this comes + in the same repository and was not extracted separately. +Last-Update: 2013-12-09 +Origin: https://github.com/dotwaffle/rancid-git + +Index: rancid/bin/control_rancid.in +=================================================================== +--- rancid.orig/bin/control_rancid.in 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/bin/control_rancid.in 2013-12-09 18:01:17.020260554 +0100 +@@ -1,4 +1,4 @@ +-#! /bin/sh ++#! /bin/bash + ## + ## $Id: control_rancid.in 2270 2010-12-09 01:21:32Z heas $ + ## +@@ -113,7 +113,7 @@ + + # RCS system + RCSSYS=${RCSSYS:=cvs}; +-if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then ++if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" -a $RCSSYS != "git" -a $RCSSYS != "git-remote" ] ; then + echo "$RCSSYS is not a valid value for RCSSYS." + exit 1 + fi +@@ -152,33 +152,72 @@ + fi + cd $DIR + +-# create a .cvsignore +-if [ ! -f .cvsignore ] ; then +- rm -f .cvsignore +- cat >.cvsignore <<EOF +-.cvsignore +-routers.all +-routers.down +-routers.up +-EOF +- if [ $RCSSYS = svn ] ; then +- svn propset svn:ignore -F .cvsignore . +- svn update . +- svn commit -m 'set svn:ignores' . +- fi +-fi ++create_ignore () { ++ echo "*~" ++ echo "routers.added" ++ echo "routers.all" ++ echo "routers.all.new" ++ echo "routers.db" ++ echo "routers.deleted" ++ echo "routers.down" ++ echo "routers.down.new" ++ echo "routers.failed" ++ echo "routers.mail" ++ echo "routers.single" ++ echo "routers.up" ++ echo "routers.up.new" ++ echo "routers.up.missed" ++} ++ ++case $RCSSYS in ++ cvs ) ++ if [ ! -f .cvsignore ]; then ++ rm -f .cvsignore ++ create_ignore > .cvsignore ++ cvs add .cvsignore ++ cvs commit -m "Adding .cvsignore" ++ fi ++ ;; ++ svn ) ++ svn proplist . | grep -q 'svn:ignore' ++ if [ $? -ne 0 ]; then ++ create_ignore > .svnignore ++ svn propset svn:ignore -F .svnignore . ++ svn commit -m "Adding svn:ignore" ++ rm -f .svnignore ++ fi ++ ;; ++ git | git-remote ) ++ if [ ! -f .gitignore ]; then ++ rm -f .gitignore ++ create_ignore > .gitignore ++ ( ++ flock -x 200 ++ git add .gitignore ++ git commit -m "Adding .gitignore" ) 200>$BASEDIR/.lockfile ++ fi ++ ;; ++esac ++ ++case $RCSSYS in ++ cvs | svn ) ++ # do cvs/svn 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 ++ ;; ++ git | git-remote ) ++ # do nothing here (for now) ++ ;; ++esac + +-# 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 -fr $MYTMPDIR +- exit 1 +-fi +-rm -f $TMP + + if [ ! -f $DIR/router.db ] ; then + echo "$DIR/router.db does not exist." +@@ -281,21 +320,27 @@ + cd $DIR/configs + + # Add new routers to the CVS structure. +- for router in `comm -13 $DIR/routers.up $DIR/routers.up.new` ++ for router in `comm -13 $DIR/routers.up $DIR/routers.up.new | cut -d: -f1` + do +- OFS=$IFS +- IFS=: +- set $router +- IFS=$OFS +- router=$1 +- ++ message="new router $router in group $GROUP" + touch $router +- if [ $RCSSYS = cvs ] ; then +- cvs add -ko $router +- else +- 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 | git-remote ) ++ ( ++ flock -x 200 ++ git add $router ++ git commit -m "$message" ++ ) 200>$BASEDIR/.lockfile ++ ;; ++ esac + echo "Added $router" + done + echo +@@ -320,29 +365,56 @@ + 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 +- else +- svn status $router | grep '^?' > /dev/null 2>&1 +- 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-remote ) ++ 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 .cvsignore -prune -o -name .svn -prune -o -name .git -prune -o -name .gitignore -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 +- $RCSSYS delete $router +- $RCSSYS commit -m 'deleted router' $router ++ case $RCSSYS in ++ cvs | svn ) ++ $RCSSYS delete $router ++ $RCSSYS commit -m "deleted router $router" $router ++ ;; ++ git | git-remote ) ++ ( ++ flock -x 200 ++ git rm $router ++ git commit -m "deleted router $router" ++ ) 200>$BASEDIR/.lockfile ++ ;; ++ esac + echo "Deleted $router" + fi + done +@@ -352,7 +424,19 @@ + if [ ! -s routers.up ] + then + # commit router.db +- $RCSSYS commit -m updates router.db ++ message="updates of group $GROUP" ++ case $RCSSYS in ++ cvs | svn ) ++ $RCSSYS commit -m "$message" router.db ++ ;; ++ git | git-remote ) ++ ( ++ flock -x 200 ++ git add router.db ++ git commit -m "$message" ++ ) 200>$BASEDIR/.lockfile ++ ;; ++ esac + exit; + fi + +@@ -447,42 +531,452 @@ + fi + done + +-# This has been different for different machines... +-# Diff the directory and then checkin. +-trap 'rm -fr $MYTMPDIR $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 +-else +- svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff +-fi +- + if [ $alt_mailrcpt -eq 1 ] ; then +- subject="router config diffs - courtesy of $mailrcpt" ++ subject="router config diffs - courtesy of $mailrcpt $ALT_COMMIT" + else +- subject="router config diffs" ++ subject="router config diffs $ALT_COMMIT" + fi + if [ "X$device" != "X" ] ; then +- $RCSSYS commit -m "updates - courtesy of $mailrcpt" ++ message="updates of group $GROUP - courtesy of $mailrcpt $ALT_COMMIT" + subject="$GROUP/$device $subject" + else +- $RCSSYS commit -m updates ++ message="updates of group $GROUP $ALT_COMMIT" + subject="$GROUP $subject" + fi + ++function ansi2html { ++# Convert ANSI (terminal) colours and attributes to HTML ++ ++# Licence: LGPLv2 ++# Author: ++# http://www.pixelbeat.org/docs/terminal_colours/ ++# Examples: ++# ls -l --color=always | ansi2html.sh > ls.html ++# git show --color | ansi2html.sh > last_change.html ++# Generally one can use the `script` util to capture full terminal output. ++# Changes: ++# V0.1, 24 Apr 2008, Initial release ++# V0.2, 01 Jan 2009, Phil Harnish <philharn...@gmail.com> ++# Support `git diff --color` output by ++# matching ANSI codes that specify only ++# bold or background colour. ++# p...@draigbrady.com ++# Support `ls --color` output by stripping ++# redundant leading 0s from ANSI codes. ++# Support `grep --color=always` by stripping ++# unhandled ANSI codes (specifically ^[[K). ++# V0.3, 20 Mar 2009, http://eexpress.blog.ubuntu.org.cn/ ++# Remove cat -v usage which mangled non ascii input. ++# Cleanup regular expressions used. ++# Support other attributes like reverse, ... ++# p...@draigbrady.com ++# Correctly nest <span> tags (even across lines). ++# Add a command line option to use a dark background. ++# Strip more terminal control codes. ++# V0.4, 17 Sep 2009, p...@draigbrady.com ++# Handle codes with combined attributes and color. ++# Handle isolated <bold> attributes with css. ++# Strip more terminal control codes. ++# V0.15, 16 Oct 2013 ++# http://github.com/pixelb/scripts/commits/master/scripts/ansi2html.sh ++ ++if [ "$1" = "--version" ]; then ++ printf '0.15\n' && exit ++fi ++ ++if [ "$1" = "--help" ]; then ++ printf '%s\n' \ ++'This utility converts ANSI codes in data passed to stdin ++It has 2 optional parameters: ++ --bg=dark --palette=linux|solarized|tango|xterm ++E.g.: ls -l --color=always | ansi2html.sh --bg=dark > ls.html' >&2 ++ exit ++fi ++ ++[ "$1" = "--bg=dark" ] && { dark_bg=yes; shift; } ++ ++if [ "$1" = "--palette=solarized" ]; then ++ # See http://ethanschoonover.com/solarized ++ P0=073642; P1=D30102; P2=859900; P3=B58900; ++ P4=268BD2; P5=D33682; P6=2AA198; P7=EEE8D5; ++ P8=002B36; P9=CB4B16; P10=586E75; P11=657B83; ++ P12=839496; P13=6C71C4; P14=93A1A1; P15=FDF6E3; ++ shift; ++elif [ "$1" = "--palette=solarized-xterm" ]; then ++ # Above mapped onto the xterm 256 color palette ++ P0=262626; P1=AF0000; P2=5F8700; P3=AF8700; ++ P4=0087FF; P5=AF005F; P6=00AFAF; P7=E4E4E4; ++ P8=1C1C1C; P9=D75F00; P10=585858; P11=626262; ++ P12=808080; P13=5F5FAF; P14=8A8A8A; P15=FFFFD7; ++ shift; ++elif [ "$1" = "--palette=tango" ]; then ++ # Gnome default ++ P0=000000; P1=CC0000; P2=4E9A06; P3=C4A000; ++ P4=3465A4; P5=75507B; P6=06989A; P7=D3D7CF; ++ P8=555753; P9=EF2929; P10=8AE234; P11=FCE94F; ++ P12=729FCF; P13=AD7FA8; P14=34E2E2; P15=EEEEEC; ++ shift; ++elif [ "$1" = "--palette=xterm" ]; then ++ P0=000000; P1=CD0000; P2=00CD00; P3=CDCD00; ++ P4=0000EE; P5=CD00CD; P6=00CDCD; P7=E5E5E5; ++ P8=7F7F7F; P9=FF0000; P10=00FF00; P11=FFFF00; ++ P12=5C5CFF; P13=FF00FF; P14=00FFFF; P15=FFFFFF; ++ shift; ++else # linux console ++ P0=000000; P1=AA0000; P2=00AA00; P3=AA5500; ++ P4=0000AA; P5=AA00AA; P6=00AAAA; P7=AAAAAA; ++ P8=555555; P9=FF5555; P10=55FF55; P11=FFFF55; ++ P12=5555FF; P13=FF55FF; P14=55FFFF; P15=FFFFFF; ++ [ "$1" = "--palette=linux" ] && shift ++fi ++ ++[ "$1" = "--bg=dark" ] && { dark_bg=yes; shift; } ++ ++# Mac OSX's GNU sed is installed as gsed ++# use e.g. homebrew 'gnu-sed' to get it ++if ! sed --version >/dev/null 2>&1; then ++ if gsed --version >/dev/null 2>&1; then ++ alias sed=gsed ++ else ++ echo "Error, can't find an acceptable GNU sed." >&2 ++ exit 1 ++ fi ++fi ++ ++printf '%s' "<html> ++<head> ++<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> ++<style type=\"text/css\"> ++.ef0,.f0 { color: #$P0; } .eb0,.b0 { background-color: #$P0; } ++.ef1,.f1 { color: #$P1; } .eb1,.b1 { background-color: #$P1; } ++.ef2,.f2 { color: #$P2; } .eb2,.b2 { background-color: #$P2; } ++.ef3,.f3 { color: #$P3; } .eb3,.b3 { background-color: #$P3; } ++.ef4,.f4 { color: #$P4; } .eb4,.b4 { background-color: #$P4; } ++.ef5,.f5 { color: #$P5; } .eb5,.b5 { background-color: #$P5; } ++.ef6,.f6 { color: #$P6; } .eb6,.b6 { background-color: #$P6; } ++.ef7,.f7 { color: #$P7; } .eb7,.b7 { background-color: #$P7; } ++.ef8, .f0 > .bold,.bold > .f0 { color: #$P8; font-weight: normal; } ++.ef9, .f1 > .bold,.bold > .f1 { color: #$P9; font-weight: normal; } ++.ef10,.f2 > .bold,.bold > .f2 { color: #$P10; font-weight: normal; } ++.ef11,.f3 > .bold,.bold > .f3 { color: #$P11; font-weight: normal; } ++.ef12,.f4 > .bold,.bold > .f4 { color: #$P12; font-weight: normal; } ++.ef13,.f5 > .bold,.bold > .f5 { color: #$P13; font-weight: normal; } ++.ef14,.f6 > .bold,.bold > .f6 { color: #$P14; font-weight: normal; } ++.ef15,.f7 > .bold,.bold > .f7 { color: #$P15; font-weight: normal; } ++.eb8 { background-color: #$P8; } ++.eb9 { background-color: #$P9; } ++.eb10 { background-color: #$P10; } ++.eb11 { background-color: #$P11; } ++.eb12 { background-color: #$P12; } ++.eb13 { background-color: #$P13; } ++.eb14 { background-color: #$P14; } ++.eb15 { background-color: #$P15; } ++" ++ ++# The default xterm 256 colour palette ++for red in $(seq 0 5); do ++ for green in $(seq 0 5); do ++ for blue in $(seq 0 5); do ++ c=$((16 + ($red * 36) + ($green * 6) + $blue)) ++ r=$((($red * 40 + 55) * ($red > 0))) ++ g=$((($green * 40 + 55) * ($green > 0))) ++ b=$((($blue * 40 + 55) * ($blue > 0))) ++ printf ".ef%d { color: #%2.2x%2.2x%2.2x; } " $c $r $g $b ++ printf ".eb%d { background-color: #%2.2x%2.2x%2.2x; }\n" $c $r $g $b ++ done ++ done ++done ++for gray in $(seq 0 23); do ++ c=$(($gray+232)) ++ l=$(($gray*10 + 8)) ++ printf ".ef%d { color: #%2.2x%2.2x%2.2x; } " $c $l $l $l ++ printf ".eb%d { background-color: #%2.2x%2.2x%2.2x; }\n" $c $l $l $l ++done ++ ++printf '%s' ' ++.f9 { color: '`[ "$dark_bg" ] && printf "#$P7;" || printf "#$P0;"`' } ++.b9 { background-color: #'`[ "$dark_bg" ] && printf $P0 || printf $P15`'; } ++.f9 > .bold,.bold > .f9, body.f9 > pre > .bold { ++ /* Bold is heavy black on white, or bright white ++ depending on the default background */ ++ color: '`[ "$dark_bg" ] && printf "#$P15;" || printf "#$P0;"`' ++ font-weight: '`[ "$dark_bg" ] && printf 'normal;' || printf 'bold;'`' ++} ++.reverse { ++ /* CSS doesnt support swapping fg and bg colours unfortunately, ++ so just hardcode something that will look OK on all backgrounds. */ ++ '"color: #$P0; background-color: #$P7;"' ++} ++.underline { text-decoration: underline; } ++.line-through { text-decoration: line-through; } ++.blink { text-decoration: blink; } ++ ++</style> ++</head> ++ ++<body class="f9 b9"> ++<pre> ++' ++ ++p='\x1b\[' #shortcut to match escape codes ++P="\(^[^°]*\)¡$p" #expression to match prepended codes below ++ ++# Handle various xterm control sequences. ++# See /usr/share/doc/xterm-*/ctlseqs.txt ++sed " ++s#\x1b[^\x1b]*\x1b\\\##g # strip anything between \e and ST ++s#\x1b][0-9]*;[^\a]*\a##g # strip any OSC (xterm title etc.) ++ ++#handle carriage returns ++s#^.*\r\{1,\}\([^$]\)#\1# ++s#\r\$## # strip trailing \r ++ ++# strip other non SGR escape sequences ++s#[\x07]##g ++s#\x1b[]>=\][0-9;]*##g ++s#\x1bP+.\{5\}##g ++s#${p}[0-9;?]*[^0-9;?m]##g ++ ++#remove backspace chars and what they're backspacing over ++:rm_bs ++s#[^\x08]\x08##g; t rm_bs ++" | ++ ++# Normalize the input before transformation ++sed " ++# escape HTML ++s#&#\&#g; s#>#\>#g; s#<#\<#g; s#\"#\"#g ++ ++# normalize SGR codes a little ++ ++# split 256 colors out and mark so that they're not ++# recognised by the following 'split combined' line ++:e ++s#${p}\([0-9;]\{1,\}\);\([34]8;5;[0-9]\{1,3\}\)m#${p}\1m${p}¬\2m#g; t e ++s#${p}\([34]8;5;[0-9]\{1,3\}\)m#${p}¬\1m#g; ++ ++:c ++s#${p}\([0-9]\{1,\}\);\([0-9;]\{1,\}\)m#${p}\1m${p}\2m#g; t c # split combined ++s#${p}0\([0-7]\)#${p}\1#g #strip leading 0 ++s#${p}1m\(\(${p}[4579]m\)*\)#\1${p}1m#g #bold last (with clr) ++s#${p}m#${p}0m#g #add leading 0 to norm ++ ++# undo any 256 color marking ++s#${p}¬\([34]8;5;[0-9]\{1,3\}\)m#${p}\1m#g; ++ ++# map 16 color codes to color + bold ++s#${p}9\([0-7]\)m#${p}3\1m${p}1m#g; ++s#${p}10\([0-7]\)m#${p}4\1m${p}1m#g; ++ ++# change 'reset' code to a single char, and prepend a single char to ++# other codes so that we can easily do negative matching, as sed ++# does not support look behind expressions etc. ++s#°#\°#g; s#${p}0m#°#g ++s#¡#\¡#g; s#${p}[0-9;]*m#¡&#g ++" | ++ ++# Convert SGR sequences to HTML ++sed " ++:ansi_to_span # replace ANSI codes with CSS classes ++t ansi_to_span # hack so t commands below only apply to preceeding s cmd ++ ++/^[^¡]*°/ { b span_end } # replace 'reset code' if no preceeding code ++ ++# common combinations to minimise html (optional) ++s#${P}3\([0-7]\)m¡${p}4\([0-7]\)m#\1<span class=\"f\2 b\3\">#;t span_count ++s#${P}4\([0-7]\)m¡${p}3\([0-7]\)m#\1<span class=\"f\3 b\2\">#;t span_count ++ ++s#${P}1m#\1<span class=\"bold\">#; t span_count ++s#${P}4m#\1<span class=\"underline\">#; t span_count ++s#${P}5m#\1<span class=\"blink\">#; t span_count ++s#${P}7m#\1<span class=\"reverse\">#; t span_count ++s#${P}9m#\1<span class=\"line-through\">#; t span_count ++s#${P}3\([0-9]\)m#\1<span class=\"f\2\">#; t span_count ++s#${P}4\([0-9]\)m#\1<span class=\"b\2\">#; t span_count ++ ++s#${P}38;5;\([0-9]\{1,3\}\)m#\1<span class=\"ef\2\">#; t span_count ++s#${P}48;5;\([0-9]\{1,3\}\)m#\1<span class=\"eb\2\">#; t span_count ++ ++s#${P}[0-9;]*m#\1#g; t ansi_to_span # strip unhandled codes ++ ++b # next line of input ++ ++# add a corresponding span end flag ++:span_count ++x; s/^/s/; x ++b ansi_to_span ++ ++# replace 'reset code' with correct number of </span> tags ++:span_end ++x ++/^s/ { ++ s/^.// ++ x ++ s#°#</span>°# ++ b span_end ++} ++x ++s#°## ++b ansi_to_span ++" | ++ ++# Convert alternative character set ++# Note we convert here, as if we do at start we have to worry about avoiding ++# conversion of SGR codes etc., whereas doing here we only have to ++# avoid conversions of stuff between &...; or <...> ++# ++# Note we could use sed to do this based around: ++# sed 'y/abcdefghijklmnopqrstuvwxyz{}`~/▒␉␌␍␊°±␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·/' ++# However that would be very awkward as we need to only conv some input. ++# The basic scheme that we do in the python script below is: ++# 1. enable transliterate once ¡ char seen ++# 2. disable once µ char seen (may be on diff line to ¡) ++# 3. never transliterate between &; or <> chars ++sed " ++# change 'smacs' and 'rmacs' to a single char so that we can easily do ++# negative matching, as sed does not support look behind expressions etc. ++# Note we don't use ° like above as that's part of the alternate charset. ++s#\x1b(0#¡#g; ++s#µ#\µ#g; s#\x1b(B#µ#g ++" | ++( ++python -c " ++# vim:fileencoding=utf8 ++ ++import sys ++import locale ++encoding=locale.getpreferredencoding() ++ ++old='abcdefghijklmnopqrstuvwxyz{}\`~' ++new='▒␉␌␍␊°±␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π£◆·' ++new=unicode(new, 'utf-8') ++table=range(128) ++for o,n in zip(old, new): table[ord(o)]=n ++ ++(STANDARD, ALTERNATIVE, HTML_TAG, HTML_ENTITY) = (0, 1, 2, 3) ++ ++state = STANDARD ++last_mode = STANDARD ++for c in unicode(sys.stdin.read(), encoding): ++ if state == HTML_TAG: ++ if c == '>': ++ state = last_mode ++ elif state == HTML_ENTITY: ++ if c == ';': ++ state = last_mode ++ else: ++ if c == '<': ++ state = HTML_TAG ++ elif c == '&': ++ state = HTML_ENTITY ++ elif c == u'¡': ++ if state == STANDARD: ++ state = ALTERNATIVE ++ last_mode = ALTERNATIVE ++ continue ++ elif c == u'µ': ++ if state == ALTERNATIVE: ++ state = STANDARD ++ last_mode = STANDARD ++ continue ++ elif state == ALTERNATIVE: ++ c = c.translate(table) ++ sys.stdout.write(c.encode(encoding)) ++" 2>/dev/null || ++sed 's/[¡µ]//g' # just strip aternative flag chars ++) ++ ++printf '</pre> ++</body> ++</html>\n' ++} ++ ++# Disable HTML Mails by default ++if [ ! $HTMLMAILS ]; then ++ HTMLMAILS=NO; export HTMLMAILS ++fi ++ ++# This has been different for different machines... ++# Diff the directory and then checkin. ++trap 'rm -fr $MYTMPDIR $DIR/routers.single;' 1 2 15 ++cd $DIR ++case $RCSSYS in ++ cvs ) ++ if [ $HTMLMAILS == YES ]; then ++ cvs -f @DIFF_CMD@ -ko > /dev/null ++ if [ $? -qe 0 ] ; then ++ # only process HTML mail fi there really is a difference ++ cvs -f @DIFF_CMD@ -ko | sed -e '/^RCS file: /d' -e '/^--- /d' \ ++ -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' | ansi2html >$TMP.diff ++ fi ++ else ++ cvs -f @DIFF_CMD@ -ko | sed -e '/^RCS file: /d' -e '/^--- /d' \ ++ -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff ++ fi ++ cvs commit -m "$message" ++ ;; ++ svn ) ++ if [ $HTMLMAILS == YES ]; then ++ svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' | ansi2html >$TMP.diff ++ else ++ svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff ++ fi ++ svn commit -m "$message" ++ ;; ++ git | git-remote ) ++ # with git we do things differently - first commit, then grab the diff ++ ( ++ flock -x 200 ++ git add router.db ++ for router in `cat $devlistfile | cut -d: -f1` ++ do ++ git add configs/$router ++ done ++ git commit -m "$message" ++ if [ $? -eq 0 ]; then ++ # only generate a diff if the commit was successful ++ if [ $HTMLMAILS == YES ]; then ++ git diff --patch-with-stat --quiet HEAD^ HEAD -- . ++ if [ $? -eq 1 ] ; then ++ # only process HTML mail if there really is a difference ++ git diff --color --patch-with-stat HEAD^ HEAD -- . | ansi2html >$TMP.diff ++ fi ++ else ++ git diff --patch-with-stat HEAD^ HEAD -- . >$TMP.diff ++ fi ++ if [ $RCSSYS = "git-remote" ] ; then ++ # only push to remotes if commit was successful ++ for repo in $(git remote) ; do ++ git push ${repo} ++ done ++ fi ++ fi ++ ) 200>$BASEDIR/.lockfile ++ ;; ++esac ++ + # Mail out the diffs (if there are any). + if [ -s $TMP.diff ] ; then +- ( +- echo "To: $mailrcpt" +- echo "Subject: $subject" +- echo "$MAILHEADERS" | awk '{L = "";LN = $0;while (LN ~ /\\n/) { I = index(LN,"\\n");L = L substr(LN,0,I-1) "\n";LN = substr(LN,I+2,length(LN)-I-1);}print L LN;}' +- echo "" +- if which diffstat >/dev/null; then +- diffstat $TMP.diff +- fi +- cat $TMP.diff +- ) | sendmail -t ++ if [ $HTMLMAILS == YES ]; then ++ ( ++ echo "To: $mailrcpt" ++ echo "Subject: $subject" ++ echo "Mime-Version: 1.0" ++ echo "Content-type: text/html" ++ echo "Content-transfer-encoding: 8bit" ++ echo "$MAILHEADERS" | awk '{L = "";LN = $0;while (LN ~ /\\n/) { I = index(LN,"\\n");L = L substr(LN,0,I-1) "\n";LN = substr(LN,I+2,length(LN)-I-1);}print L LN;}' ++ echo "" ++ cat $TMP.diff ++ ) | sendmail -oi -t ++ else ++ ( ++ echo "To: $mailrcpt" ++ echo "Subject: $subject" ++ echo "$MAILHEADERS" | awk '{L = "";LN = $0;while (LN ~ /\\n/) { I = index(LN,"\\n");L = L substr(LN,0,I-1) "\n";LN = substr(LN,I+2,length(LN)-I-1);}print L LN;}' ++ echo "" ++ cat $TMP.diff ++ ) | sendmail -t ++ fi + fi + + # If any machines have not been reached within the last $OLDTIME +Index: rancid/bin/rancid-cvs.in +=================================================================== +--- rancid.orig/bin/rancid-cvs.in 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/bin/rancid-cvs.in 2013-12-09 18:01:17.020260554 +0100 +@@ -1,4 +1,4 @@ +-#! /bin/sh ++#! /bin/bash + ## + ## $Id: rancid-cvs.in 2340 2011-11-29 22:30:30Z heas $ + ## +@@ -87,27 +87,45 @@ + + # RCS system + RCSSYS=${RCSSYS:=cvs}; +-if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then +- echo "$RCSSYS is not a valid value for RCSSYS." +- exit 1 +-fi ++case $RCSSYS in ++ cvs | svn ) ++ # we're good ++ ;; ++ git | git-remote ) ++ # force $CVSROOT ++ CVSROOT=$BASEDIR/.git ++ ;; ++ * ) ++ echo "$RCSSYS is not a valid value for RCSSYS." ++ exit 1 ++ ;; ++esac + + # Top level CVS stuff +-if [ $RCSSYS = cvs ]; then +- if [ ! -d $CVSROOT ]; then +- cvs -d $CVSROOT init +- fi +-else +- if echo "$CVSROOT" | grep -q "://"; then +- # do nothing because CVSROOT is some sort of a URL +- # also assume the repository has already been provisioned +- : +- else +- if ! svn ls "file://$CVSROOT" >/dev/null 2>&1; then ++if [ ! -d $CVSROOT ]; then ++ case $RCSSYS in ++ cvs ) ++ cvs -d $CVSROOT init ++ ;; ++ svn ) + svnadmin create $CVSROOT @SVN_FSTYPE@ +- fi +- CVSROOT="file://$CVSROOT" +- fi ++ ;; ++ git | git-remote ) ++ # 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 "*.new" >> .gitignore ++ git add .gitignore ++ git commit -m "Initializing repository." ++ ) 200>$BASEDIR/.lockfile ++ ;; ++ esac + fi + + # Log dir +@@ -132,23 +150,48 @@ + 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 +- else +- svn import -m "$GROUP" . $CVSROOT/$GROUP +- cd $BASEDIR +- svn checkout $CVSROOT/$GROUP $GROUP +- cd $DIR +- svn update +- 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 | git-remote ) ++ 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 +- $RCSSYS add configs +- $RCSSYS commit -m 'new' configs ++ case $RCSSYS in ++ cvs | svn ) ++ $RCSSYS add configs ++ $RCSSYS commit -m 'new' configs ++ ;; ++ git | git-remote ) ++ # nothing to be done here ++ ;; ++ esac + fi + + # main files +@@ -163,7 +206,18 @@ + fi + if [ ! -f router.db ]; then + touch router.db +- $RCSSYS add router.db +- $RCSSYS commit -m 'new' router.db ++ case $RCSSYS in ++ cvs | svn ) ++ $RCSSYS add router.db ++ $RCSSYS commit -m 'new' router.db ++ ;; ++ git | git-remote ) ++ ( ++ flock -x 200 ++ git add router.db ++ git commit -m "Initializing $GROUP" ++ ) 200>$BASEDIR/.lockfile ++ ;; ++ esac + fi + done +Index: rancid/configure.in +=================================================================== +--- rancid.orig/configure.in 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/configure.in 2013-12-09 18:01:17.020260554 +0100 +@@ -159,6 +159,25 @@ + ], [AC_MSG_RESULT(no) + RCSSYS="cvs" + ]) ++ ++# Configure for git distributed version control system instead of CVS. ++AC_MSG_CHECKING([whether git]) ++AC_ARG_WITH(git, ++ AS_HELP_STRING([--with-git], ++ [use git instead of cvs]), ++[ case "$withval" in ++ yes) ++ AC_MSG_RESULT(yes) ++ RCSSYS="git" ++ ;; ++ no) ++ AC_MSG_RESULT(no) ++ RCSSYS="cvs" ++ esac ++], [AC_MSG_RESULT(no) ++ RCSSYS="cvs" ++]) ++ + AC_SUBST(RCSSYS) + AC_SUBST(SVN_FSTYPE) + rd_cv_RCSSYS=$RCSSYS +@@ -321,9 +340,12 @@ + if test $RCSSYS = "cvs" ; then + AC_PATH_PROG(CVS,cvs,no) + ENV_PATH="$ENV_PATH:`dirname $ac_cv_path_CVS`" +-else ++elif test $RCSSYS = "svn" ; then + AC_PATH_PROG(SVN,svn,no) + ENV_PATH="$ENV_PATH:`dirname $ac_cv_path_SVN`" ++elif test $RCSSYS = "git" ; then ++ AC_PATH_PROG(GIT,git,no) ++ ENV_PATH="$ENV_PATH:`dirname $ac_cv_path_GIT`" + fi + AC_PATH_PROG(COMM,comm,no) + ENV_PATH="$ENV_PATH:`dirname $ac_cv_path_COMM`" +Index: rancid/etc/rancid.conf.sample.in +=================================================================== +--- rancid.orig/etc/rancid.conf.sample.in 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/etc/rancid.conf.sample.in 2013-12-09 18:01:17.020260554 +0100 +@@ -36,8 +36,9 @@ + # Location of log files produced by rancid-run(1). + LOGDIR=$BASEDIR/logs; export LOGDIR + # +-# Select which RCS system to use, "cvs" (default) or "svn". Do not change +-# this after CVSROOT has been created with rancid-cvs. Changing between these ++# Select which RCS system to use, "cvs" (default), "svn", "git" or ++# "git-remote". Do not change this after CVSROOT has been created with ++# rancid-cvs, with the exception of git <-> git-remote. Changing between these + # requires manual conversions. + RCSSYS=@RCSSYS@; export RCSSYS + # +@@ -88,6 +89,9 @@ + # appended to recipients specified in rancid-run's -m option. + #MAILDOMAIN="@example.com"; export MAILDOMAIN + # ++# If you want to have colorised html mails with the diffs set this to YES ++#HTMLMAILS=YES; export HTMLMAILS ++# + # By default, rancid mail is marked with precedence "bulk". This may be + # changed by setting the MAILHEADERS variable; for example no header by setting + # it to "" or adding X- style headers. Individual headers must be separated +Index: rancid/man/rancid.conf.5.in +=================================================================== +--- rancid.orig/man/rancid.conf.5.in 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/man/rancid.conf.5.in 2013-12-09 18:01:17.020260554 +0100 +@@ -163,9 +163,9 @@ + If set, + .IR rancid (1) + will use temporary files to save the output from the router and then read +-these to build the file which will be saved in CVS (or Subversion). +-Otherwise, an IPC pipe will be used. We have found that the buffering +-mechanisms used in perl and expect are heinous. ++these to build the file which will be saved in the revision control system ++(CVS, Subversion or Git). Otherwise, an IPC pipe will be used. We have found ++that the bufferingmechanisms used in perl and expect are heinous. + Using temporary files may result in a noticeable improvement in speed. + By default, this is not set. + .\" +@@ -213,9 +213,11 @@ + Valid values are + .B cvs + for CVS +-or + .B svn +-for Subversion. ++for Subversion ++or ++.B git ++for Git. + .sp + Default: cvs + .\" +Index: rancid/man/rancid-cvs.1 +=================================================================== +--- rancid.orig/man/rancid-cvs.1 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/man/rancid-cvs.1 2013-12-09 18:01:17.020260554 +0100 +@@ -2,7 +2,8 @@ + .hys 50 + .TH "rancid-cvs" "1" "5 October 2006" + .SH NAME +-rancid-cvs \- initialize CVS or Subversion and rancid group files and directories ++rancid-cvs \- initialize CVS, Subversion or Git and rancid group files and ++directories + .SH SYNOPSIS + .B rancid-cvs + [\fB\-V\fR] [group [group ...]] +@@ -10,8 +11,8 @@ + .B rancid-cvs + creates the directories and + .BR router.db (5) +-for each rancid group and handles the revision control system (CVS or +-Subversion) set-up. ++for each rancid group and handles the revision control system (CVS, ++Subversion or Git) set-up. + It must be run after installation and whenever a rancid group is added. + .\" + .PP +@@ -19,7 +20,7 @@ + reads + .BR rancid.conf (5) + to configure itself, then proceeds with the initialization. +-First of the CVS or Subversion repository, if necessary, and then for each ++First of the CVS, Subversion or Git repository, if necessary, and then for each + of the rancid groups listed on the command-line or those in the variable + .I LIST_OF_GROUPS + from +@@ -55,4 +56,5 @@ + .BR cvs (1), + .BR rancid.conf (5), + .BR router.db (5), +-.BR svn (1) ++.BR svn (1), ++.BR git (1) +Index: rancid/man/rancid_intro.1 +=================================================================== +--- rancid.orig/man/rancid_intro.1 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/man/rancid_intro.1 2013-12-09 18:01:17.020260554 +0100 +@@ -58,7 +58,7 @@ + .IR "router.db". + .PP + Lastly, all the updated files are checked into the revision control system +-(CVS or Subversion). ++(CVS, Subversion or Git). + .PP + Additional utilities, including a looking glass, come with rancid. See + rancid's share directory ( +Index: rancid/man/rancid-run.1 +=================================================================== +--- rancid.orig/man/rancid-run.1 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/man/rancid-run.1 2013-12-09 18:01:17.020260554 +0100 +@@ -118,7 +118,7 @@ + .SH ERRORS + If rancid fails to run or collect a device's configuration, the particular + group's log file (mentioned above) should be consulted. Any errors produced +-by the revision control system (CVS or Subversion) or any of the rancid ++by the revision control system (CVS, Subversion or Git) or any of the rancid + scripts should be included there, whether they be a botched cvs tree, login + authentication failure, rancid configuration error, etc. + If the log file produces no clues, the next debugging step should be run the +Index: rancid/README +=================================================================== +--- rancid.orig/README 2013-12-09 18:01:17.024260554 +0100 ++++ rancid/README 2013-12-09 18:01:17.020260554 +0100 +@@ -37,10 +37,10 @@ + Force10, Juniper E-series, Procket, Redback, Zebra/MRT. + control_rancid.in + Builds router list, calls rancid on each router and +- handles cvs routines. ++ handles version control routines. + hpuifilter.c HP procurve login filter - see hlogin(1). + par.in Parallel processing of commands - any commands. +- rancid-cvs.in Creates all of the CVS and config directories. ++ rancid-cvs.in Creates all of the version control and config directories. + rancid-run.in Script designed to be run from cron. + rancid-fe.in Chooses between rancid/[abefhjrx]rancid/cat5rancid. + rancid.in Runs commands on cisco routers and processes the output. +@@ -111,9 +111,12 @@ + expect http://expect.nist.gov/ We highly suggest that you stick to + expect 5.24.1 (or so). This seems to work best. Note that + you need to have the accompanying tcl &/ tk. +-svn Code revision system, an alternative to cvs. Available from ++svn Code revision system, an alternative to cvs or git. Available from + http://subversion.tigris.org/tarballs/. Use the configure + option --with-svn to configure for Subversion. ++git Distributed version control system, an alternative to cvs or svn ++ Available from http://git-scm.com/downloads. Use the configure ++ option --with-git to configure for Git. + tcl Required by expect. + + Bill Fenner (now maintained by others) has a cgi script for interacting +@@ -194,10 +197,10 @@ + + 7) Run rancid-cvs. + This creates all of the necessary directories and config files for +- each of the groups in LIST_OF_GROUPS and imports them into CVS (or +- Subversion). This will also be run each time a new group is added. Do +- not create the directories or CVS repository manually, allow rancid-cvs +- do it. Also see 'man -M <basedir>/man rancid-cvs'. ++ each of the groups in LIST_OF_GROUPS and imports them into version control ++ (CVS, Subversion or Git). This will also be run each time a new group is ++ added. Do not create the directories or version control repository manually, ++ allow rancid-cvs to do it. Also see 'man -M <basedir>/man rancid-cvs'. + + 8) For each "group", modify the router.db file in the group directory. + The file is of the form "router:mfg:state" where "router" is diff --git a/debian/patches/series b/debian/patches/series index 8cd5f27..8d53128 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -18,3 +18,4 @@ 20_rancid-2.3.8.p4.patch 21_arista_free_flash.patch 22_juniper_timestamps.patch +23_git_support.patch -- 1.8.5.1
-- Vincent Bernat | v...@deezer.com ▅▃▇▅█ Deezer | 12 rue d'Athènes | 75009 Paris | France