ip config changes, do kernel upgrades
[automated-distro-installer] / fai / config / scripts / IANK / 11-iank
index e77eb8f8ca3081bd7f5ce0902c90d976f69c7d2d..1aa974057798a449b7ae9c08c85fffeb0b645c70 100755 (executable)
@@ -19,7 +19,13 @@ if [[ -e /a/bin/fai/fai-wrapper ]]; then
   }
 fi
 
-
+if [[ $FAI_ROOT == / ]]; then
+  source /a/bin/bash_unpublished/source-state
+  bprogs_dir=/a/opt/btrfs-progs-release
+else
+  bprogs_dir=/srv/btrfs-progs-release
+  chroot="chroot $FAI_ROOT"
+fi
 
 # -r = recursive
 # -i = ignore non-matching class warnings, always exit 0
@@ -28,6 +34,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
@@ -51,13 +59,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 ||:
+$chroot /usr/bin/apt-cache policy >$tmpfile1 ||:
 fcopy -riB /etc/apt
 
 tmpfile2=$(mktemp)
-chroot $FAI_ROOT /usr/bin/apt-cache policy >$tmpfile2
+$chroot /usr/bin/apt-cache policy >$tmpfile2
 if ! diff -q $tmpfile1 $tmpfile2; then
-  chroot $FAI_ROOT /usr/bin/apt update
+  $chroot /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)
@@ -107,12 +115,12 @@ TimeoutStartSec=20
 WantedBy=dev-disk-by\x2did-ata\x2dSamsung_SSD_870_QVO_8TB_S5VUNG0N900656V.device
 EOF
 
-        chroot $FAI_ROOT bash <<'EOFOUTER'
+        $chroot 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
@@ -157,7 +165,7 @@ fi
 
 # use networkmanager if this host has wireless.
 if [[ $HOSTNAME == bo ]] || type -p iw &>/dev/null && [[ $(iw dev) ]]; then
-  chroot $FAI_ROOT bash <<EOF
+  $chroot bash <<EOF
 apt-get -y install network-manager
 EOF
 
@@ -174,18 +182,6 @@ 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
-  fi
-
 else
   cat > $target/etc/network/interfaces <<-EOF
 # generated by FAI
@@ -212,6 +208,72 @@ EOF
 
 fi
 
+# for new btrfs features, get latest stable kernel and btrfs progs,
+# update ver= as needed.
+case $HOSTNAME in
+  sy)
+    mkdir -p $FAI_ROOT/tmp/kernel-debs
+    files=($FAI_ROOT/tmp/kernel-debs/*)
+    if (( ${#files[@]} >= 1 )); then
+      rm -rf "${files[@]}"
+    fi
+    cd $FAI_ROOT/tmp/kernel-debs
+    ver='6\.6'
+    va=$(curl -s https://kernel.ubuntu.com/mainline/ | \
+           sed -rn 's,.*alt="\[DIR\]".*href="([^/]+).*,\1,p' | \
+           grep -v -- -rc | sed 's/^v//' | grep "^$ver" | sort -V | tail -n1)
+
+    # note the wiki page about these says to install linux-headers.*generic.*amd64, but
+    # as of 2024, they have a requirement of a very new glibc, and people report
+    # that installing it is not needed.
+    pkgs=$(curl -s https://kernel.ubuntu.com/mainline/v$va/amd64/CHECKSUMS | awk '$2 ~ /^linux-/ { print $2 }' | sort -u | grep -iv 'linux-headers.*generic.*amd64' )
+
+    urls=()
+    for p in $pkgs; do
+      if ! dpkg -s -- "${p%%_*}"  2>&1 | grep -Fx "Status: install ok installed" &>/dev/null; then
+        urls+=(https://kernel.ubuntu.com/mainline/v$va/amd64/$p)
+      fi
+    done
+    if (( ${#urls[@]} >= 1 )); then
+      wget "${urls[@]}"
+      $chroot bash <<EOF
+cd /tmp/kernel-debs
+dpkg -i *.deb
+EOF
+    fi
+    ;;
+  *)
+    $chroot 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${ver}.*gz\$" | sort -V | tail -n1)
+url="$pre/$tarball"
+dir=${tarball%.tar.gz}
+ver=${dir#btrfs-progs}
+cur_ver=$(btrfs --version 2>/dev/null | awk '{print $2}') ||:
+if [[ $ver != "$cur_ver" ]]; then
+  if [[ $HOST2 == $HOSTNAME && $ver != "$($bprogs_dir/btrfs --version 2>/dev/null | awk '{print $2}')" ]]; then
+    rm -rf $bprogs_dir
+    cd /tmp
+    wget $url
+    sudo -u iank tar xzf $tarball
+    mv ${tarball%.tar.gz} $bprogs_dir
+    cd $bprogs_dir
+    apt-get -y build-dep btrfs-progs
+    sudo -u iank ./configure --disable-documentation
+    sudo -u iank make
+    make install
+  else
+    $chroot bash -xe <<EOF
+cd $bprogs_dir
+make install
+EOF
+  fi
+fi
+
 if ifclass LINODE; then
   mkdir -p $target/etc/initramfs-tools/conf.d
   cat >$target/etc/initramfs-tools/conf.d/mine <<EOF
@@ -252,7 +314,7 @@ fi
 
 if ifclass VOL_BULLSEYE_BOOTSTRAP; then
   fcopy /etc/systemd/system/faicheck.service
-  chroot $FAI_ROOT bash <<'EOFOUTER'
+  $chroot bash <<'EOFOUTER'
 systemctl enable faicheck.service
 EOFOUTER
   exit 0 # avoid unnecessary stuff in bootstrap vol
@@ -260,7 +322,7 @@ fi
 
 
 ## misc settings
-chroot $FAI_ROOT bash <<'EOFOUTER'
+$chroot bash <<'EOFOUTER'
 #### begin .ssh setup ###
 set -x
 set -eE -o pipefail
@@ -285,7 +347,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