set sudo group earlier to be safe
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 11-iank
index 8a9eab792b8ebd230366dae0b40df959de60ff2c..93df65558234e1a2537ec50ea83009817228f5a2 100755 (executable)
@@ -27,6 +27,7 @@ fi
 fcopy -riB /boot
 # this is also done by FABASE/10-misc by default (without B)
 fcopy -riB /root
+fcopy -riB /usr/local/bin
 
 
 src=$FAI/distro-install-common/shadow
@@ -104,10 +105,29 @@ if [[ $FAI_ACTION != dirinstall ]] && ! ifclass NOCRYPT; then
     speed=115200
     cmdline="rd.luks.crypttab=no net.ifnames=0 console=ttyS0,${speed}n8 console=tty0"
     case $HOSTNAME in
-      # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
-      # evo-870 doesnt get along well with d16 with etiona.
-      # the number is based on dmesg errors
-      kd) cmdline+=" libata.force=4.00:noncq" ;;
+      kd)
+        fcopy -v /usr/bin/myncq
+
+        cat >$target/etc/systemd/system/myncq.service <<'EOF'
+[Unit]
+Description=fix ncq errors
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/myncq
+TimeoutStartSec=20
+
+[Install]
+# https://www.enricozini.org/blog/2017/debian/systemd-07-devices/
+WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
+EOF
+
+        chroot $FAI_ROOT bash <<'EOFOUTER'
+systemctl enable myncq.service
+/usr/bin/myncq no-upgrub
+EOFOUTER
+
+        ;;
       # per rubens suggestion to make a d16 more stable
       kd|kw) cmdline+=" pci=realloc=off" ;;
     esac
@@ -132,7 +152,15 @@ EOF
   chroot $FAI_ROOT bash <<EOF
 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
-# we remove quiet and splash, and all thats left is what we want
+
+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
+
+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
@@ -144,7 +172,12 @@ sed -ri 's/^ *GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="$cmdline
 # warning about it in error.log
 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
 
-update-grub2
+if type -P update-grub2 &>/dev/null; then
+  update-grub2
+else
+  update-grub
+fi
+
 EOF
 fi ##### end != dirinstall && != NOCRYPT
 
@@ -165,6 +198,22 @@ case $HOSTNAME in
 esac
 
 
+# bug fix, somewhere between t9's xorg 1.19.6
+# and 1.20.1-3ubuntu2
+#  xserver-xorg-video-nouveau                 1:1.0.15-3
+# xorg stopped load nouveau
+#  https://www.linuxquestions.org/questions/slackware-14/kernel-modules-conflicting-with-nouveau-driver-4175623867/
+# https://nouveau.freedesktop.org/InstallNouveau.html
+if lspci|grep -q 'GeForce GTX 6[0-9][0-9]\]'; then
+  mkdir -p $target/etc/X11/xorg.conf.d/
+  cat >$target/etc/X11/xorg.conf.d/10-nouveau.conf <<'EOF'
+Section "Device"
+Identifier "Device0"
+Driver "nouveau"
+EndSection
+EOF
+fi
+
 # use networkmanager if this host has wireless.
 if type -p iw &>/dev/null && [[ $(iw dev) ]]; then
   chroot $FAI_ROOT bash <<EOF
@@ -191,6 +240,8 @@ auto lo eth0
 iface lo inet loopback
 iface eth0 inet static
 address 10.3.0.2/16
+
+source-directory /etc/network/interfaces.d
 EOF
   fi
 
@@ -201,6 +252,8 @@ auto lo eth0
 iface lo inet loopback
 iface eth0 inet dhcp
 iface eth0 inet6 auto
+
+source-directory /etc/network/interfaces.d
 EOF
 
   # previously had an else condition after
@@ -247,9 +300,10 @@ gateway fe80::1
 iface eth0 inet6 static
 # from a requested /64 pool
 address 2600:3c00:e000:280::2/64
+
+source-directory /etc/network/interfaces.d
 EOF
   fi
-
 fi
 
 # I prefer to stick with ifup/down for now. a. networkd is not in its
