Commit 9de005b7 authored by Maria Matejka's avatar Maria Matejka

In-virtual rc.local

parent 9150ebac
img/*
iso/*
run/*
nfs/*
nfs/bird*
nfs/net/vl-*
nfs/tmp
bin/socat
#!/bin/bash
UNAME=$(uname)
UNAME=${UNAME,,}
declare -a INTERFACES_OLD
declare -a INTERFACES
case $UNAME in
linux)
INTERFACES_OLD+=( $( ( ip link ; echo "0: eof" ) | sed -rn '/^[0-9]/{s/^[0-9]+: //;s/:.*//;x;s/\n /,/;p;}; /ether/{s/.*ether (..:..:..:..:..:..).*/ \1/;H;}') )
;;
*)
INTERFACES_OLD+=( $( ( ifconfig ; echo "eof" ) | sed -rn '/^[a-z]/{s/:.*//;x;s/\n /,/;p;}; /(ether|lladdr)/{s/.*(ether|lladdr) (..:..:..:..:..:..).*/ \2/;H;}') )
;;
esac
for I in ${INTERFACES_OLD[@]}; do
NAME=${I%%,*}
MAC=${I##*,}
MAC=${MAC,,}
if [ "$NAME" = "$MAC" ]; then continue; fi
echo "$NAME -> $MAC"
MACFILE=/mnt/nfs/net/vl-${MAC//:}
if [ ! -f $MACFILE ]; then
continue;
fi
IP4=$(sed -rn 's/^IP4 //p;' < $MACFILE)
IP4PEER=$(sed -rn 's/^IP4PEER //p;' <$MACFILE)
NN=$(sed -rn 's/^NAME //p;' < $MACFILE)
case $UNAME in
linux)
echo "Renaming $NAME to $NN"
ip link set $NAME name $NN
NAME=$NN
echo "Adding $IP4 to $NAME ($MAC)${IP4PEER:+,peer $IP4PEER}"
ip link set $NAME up
ip addr add $IP4 dev $NAME ${IP4PEER:+peer $IP4PEER}
;;
freebsd)
echo "Renaming $NAME to $NN"
ifconfig $NAME name $NN
NAME=$NN
echo "Adding $IP4 to $NAME ($MAC)${IP4PEER:+,peer $IP4PEER}"
ifconfig $NAME up
ifconfig $NAME inet $IP4 ${IP4PEER%%/*}
if [ ! -z "$IP4PEER" ]; then route add ${IP4PEER%%/*} -iface $NAME; fi
;;
openbsd)
echo "Can't rename $NAME to $NN"
ifconfig $NAME up
echo "Adding $IP4 to $NAME ($MAC)${IP4PEER:+,peer $IP4PEER}"
ifconfig $NAME up
ifconfig $NAME inet $IP4 ${IP4PEER%%/*}
if [ ! -z "$IP4PEER" ]; then route add ${IP4PEER%%/*} -iface $NAME; fi
;;
*)
echo "Unknown system $UNAME"
;;
esac
INTERFACES+=( "$NAME,$MAC" )
done
#!/bin/bash
H=$(hostname)
if [ "${H%%-install}" != "$H" ]; then
echo "Install machine. Aborting tests."
exit 0
fi
export PATH=$PATH:/usr/local/bin
. /mnt/nfs/net/rc.local.network
OSPF_INAME_SED="x;"
echo ${INTERFACES[@]}
for I in ${INTERFACES[@]}; do
if [ "${I:0:2}" != "dl" ]; then
continue
fi
COST=$((4#${I:2:4} + 1))
OSPF_INAME_SED="$OSPF_INAME_SED G; s/INAME/${I:0:6}/; s/ICOST/$COST/;"
done
OSPF_INAME_SED="$OSPF_INAME_SED x; s/.*//; x;"
IDBIN=$(($(hostname | tr '12md' '012#') + 50))
IDHEX=${H##md}
CTLIP=10.200.0.$IDBIN
CTLIP6=fd01::$IDHEX
case $UNAME in
linux) AUTOCONF=autoconf
MAKE=make
ip link add $H type dummy
ip link set $H up
ip addr add $CTLIP/32 dev $H
ip -6 addr add $CTLIP6/128 dev $H
;;
freebsd)
AUTOCONF=autoconf
MAKE=gmake
;;
openbsd)
AUTOCONF=autoconf-2.69
MAKE=gmake
;;
*)
echo "Unknown system $UNAME"
;;
esac
SED_PATTERN="s/CTLIP6/$CTLIP6/g; s/CTLIP/$CTLIP/g; s/IDBIN/$IDBIN/g; s/IDHEX/$IDHEX/g; /INAME/ { $OSPF_INAME_SED };"
CONFDIR="/mnt/nfs/bird-conf"
function runbird4() {
sed "$SED_PATTERN" "$1" > /tmp/bird4.conf
rsync -av /mnt/nfs/bird/ /tmp/bird4
cd /tmp/bird4
$AUTOCONF
./configure
$MAKE
./bird -c /tmp/bird4.conf -s ./bird.sock -P ./bird.pid
}
function runbird6() {
sed "$SED_PATTERN" "$1" > /tmp/bird6.conf
rsync -av /mnt/nfs/bird/ /tmp/bird6
cd /tmp/bird6
$AUTOCONF
./configure --enable-ipv6
$MAKE
./bird -c /tmp/bird6.conf -s ./bird.sock -P ./bird.pid
}
function runbird() {
sed "$SED_PATTERN" "$1" > /tmp/bird-int.conf
rsync -av /mnt/nfs/bird/ /tmp/bird
cd /tmp/bird
$AUTOCONF
./configure
sed -i 's/-g -O2/-g3 -O0/' obj/Rules
$MAKE
./bird -c /tmp/bird-int.conf -s ./bird.sock -P ./bird.pid
}
#runbird $CONFDIR/bird-int-4.conf
runbird4 $CONFDIR/bird-int-4-old.conf
#runbird $CONFDIR/bird-int-6.conf
runbird6 $CONFDIR/bird-int-6-old.conf
#runbird $CONFDIR/bird-int-template.conf
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment