shellcheck stuff
[distro-setup] / bitfolk-chroot-install
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
25 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
26 set -eE -o pipefail
27 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
28
29
30 host=$1
31
32 case $host in
33 je)
34 ip6=2001:ba8:1f1:f09d
35 ip4=85.119.82.128
36 ;;
37 bk)
38 ip6=2001:ba8:1f1:f0c9
39 ip4=85.119.83.50
40 ;;
41 esac
42
43 debconf-set-selections <<'EOF'
44 locales locales/default_environment_locale select en_US.UTF-8
45 locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
46 EOF
47
48 # /a/bin/fai/fai/config/hooks/updatebase.UBUNTU
49 # shellcheck disable=SC2016
50 debconf --owner=locales sh -c '
51 . /usr/share/debconf/confmodule
52 db_version 2.0
53 db_get locales/locales_to_be_generated &&
54 mkdir -p /var/lib/locales/supported.d &&
55 echo "$RET" > /var/lib/locales/supported.d/local'
56 dpkg-reconfigure -fnoninteractive locales
57
58 apt -y remove --purge --auto-remove netplan.io libnetplan0
59 apt update
60 apt -y install linux-virtual-hwe-20.04 grub-pc-bin openssh-server ifupdown rsync
61 mkdir -p /root/.ssh
62 chmod 700 /root/.ssh
63 cat >/root/.ssh/authorized_keys <<'EOF'
64 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDX42yru/h6r6UDRy/VwVZjcYEmNLG5/SUjv7xwu43OaW0wL+uHYg2rkfn4Ygh5o1I5pgBh2SWg8TeWuVGhgL1SCuBzzeai/+58Sny065Qak+D2WjVOuRonRelh+CBA5EpNZPuiWQkoWdf9NACTBCbS2Zu7r8OOgRqu/ruaDNePlG5+U0Wlpy3oBnpbzQiuSA3AKMW30fsCJtOBjz5qQaiPbYEKJy3AOvtbq10wliKx9TpsTzrq8dKWs7PLhZnzqVCsaq6D95IzjqXcSpx4Cga5bn+YEuAnJQ53PGA5eO+hpz6HDmawTbJlaV/Dufb9bJ/ZZy1DXzs07yWRtTEY54/X ian@iankelling.org
65 EOF
66
67 # https://tools.bitfolk.com/wiki/IPv6
68 cat >/etc/network/interfaces <<EOF
69 auto lo
70 iface lo inet loopback
71
72 # The primary network interface
73 auto eth0
74 iface eth0 inet static
75 address $ip4/21
76 gateway 85.119.80.1
77
78 iface eth0 inet6 static
79 address $ip6::2
80 netmask 64
81 gateway $ip6::1
82 post-up echo 0 > /proc/sys/net/ipv6/conf/default/accept_ra
83 post-up echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra
84 post-up echo 0 > /proc/sys/net/ipv6/conf/\$IFACE/accept_ra
85 post-up echo 0 > /proc/sys/net/ipv6/conf/default/autoconf
86 post-up echo 0 > /proc/sys/net/ipv6/conf/all/autoconf
87 post-up echo 0 > /proc/sys/net/ipv6/conf/\$IFACE/autoconf
88 EOF
89
90 cat >/etc/fstab <<'EOF'
91 /dev/xvda1 / ext4 noatime,nodiratime 0 1
92 /dev/xvdb1 none swap nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,sw 0 0
93 EOF
94
95 cat >> /etc/default/grub <<'EOF'
96 GRUB_CMDLINE_LINUX_DEFAULT=""
97 GRUB_CMDLINE_LINUX="console=hvc0"
98 EOF
99
100 update-grub
101
102 cat >/etc/systemd/resolved.conf.d/servers.conf <<'EOF'
103 [Resolve]
104 DNS=85.119.80.232 85.119.80.233
105 Domains=~.
106 EOF
107
108 cat >/etc/hostname <<EOF
109 $host
110 EOF
111
112 # from fai/fai/config/scripts/FAIBASE/10-misc
113
114 TIMEZONE=US/Eastern
115 echo $TIMEZONE >/etc/timezone
116 if [[ -L /etc/localtime ]]; then
117 ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
118 else
119 cp -f /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
120 fi
121
122
123 echo $0 SUCCESS