@@ -262,39 +316,60 @@ EOF
 ##### end network setup  #####
 
 
-if ifclass VOL_BUSTER_BOOTSTRAP; then
-  fcopy -riM /etc/systemd/system
+if ifclass VOL_BULLSEYE_BOOTSTRAP; then
+  fcopy /etc/systemd/system/faicheck.service
   chroot $FAI_ROOT bash <<'EOFOUTER'
-systemctl enable fai_check.service
+systemctl enable faicheck.service
 EOFOUTER
   exit 0 # avoid unnecessary stuff in bootstrap vol
 fi
 
 
-
 ## misc settings
 chroot $FAI_ROOT bash <<'EOFOUTER'
 #### begin .ssh setup ###
 set -x
 set -eE -o pipefail
-mkdir -p /home/iank/.ssh
-f=/root/.ssh/authorized_keys
-if [[ -e $f ]]; then
-   cp $f /home/iank/.ssh
+if ! [[ -s /home/iank/.ssh/authorized_keys ]]; then
+  mkdir -p /home/iank/.ssh
+  f=/root/.ssh/authorized_keys
+  if [[ -e $f ]]; then
+     cp $f /home/iank/.ssh
+  fi
+  chown -R 1000:1000 /home/iank/.ssh
+  chmod -R u=Xrw,og= /home/iank/.ssh
+  rm -rf /root/.ssh
+  # remove broken symlinks or the following cp will fail
+  find /home/iank/.ssh -xtype l -exec rm '{}' \;
+  cp -rL /home/iank/.ssh /root
+  chown -R root:root /root/.ssh
+  chmod 700 /root/.ssh
 fi
-chown -R 1000:1000 /home/iank/.ssh
-chmod -R u=Xrw,og= /home/iank/.ssh
-rm -rf /root/.ssh
-# remove broken symlinks or the following cp will fail
-find /home/iank/.ssh -xtype l -exec rm '{}' \;
-cp -rL /home/iank/.ssh /root
-chown -R root:root /root/.ssh
-chmod 700 /root/.ssh
-# https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
+
+# old link from
+# # https://ticktockhouse.svbtle.com/my-obligatory-ubuntu-ssh-agent-post
+# but that made a service that started too soon and didn't pick up our
+# x env vars. instead, copy from the root ssh-agent just the
+# appropriate things into a new service.
+rm -f /home/iank/.config/systemd/user/default.target.wants/ssh-agent.service
+
+mkdir -p /home/iank/.local/share/systemd/user
+cat >/home/iank/.local/share/systemd/user/sshaiank.service <<'EOF'
+[Unit]
+Description=OpenSSH User Agent
+Documentation=man:ssh-agent(1)
+[Service]
+ExecStart=/usr/lib/openssh/agent-launch start
+ExecStopPost=/usr/lib/openssh/agent-launch stop
+[Install]
+WantedBy=default.target
+EOF
+# enable it
 # systemctl --user is not available at fai time, so create the link ourselves
-d=/home/iank/.config/systemd/user/default.target.wants
-sudo -u iank mkdir -p $d
-sudo -u iank ln -sf /usr/lib/systemd/user/ssh-agent.service $d
+dir=/home/iank/.config/systemd/user/default.target.wants
+mkdir -p $dir
+ln -sf /home/iank/.local/share/systemd/user/sshaiank.service $dir
+
 #### end .ssh setup ###
 
 ## duplicated in ssh-emacs-setup
@@ -304,9 +379,9 @@ f=/etc/ssh/sshd_config
 grep -xFq "$line" $f || tee -a $f <<<"$line"
 
 
-# default debian groups (jessie through buster) + adm, sudo, root
-for g in cdrom floppy audio dip video plugdev netdev adm sudo; do
-  if getent gropu $g >/dev/null; then
+# default debian groups (jessie through buster) + adm, root, admin
+for g in cdrom floppy audio dip video plugdev netdev adm sudo admin; do
+  if getent group $g >/dev/null; then
     usermod -aG $g iank
   fi
 done