improvements
[automated-distro-installer] / fai / config / scripts / DEBIAN / 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 m() { printf "%s\n" "$*"; "$@"; }
28
29 source $FAI/distro-install-common/bash-misc-functions
30
31 fcopy -riB /root
32
33 # in bullseye, installing systemd-resolved says: Converting
34 # /etc/resolv.conf to a symlink to
35 # /run/systemd/resolve/stub-resolv.conf... which breaks
36 # resolution. This happens to be the first script we install a package
37 # after that. This should do nothing in a fai-wrapper situation.
38 if [[ ! -s $target/etc/resolv.conf ]]; then
39 m ls -la $target/etc/resolv.conf ||:
40 # Keep the symlink in place, systemd-resolved should change the file
41 # when it runs.
42 mkdir -p $target/run/systemd/resolve
43 if [[ ! -s /etc/resolv.conf ]] && ! host google.com; then
44 echo "ERROR: empty resolv.conf & failed dns resolution. exiting 1" >&2
45 exit 1
46 fi
47 cat /etc/resolv.conf >$target/etc/resolv.conf
48 fi
49
50
51
52 #### misc configurations
53 chroot $FAI_ROOT bash <<'EOFOUTER'
54 set -xe
55 if getent group systemd-journal >/dev/null; then
56 # makes the journal be saved to disk.
57 mkdir -p /var/log/journal
58 chmod 755 /var/log/journal
59 fi
60 debconf-set-selections <<EOF
61 kexec-tools kexec-tools/load_kexec boolean false
62 EOF
63
64 # This used to be pxe-kexec. For some reason pxe-kexec is not in
65 # bookworm. kexec-tools is
66 # something pxe-kexec depended on and might be useful.
67 # todo: figure out why and get it installed.
68 apt-get install -y kexec-tools
69
70 # this is usefull. Only thing reason I see this being disabled by default is
71 # that a non-root user can disrupt the system, eg cause a reboot.
72 sed -i '$a kernel.sysrq=1
73 /^kernel.sysrq=/d' /etc/sysctl.conf
74 EOFOUTER
75
76 cmdline_extra="$d16_cmdline $fsf_cmdline_extra"
77
78 # luks options, see man systemd-cryptsetup-generator
79 # all i know is that with luks.crypttab=no, swap still timed out on boot.
80 # and with rd.luks.crypttab=no, it works.
81 cmdline="rd.luks.crypttab=no net.ifnames=0 $cmdline_extra"
82
83
84 u /etc/default/grub.d/iank.cfg <<'EOF'
85 # note: in git history, you can see code that modified the existing
86 # GRUB_CMDLINE_LINUX_DEFAULT. That was being cautious in case something
87 # else modified it, but experience has shown nothing else modifying it.
88
89 GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"
90 GRUB_TERMINAL=console
91 # on xenial, no grub is displayed at all. fix that.
92 # found just by noticing a warning about it in error.log
93 GRUB_HIDDEN_TIMEOUT=
94 GRUB_TIMEOUT_STYLE=menu
95 GRUB_TIMEOUT=4
96 # grub tries to detect error in booting and then wait longer with this entry.
97 # but that detection doesn't work for us because we have btrfs /boot, and so it flags
98 # failure always.
99 GRUB_RECORDFAIL_TIMEOUT=4
100 EOF
101
102 if $ur; then
103 $ROOTCMD update-grub
104 fi
105
106 # I prefer to stick with ifup/down or networkmanager: networkd is not in its
107 # own package, so cant use in other init systems. b. it works fine.
108 chroot $FAI_ROOT bash <<EOF
109 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
110 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
111 EOF