more complete copyright notices
[automated-distro-installer] / fai / config / scripts / FSF / 11-iank
1 #!/bin/bash -x
2 # This file is part of Ian Kelling's automated-distro-installer
3 # Copyright (C) 2024 Ian Kelling
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 set -eE -o pipefail
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21
22 if [[ $EUID != 0 ]]; then
23 echo "$0: error: expected to be root."
24 exit 1
25 fi
26
27
28 sed 's/^/root:/' $FAI/distro-install-common/shadow/community0p | $ROOTCMD chpasswd -e
29
30 # todo, need to set static ip here
31 if ifclass demohost; then
32 cat > $target/etc/network/interfaces <<EOF
33 # generated by FAI
34 auto lo eth0
35 iface lo inet loopback
36 iface eth0 inet dhcp
37 iface eth0 inet6 auto
38
39 source-directory /etc/network/interfaces.d
40 EOF
41 else
42 ip6=$(getent ahosts $HOSTNAME |grep ^2001.*RAW| sed 's/ .*//' ||:)
43 gateway6=2001:470:142::1
44
45 # todo: this needs adjustment per machine
46 internal_ip=10.0.0.25/16
47
48 if ip l show dev bond0 &>/dev/null; then
49 cat >$target/etc/network/interfaces <<EOF
50 auto lo
51 iface lo inet loopback
52
53 auto eth0
54 allow-bond eth0
55 iface eth0 inet manual
56 bond-master bond0
57
58 auto eth1
59 allow-bond eth1
60 iface eth1 inet manual
61 bond-master bond0
62
63 auto bond0
64 iface bond0 inet static
65 bond-slaves none
66 bond-mode 0
67 bond-miimon 100
68 address $internal_ip
69 pre-up ip link add link bond0 name macvtap-bond0 type macvtap mode bridge
70 # no iptables files exist yet
71 # post-up iptables-restore < /etc/default/iptables ; ip6tables-restore < /etc/default/ip6tables || :
72
73 auto macvtap-bond0
74 iface macvtap-bond0 inet static
75 address $CIDR
76 gateway $GATEWAYS
77 post-up ip a add $internal_ip broadcast 10.0.255.255 dev macvtap-bond0
78
79 EOF
80
81 # I'm not sure ipv6 works well with the macvtap stuff. todo: research.
82 # anyways, other kvm hosts dont have it enabled.
83 if false && [[ $ip6 ]]; then
84 cat >>$target/etc/network/interfaces <<EOF
85 iface bond0 inet6 static
86 pre-up echo 0 > /proc/sys/net/ipv6/conf/bond0/accept_dad
87 address $ip6
88 netmask 48
89 gateway $gateway6
90 EOF
91 fi
92
93 else
94 cat > $target/etc/network/interfaces <<EOF
95 auto lo
96 iface lo inet loopback
97
98 auto eth0
99 iface eth0 inet static
100 address $CIDR
101 gateway $GATEWAYS
102 EOF
103
104 if [[ $ip6 ]]; then
105 cat >>$target/etc/network/interfaces <<EOF
106 iface eth0 inet6 static
107 pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_dad
108 address $ip6
109 netmask 48
110 gateway $gateway6
111 EOF
112 fi
113 fi
114 fi
115
116 # previously had an else condition after
117 #elif ifclass VM || ifclass LINODE; then
118 # iface $NIC1 inet manual
119 # iface br0 inet dhcp
120 # bridge_ports $NIC1
121 # bridge_stp off
122 # bridge_maxwait 0
123 # however, on t9, on startup, br0, became
124 # rename1 and didn't come up. i dunno why,
125 # but the bridge is for vms that I rarely use,
126 # so not bothering to figure it out.
127
128
129 ##### end network setup #####
130
131 # note: systemd-resolved + ifupdown causes networking.service to fail in t11,
132 # https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1907878
133 systemctl disable systemd-resolved
134 # rm first to remove any symlink
135 rm -f $target/etc/resolv.conf
136
137 if ifclass demohost || [[ $GATEWAYS != 209.51.188.* ]]; then
138 cat >$target/etc/resolv.conf <<'EOF'
139 nameserver 8.8.8.8
140 EOF
141 else
142 cat >$target/etc/resolv.conf <<'EOF'
143 domain fsf.org
144 search fsf.org
145 nameserver 209.51.188.16
146 nameserver 209.51.188.27
147 EOF
148 fi