Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@barryo
Created November 18, 2013 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryo/7529951 to your computer and use it in GitHub Desktop.
Save barryo/7529951 to your computer and use it in GitHub Desktop.
Script to start and / or reconfigure Bird daemons on INEX's quarantine VLANs
#! /bin/bash
KEY="hahahahayeahright"
URL="https://www.example.com/apiv1/router/collector-conf/key/${KEY}"
LAN1ID="1"
LAN2ID="2"
ETCPATH="/usr/local/etc/bird"
RUNPATH="/var/run/bird"
BIN="/usr/sbin/bird"
mkdir -p $RUNPATH
if [[ -n $1 && $1 = '--quiet' ]]; then
export QUIET=1
else
export QUIET=0
echo -en "\nINEX Quarantine BGPd Lisenters\n==============================\n\n"
echo -e "Verbose mode enabled. Issue --quiet for non-verbose mode (--debug also available)\n"
fi
if [[ -n $1 && $1 = '--debug' ]]; then
export QUIET=1
export DEBUG=1
else
export DEBUG=0
fi
function log {
if [[ $QUIET -eq 0 && $DEBUG -eq 0 ]]; then
echo -en $1
fi
}
for vlanid in $LAN1ID $LAN2ID; do
for proto in 4 6; do
if [[ $proto = "6" ]]; then
PROTOCOL="6"
else
PROTOCOL=""
fi
log "VLAN ID ${vlanid}\tIPv${proto}:\tConfig: "
log "VLAN ID ${vlanid}\tIPv${proto}:\tConfig: "
cmd="wget -q -O ${ETCPATH}/bird-vlanid${vlanid}-ipv${proto}.conf \
\"${URL}/target/bird/vlanid/${vlanid}/proto/${proto}/config/rc-inex-vlanid${vlanid}-ipv${proto}\""
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
eval $cmd
if [[ $? -eq 0 ]]; then
log "DONE \tDaemon: "
else
log "ERROR\n"
continue
fi
# are we running or do we need to be started?
cmd="${BIN}c${PROTOCOL} -s ${RUNPATH}/bird-vlanid${vlanid}-ipv${proto}.ctl configure"
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
eval $cmd &>/dev/null
if [[ $? -eq 0 ]]; then
log "RECONFIGURED"
else
cmd="${BIN}${PROTOCOL} -c ${ETCPATH}/bird-vlanid${vlanid}-ipv${proto}.conf -s ${RUNPATH}/bird-vlanid${vlanid}-ipv${proto}.ctl"
if [[ $DEBUG -eq 1 ]]; then echo $cmd; fi
eval $cmd &>/dev/null
if [[ $? -eq 0 ]]; then
log "STARTED"
else
log "ERROR\n"
continue
fi
fi
log "\n"
done
done
log "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment