#!/bin/sh run() { printf '$ \x1b[32;1m%s\x1b[0m\n' "$*" "$@" } step() { printf '\x1b[34;1m>> %s\x1b[0m\n' "$*" } getval() { /usr/local/bin/config.awk /config/inet2.conf "$@" } haskey() { getval interface | while read -r inter; do if getval "interface $inter" "$1"; then echo "true" return fi done } # ensure the /run/inet2 directory is empty (docker doesn't mount tmpfs to /run) # /run/inet2 is used for storage during runtime - restarting the container should clear it rm -rf /run/inet2 2>/dev/null mkdir /run/inet2 # ensure the /var/lib/inet2 directory exists # /var/lib/inet2 is used for storage for the entire lifetime of the container - restarting the container shouldn't clear it if [ ! -d /var/lib/inet2 ]; then mkdir -p /var/lib/inet2 fi # these are disabled in the docker netns step "Enabling IPv6" run sysctl net.ipv6.conf.all.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.all.forwarding=1 ospf="$(haskey OSPF)" escapebird() { sed -e 's/\\/\\\\/g;s/"/\\"/g' } if [ -n "$ospf" ]; then step "Creating Bird configuration" touch /var/log/bird.log chown bird:bird /var/log/bird.log selfas=$(getval AS) ( cat < /etc/bird.conf chown root:bird /etc/bird.conf chmod 640 /etc/bird.conf step "Enabling BIRD" run rc-update add bird fi if [ ! -f /var/lib/inet2/setupDone ]; then if [ -f /config/setup.sh ]; then step "Running /config/setup.sh" /config/setup.sh fi touch /var/lib/inet2/setupDone fi if [ -f /config/start.sh ]; then step "Running /config/start.sh" /config/start.sh fi if [ "$#" = "0" ]; then step "Starting OpenRC" rm -rf /run/openrc 2>/dev/null mkdir /run/openrc touch /run/openrc/softlevel exec /sbin/openrc else "$@" fi