mostly fixes and host updates
[automated-distro-installer] / fai / config / scripts / IANK / 11-iank
index 43fc13bcf5ff83db61307ac733f38278f6019573..0b8d6c5576caba9763234f1de2bbca79f9a0e41a 100755 (executable)
@@ -19,7 +19,10 @@ if [[ -e /a/bin/fai/fai-wrapper ]]; then
   }
 fi
 
-
+if [[ $FAI_ROOT != / ]]; then
+  bprogs_pre=/srv
+  chroot="chroot $FAI_ROOT"
+fi
 
 # -r = recursive
 # -i = ignore non-matching class warnings, always exit 0
@@ -53,13 +56,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)
@@ -109,7 +112,7 @@ 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
@@ -159,7 +162,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
 
@@ -212,26 +215,25 @@ case $HOSTNAME in
     vb=$va-060403
     vc=${vb}.202307110536
     pre="https://kernel.ubuntu.com/~kernel-ppa/mainline/v$va/amd64/linux-"
-    urls=(
-      ${pre}headers-${vb}_${vc}_all.deb
-      ${pre}{headers,image-unsigned,modules}-${vb}-generic_${vc}_amd64.deb
-    )
-    wget "${urls[@]}"
-    chroot $FAI_ROOT make install
-
-    chroot $FAI_ROOT bash <<EOF
+    if ! dpkg -s -- linux-headers-${vb}  2>&1 | grep -Fx "Status: install ok installed" &>/dev/null; then
+      urls=(
+        ${pre}headers-${vb}_${vc}_all.deb
+        ${pre}{headers,image-unsigned,modules}-${vb}-generic_${vc}_amd64.deb
+      )
+      wget "${urls[@]}"
+      $chroot bash <<EOF
 cd /tmp/kernel-debs
 dpkg -i *.deb
 EOF
-
+    fi
     ;;
   *)
-    chroot $FAI_ROOT apt-get install linux-libre
+    $chroot apt-get -y install linux-libre
     ;;
 esac
 
-cp -ra /srv/a/opt/btrfs-progs-release/btrfs-progs-v6.3.2 $FAI_ROOT/tmp/btrfs-progs
-chroot $FAI_ROOT bash <<EOF
+cp -ra $bprogs_pre/a/opt/btrfs-progs-release/btrfs-progs-v6.3.2 $FAI_ROOT/tmp/btrfs-progs
+$chroot bash <<EOF
 cd /tmp/btrfs-progs
 make install
 EOF
@@ -277,7 +279,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
@@ -285,7 +287,7 @@ fi
 
 
 ## misc settings
-chroot $FAI_ROOT bash <<'EOFOUTER'
+$chroot bash <<'EOFOUTER'
 #### begin .ssh setup ###
 set -x
 set -eE -o pipefail