diff options
author | Freya Murphy <freya@freyacat.org> | 2023-12-30 15:23:30 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-12-30 15:23:30 -0500 |
commit | 9ea034f42095bb1a61d1e8ee628575cb2bbee7e6 (patch) | |
tree | 123e5758aa4b078eea5dce59ebe4f1afaf7ec523 /setup.sh | |
parent | stubnet (diff) | |
download | freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.tar.gz freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.tar.bz2 freyanet-9ea034f42095bb1a61d1e8ee628575cb2bbee7e6.zip |
refactor
Diffstat (limited to 'setup.sh')
-rwxr-xr-x | setup.sh | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/setup.sh b/setup.sh deleted file mode 100755 index 6d51389..0000000 --- a/setup.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/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 <<EOF -log "/var/log/bird.log" all; - -$(getval RouterID | while read -r line; do echo "router id $line;"; done) - -protocol kernel { - ipv4 { export all; }; -} - -protocol kernel { - ipv6 { export all; }; -} - -protocol device { -} - -protocol direct { - ipv4; - ipv6; -} - -protocol static { - ipv4; -} - -EOF - if [ -n "$ospf" ]; then - 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 - ) - - cat <<EOF -protocol ospf v3 ospf4 { - ipv4 { - import all; - export filter { if source ~ [RTS_DEVICE, RTS_INHERIT] && net ~ [$(getval "Subnet" | grep -v ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')] 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 ~ [$(getval "Subnet" | grep ':' | while read -r line; do printf "%s+," "$line"; done | sed 's/,$//')] then accept; else reject; }; - }; - area 0 { -$(getval "Stubnet" | grep ':' | while read -r net; do echo " stubnet $net {};"; done) -$interfacelist - }; -} -EOF - fi -) > /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 - |