static usb ethnet addresses
[automated-distro-installer] / fai / config / scripts / IANK / 11-iank
index e77eb8f8ca3081bd7f5ce0902c90d976f69c7d2d..54641b237bcc10b15b30b90bb0f8b662253f8609 100755 (executable)
@@ -1,4 +1,20 @@
 #!/bin/bash -x
+# This file is part of Ian Kelling's automated-distro-installer
+# Copyright (C) 2024 Ian Kelling
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
@@ -12,15 +28,6 @@ if ! type -t fcopy &>/dev/null; then
   sudo apt-get -y install fai-client
 fi
 
-if [[ -e /a/bin/fai/fai-wrapper ]]; then
-  chroot() {
-    shift
-    "$@"
-  }
-fi
-
-
-
 # -r = recursive
 # -i = ignore non-matching class warnings, always exit 0
 # -B = no backup files
@@ -28,6 +35,8 @@ fcopy -riB /boot
 # this is also done by FAIBASE/10-misc by default (without B)
 fcopy -riB /usr/local/bin
 
+fcopy -riB /etc/apt/logind.conf.d
+
 # this gets done by fai, but just happens too often that
 # I add sources due to new distros, whatever.
 fcopy -riB /etc/apt/preferences.d
@@ -42,6 +51,8 @@ if [[ ! -e $dst && -e $src ]]; then
   mount -o bind $src $dst
 fi
 
+
+
 $FAI/distro-install-common/end
 
 
@@ -51,13 +62,13 @@ $FAI/distro-install-common/end
 # I run this as a single post-fai script to update things that have changed.
 tmpfile1=$(mktemp)
 # this can fail if we need an apt update
-chroot $FAI_ROOT /usr/bin/apt-cache policy >$tmpfile1 ||:
+$ROOTCMD /usr/bin/apt-cache policy >$tmpfile1 ||:
 fcopy -riB /etc/apt
 
 tmpfile2=$(mktemp)
-chroot $FAI_ROOT /usr/bin/apt-cache policy >$tmpfile2
+$ROOTCMD /usr/bin/apt-cache policy >$tmpfile2
 if ! diff -q $tmpfile1 $tmpfile2; then
-  chroot $FAI_ROOT /usr/bin/apt update
+  $ROOTCMD /usr/bin/apt update
 fi
 # outside of fai, this seems to regularly lead to
 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
@@ -81,7 +92,6 @@ fi
 
 #### misc configurations
 
-
 if [[ $FAI_ACTION != dirinstall ]] && ! ifclass NOCRYPT; then
   if ifclass LINODE; then
     speed=19200
@@ -107,12 +117,12 @@ TimeoutStartSec=20
 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
 EOF
 
-        chroot $FAI_ROOT bash <<'EOFOUTER'
+        $ROOTCMD 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
@@ -156,8 +166,8 @@ EOF
 fi
 
 # use networkmanager if this host has wireless.
-if [[ $HOSTNAME == bo ]] || type -p iw &>/dev/null && [[ $(iw dev) ]]; then
-  chroot $FAI_ROOT bash <<EOF
+if [[ $(iw dev) ]]; then
+  $ROOTCMD bash -xe <<EOF
 apt-get -y install network-manager
 EOF
 
@@ -174,18 +184,16 @@ EOF
 [main]
 dns=systemd-resolved
 EOF
-  if [[ $HOSTNAME == frodo ]]; then
-    cat > $target/etc/network/interfaces <<-EOF
-# generated by FAI
-auto lo eth0
-iface lo inet loopback
-iface eth0 inet static
-address 10.3.0.2/16
 
-source-directory /etc/network/interfaces.d
-EOF
+  $FAI/distro-install-common/ethusb-static
+  if [[ $(dig +short @10.2.0.1 -x 10.2.0.2 2>&1 ||:) == kd.b8.nz. ]] \
+       && ip n show 10.2.0.1 | grep . &>/dev/null; then
+    : # we are at home. note: logic duplicated in btrbk-run
+  else
+    $FAI/distro-install-common/ethusb-nm
   fi
 
+
 else
   cat > $target/etc/network/interfaces <<-EOF
 # generated by FAI
