improvements
[automated-distro-installer] / fai / config / scripts / DEBIAN / 11-iank
index 69b9afe7bc10c3f2d53a8999e2795ceb1439ca5c..b2c5567533a56e35bcc4a7e0ccb13fbc8f366ab9 100755 (executable)
@@ -24,12 +24,34 @@ if [[ $EUID != 0 ]]; then
   exit 1
 fi
 
+m() { printf "%s\n" "$*";  "$@"; }
+
+source $FAI/distro-install-common/bash-misc-functions
+
 fcopy -riB /root
 
+# in bullseye, installing systemd-resolved says: Converting
+# /etc/resolv.conf to a symlink to
+# /run/systemd/resolve/stub-resolv.conf...  which breaks
+# resolution. This happens to be the first script we install a package
+# after that. This should do nothing in a fai-wrapper situation.
+if [[ ! -s $target/etc/resolv.conf ]]; then
+  m ls -la $target/etc/resolv.conf ||:
+  # Keep the symlink in place, systemd-resolved should change the file
+  # when it runs.
+  mkdir -p $target/run/systemd/resolve
+  if [[ ! -s /etc/resolv.conf ]] && ! host google.com; then
+    echo "ERROR: empty resolv.conf & failed dns resolution. exiting 1" >&2
+    exit 1
+  fi
+  cat /etc/resolv.conf >$target/etc/resolv.conf
+fi
+
+
 
 #### misc configurations
 chroot $FAI_ROOT bash <<'EOFOUTER'
-set -x
+set -xe
 if getent group systemd-journal >/dev/null; then
   # makes the journal be saved to disk.
   mkdir -p /var/log/journal
@@ -38,13 +60,17 @@ fi
 debconf-set-selections <<EOF
 kexec-tools kexec-tools/load_kexec boolean false
 EOF
-apt-get install -y pxe-kexec
+
+# This used to be pxe-kexec. For some reason pxe-kexec is not in
+# bookworm. kexec-tools is
+# something pxe-kexec depended on and might be useful.
+# todo: figure out why and get it installed.
+apt-get install -y kexec-tools
 
 # this is usefull. Only thing reason I see this being disabled by default is
 # that a non-root user can disrupt the system, eg cause a reboot.
 sed -i '$a kernel.sysrq=1
 /^kernel.sysrq=/d' /etc/sysctl.conf
-
 EOFOUTER
 
 cmdline_extra="$d16_cmdline $fsf_cmdline_extra"
@@ -54,45 +80,28 @@ cmdline_extra="$d16_cmdline $fsf_cmdline_extra"
 # and with rd.luks.crypttab=no, it works.
 cmdline="rd.luks.crypttab=no net.ifnames=0 $cmdline_extra"
 
-chroot $FAI_ROOT bash <<EOF
-set -x
-set -eE -o pipefail
-# https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
 
-sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")quiet/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) quiet([ "])/\1\2/' /etc/default/grub
-sed -ri 's/(^GRUB_CMDLINE_LINUX_DEFAULT=")splash/\1/;s/^(GRUB_CMDLINE_LINUX_DEFAULT=".*) splash([ "])/\1\2/' /etc/default/grub
+u /etc/default/grub.d/iank.cfg <<'EOF'
+# note: in git history, you can see code that modified the existing
+# GRUB_CMDLINE_LINUX_DEFAULT. That was being cautious in case something
+# else modified it, but experience has shown nothing else modifying it.
 
-for arg in $cmdline; do
-  if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]\${arg//./\\.}[\" ]" /etc/default/grub; then
-    sed -ri "s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"\$arg \1/" /etc/default/grub
-  fi
-done
-
-if grep -qF "$cmdline" /etc/default/grub; then
-  # already set things, exit
-  exit 0
-fi
-
-# required to show vga grub on d16, at least for t11
-echo GRUB_TERMINAL=console >>/etc/default/grub
-
-
-sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"/' /etc/default/grub
-sed -ri 's/^ *GRUB_TIMEOUT_STYLE=.*/GRUB_TIMEOUT_STYLE=menu/' /etc/default/grub
-sed -ri 's/^ *GRUB_TIMEOUT=.*/GRUB_TIMEOUT=6/' /etc/default/grub
+GRUB_CMDLINE_LINUX_DEFAULT="$cmdline"
+GRUB_TERMINAL=console
 # on xenial, no grub is displayed at all. fix that.
-# found just by noticing this in the config file, and a
-# warning about it in error.log
-sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
-
-if type -P update-grub2 &>/dev/null; then
-  update-grub2
-else
-  update-grub
-fi
-
+# found just by noticing a warning about it in error.log
+GRUB_HIDDEN_TIMEOUT=
+GRUB_TIMEOUT_STYLE=menu
+GRUB_TIMEOUT=4
+# grub tries to detect error in booting and then wait longer with this entry.
+# but that detection doesn't work for us because we have btrfs /boot, and so it flags
+# failure always.
+GRUB_RECORDFAIL_TIMEOUT=4
 EOF
 
+if $ur; then
+  $ROOTCMD update-grub
+fi
 
 # I prefer to stick with ifup/down or networkmanager: networkd is not in its
 # own package, so cant use in other init systems. b. it works fine.