freyanet/bin/mkbirdconfig.sh
2023-12-30 15:23:30 -05:00

85 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
. /var/lib/inet2/inet2.sh
escapebird() {
sed -e 's/\\/\\\\/g;s/"/\\"/g'
}
step "Creating Bird configuration"
touch /var/log/bird.log
chown bird:bird /var/log/bird.log
interfacelist=$(
echo " interface \"lo\" { stub; };"
getval interface | while read -r inter; do
val="$(getval "interface $inter" OSPF)"
if [ "$?" = "0" ]; then
echo " interface \"$(printf "%s" "$inter" | escapebird)\" {"
echo " type ptp;"
if [ -n "$val" ]; then
echo " $val;";
fi
echo " };"
fi
done
)
filter4=$(getval "Subnet" | grep -v ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')
filter6=$(getval "Subnet" | grep ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')
(cat <<EOF
log "/var/log/bird.log" all;
$(getval RouterID | while read -r line; do echo "router id $line;"; done)
protocol kernel {
ipv4 { export filter { if net ~ [$filter4] then accept; else reject; }; };
}
protocol kernel {
ipv6 { export filter { if net ~ [$filter6] then accept; else reject; }; };
}
protocol device {
}
protocol direct {
ipv4;
ipv6;
}
protocol static {
ipv4;
}
EOF
cat <<EOF
protocol ospf v3 ospf4 {
ipv4 {
import all;
export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter4] then accept; else reject; };
};
area 0 {
$(getval "Stubnet" | grep -v ':' | while read -r net; do echo " stubnet $net {};"; done)
$interfacelist
};
}
protocol ospf v3 ospf6 {
ipv6 {
import all;
export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$filter6] then accept; else reject; };
};
area 0 {
$(getval "Stubnet" | grep ':' | while read -r net; do echo " stubnet $net {};"; done)
$interfacelist
};
}
EOF
) > /etc/bird.conf
chown root:bird /etc/bird.conf
chmod 640 /etc/bird.conf