69b9afe7bc10c3f2d53a8999e2795ceb1439ca5c
[automated-distro-installer] / 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 fcopy -riB /root
28
29
30 #### misc configurations
31 chroot $FAI_ROOT bash <<'EOFOUTER'
32 set -x
33 if getent group systemd-journal >/dev/null; then
34 # makes the journal be saved to disk.
35 mkdir -p /var/log/journal
36 chmod 755 /var/log/journal
37 fi
38 debconf-set-selections <<EOF
39 kexec-tools kexec-tools/load_kexec boolean false
40 EOF
41 apt-get install -y pxe-kexec
42
43 # this is usefull. Only thing reason I see this being disabled by default is
44 # that a non-root user can disrupt the system, eg cause a reboot.
45 sed -i '$a kernel.sysrq=1
46 /^kernel.sysrq=/d' /etc/sysctl.conf
47
48 EOFOUTER
49
50 cmdline_extra="$d16_cmdline $fsf_cmdline_extra"
51
52 # luks options, see man systemd-cryptsetup-generator
53 # all i know is that with luks.crypttab=no, swap still timed out on boot.
54 # and with rd.luks.crypttab=no, it works.
55 cmdline="rd.luks.crypttab=no net.ifnames=0 $cmdline_extra"
56
57 chroot $FAI_ROOT bash <<EOF
58 set -x
59 set -eE -o pipefail
60 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
61
62 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")quiet/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) quiet([ "])/\1\2/' /etc/default/grub
63 sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")splash/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) splash([ "])/\1\2/' /etc/default/grub
64
65 for arg in $cmdline; do
66 if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]\${arg//./\\.}[\" ]" /etc/default/grub; then
67 sed -ri "s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"\$arg \1/" /etc/default/grub
68 fi
69 done
70
71 if grep -qF "$cmdline" /etc/default/grub; then
72 # already set things, exit
73 exit 0
74 fi
75
76 # required to show vga grub on d16, at least for t11
77 echo GRUB_TERMINAL=console >>/etc/default/grub
78
79
80 sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
81 sed -ri 's/^ *GRUB_TIMEOUT_STYLE=.*/GRUB_TIMEOUT_STYLE=menu/' /etc/default/grub
82 sed -ri 's/^ *GRUB_TIMEOUT=.*/GRUB_TIMEOUT=6/' /etc/default/grub
83 # on xenial, no grub is displayed at all. fix that.
84 # found just by noticing this in the config file, and a
85 # warning about it in error.log
86 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
87
88 if type -P update-grub2 &>/dev/null; then
89 update-grub2
90 else
91 update-grub
92 fi
93
94 EOF
95
96
97 # I prefer to stick with ifup/down or networkmanager: networkd is not in its
98 # own package, so cant use in other init systems. b. it works fine.
99 chroot $FAI_ROOT bash <<EOF
100 systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
101 systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online
102 EOF