#!/bin/bash -x
+# This file is part of Ian Kelling's automated-distro-installer
+# Copyright (C) 2024 Ian Kelling
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
source-directory /etc/network/interfaces.d
EOF
else
- ip=$(getent ahosts $HOSTNAME |grep ^209.*RAW| sed 's/ .*//')
- ip6=$(getent ahosts $HOSTNAME |grep ^2001.*RAW| sed 's/ .*//')
- gateway=209.51.188.1
+ ip6=$(getent ahosts $HOSTNAME |grep ^2001.*RAW| sed 's/ .*//' ||:)
gateway6=2001:470:142::1
- cat > $target/etc/network/interfaces <<EOF
-# The loopback network interface
+
+ # todo: this needs adjustment per machine
+ internal_ip=10.0.0.25/16
+
+ if ip l show dev bond0 &>/dev/null; then
+ cat >$target/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
-iface eth0 inet static
- address $ip
- gateway $gateway
- netmask 255.255.255.0
+allow-bond eth0
+iface eth0 inet manual
+ bond-master bond0
-iface eth0 inet6 static
- pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_dad
+auto eth1
+allow-bond eth1
+iface eth1 inet manual
+ bond-master bond0
+
+auto bond0
+iface bond0 inet static
+ bond-slaves none
+ bond-mode 0
+ bond-miimon 100
+ address $internal_ip
+ pre-up ip link add link bond0 name macvtap-bond0 type macvtap mode bridge
+# no iptables files exist yet
+# post-up iptables-restore < /etc/default/iptables ; ip6tables-restore < /etc/default/ip6tables || :
+
+auto macvtap-bond0
+iface macvtap-bond0 inet static
+ address $CIDR
+ gateway $GATEWAYS
+ post-up ip a add $internal_ip broadcast 10.0.255.255 dev macvtap-bond0
+
+EOF
+
+ # I'm not sure ipv6 works well with the macvtap stuff. todo: research.
+ # anyways, other kvm hosts dont have it enabled.
+ if false && [[ $ip6 ]]; then
+ cat >>$target/etc/network/interfaces <<EOF
+iface bond0 inet6 static
+ pre-up echo 0 > /proc/sys/net/ipv6/conf/bond0/accept_dad
address $ip6
netmask 48
gateway $gateway6
EOF
+ fi
+
+ else
+ cat > $target/etc/network/interfaces <<EOF
+auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet static
+address $CIDR
+gateway $GATEWAYS
+EOF
+
+ if [[ $ip6 ]]; then
+ cat >>$target/etc/network/interfaces <<EOF
+iface eth0 inet6 static
+pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_dad
+address $ip6
+netmask 48
+gateway $gateway6
+EOF
+ fi
+ fi
fi
# previously had an else condition after
##### end network setup #####
+# note: systemd-resolved + ifupdown causes networking.service to fail in t11,
+# https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1907878
+systemctl disable systemd-resolved
# rm first to remove any symlink
rm -f $target/etc/resolv.conf
-if ifclass demohost; then
+if ifclass demohost || [[ $GATEWAYS != 209.51.188.* ]]; then
cat >$target/etc/resolv.conf <<'EOF'
nameserver 8.8.8.8
EOF