@@ -250,9 +258,9 @@ fi
 ##### end network setup  #####
 
 
-if ifclass VOL_BULLSEYE_BOOTSTRAP; then
+if ifclass VOL_BULLSEYE_BOOTSTRAP || ifclass VOL_BOOKWORM_BOOTSTRAP; then
   fcopy /etc/systemd/system/faicheck.service
-  chroot $FAI_ROOT bash <<'EOFOUTER'
+  $ROOTCMD bash <<'EOFOUTER'
 systemctl enable faicheck.service
 EOFOUTER
   exit 0 # avoid unnecessary stuff in bootstrap vol
@@ -260,7 +268,7 @@ fi
 
 
 ## misc settings
-chroot $FAI_ROOT bash <<'EOFOUTER'
+$ROOTCMD bash <<'EOFOUTER'
 #### begin .ssh setup ###
 set -x
 set -eE -o pipefail
@@ -285,7 +293,6 @@ fi
 # 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
 
 rm -f /home/iank/.local/share/systemd/user/sshaiank.service \
   /home/iank/.config/systemd/user/default.target.wants/sshaiank.service
@@ -325,3 +332,70 @@ fi
 for g in plugdev audio video cdrom; do
   $ROOTCMD usermod -a -G $g user2
 done
+
+
+## begin get new kernel and btrfs-progs ##
+case $HOSTNAME in
+  sy|so)
+    $FAI/distro-install-common/install-stable-kernel-debs
+    ;;
+  *)
+    $ROOTCMD apt-get -y install linux-libre
+    ;;
+esac
+
+pre=https://mirrors.edge.kernel.org/pub/linux/kernel/people/kdave/btrfs-progs
+tarball=$(curl -s $pre/sha256sums.asc \
+            | awk '$2 ~ /^btrfs-progs-v/ { print $2 }' | grep -v -- -rc | grep "^btrfs-progs-v.*gz\$" | sort -V | tail -n1)
+url="$pre/$tarball"
+dir=${tarball%.tar.gz}
+ver=${dir#btrfs-progs-}
+cur_ver=$($ROOTCMD btrfs --version 2>/dev/null | awk '{print $2}') ||:
+
+if [[ $FAI_ROOT == / ]]; then
+  bp_dir=/a/opt/btrfs-progs-release
+else
+  bp_dir=$FAI/distro-install-common/btrfs-progs-release
+fi
+if [[ $ver != "$cur_ver" ]]; then
+  if [[ $ver != "$($bp_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
+    cd $target/tmp
+    wget $url
+    tar xzf $tarball
+    $ROOTCMD apt-get -y build-dep btrfs-progs
+    # no docs cuz I didn't want to bother fixing error of missing docs dependencies
+    $ROOTCMD bash -xe <<EOF
+cd /tmp/${tarball%.tar.gz}
+./configure --disable-documentation
+make
+make install
+EOF
+    # If our desktop is HOST2, will we btrbk this latest bprogs to other
+    # machines.
+    if [[ -s /a/bin/bash_unpublished/source-state ]]; then
+      source /a/bin/bash_unpublished/source-state
+    fi
+    if [[ $HOST2 == "$HOSTNAME" && $FAI_ROOT != / ]]; then
+      rm -rf $bp_dir
+      chown -R iank:iank $target/tmp/${tarball%.tar.gz}
+      mv $target/tmp/${tarball%.tar.gz} $bp_dir
+    fi
+  else
+    if ! $ROOTCMD dpkg -s -- build-essential  2>&1 | grep -Fx "Status: install ok installed" &>/dev/null; then
+      $ROOTCMD apt-get -y install build-essential
+    fi
+
+    if [[ $FAI_ROOT == / ]]; then
+      cd /a/opt/btrfs-progs-release
+      make install
+    else
+      mkdir -p $target/tmp/bprogs
+      mount -o bind $bp_dir $target/tmp/bprogs
+      $ROOTCMD bash -xe <<EOF
+cd /tmp/bprogs
+make install
+EOF
+    fi
+  fi
+fi
+## end get new kernel and btrfs-progs ##