fixes and remove some jessie stuff
[automated-distro-installer] / fai / config / files / root / fai-check / VOL_BUSTER_BOOTSTRAP
index e96879ac8176da15f7bdf4bd3660c5ccca489759..283bbf66610efff9f2fc3cf4e11875d4cf48a3a0 100755 (executable)
@@ -6,7 +6,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 
 usage() {
-    cat <<EOF
+  cat <<EOF
 Usage: ${0##*/} [OPTION]
 If grub var set, act like pxe rom and pxe-kexec to faiserver
 
@@ -15,7 +15,7 @@ If grub var set, act like pxe rom and pxe-kexec to faiserver
 
 Note: Uses GNU getopt options parsing style
 EOF
-    exit $1
+  exit $1
 }
 
 
@@ -29,59 +29,59 @@ did_fai_check=false
 m() { printf "%s\n" "$*";  "$@"; }
 
 try-kexec() {
-    deadline=$(( `date +%s` + NETWORK_TIMOUT_SECS ))
-    while ! nc -zu faiserver 69; do
-        if (( `date +%s` > deadline )); then
-            echo "fai-check: hit $NETWORK_TIMOUT_SECS s tftp server timeout"
-            return 0
-        fi
-        sleep 1
-    done
-    m pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||:
+  deadline=$(( `date +%s` + NETWORK_TIMOUT_SECS ))
+  while ! timeout -s 9 3 nc -zu faiserver 69; do
+    if (( `date +%s` > deadline )); then
+      echo "fai-check: hit $NETWORK_TIMOUT_SECS s tftp server timeout"
+      return 0
+    fi
+    sleep 1
+  done
+  m pxe-kexec -n --ignore-whitelist -l fai-generated faiserver ||:
 }
 
 case $1 in
-    -f|--force)
-        try-kexec
-        exit
-        ;;
+  -f|--force)
+    try-kexec
+    exit
+    ;;
 esac
 
 first=true
 for dev in $(btrfs fi show / | sed -rn 's#^\s*devid\s.*\s([^0-9 ]+)\S+$#\1#p' \
-                 |sort); do
-    dev+=4
-    mount $dev /mnt
-    if $first; then
-        if [[ -e /mnt/grubenv ]]; then
-            set -x
-            source <(grub-editenv /mnt/grubenv list)
-            set +x
-        fi
-        first=false
-        # we could just as well check if last_boot != /debianbuster_boostrap
-        # the intent with this one is just a little clearer.
-        if [[ $did_fai_check == true ]]; then
-            grub-editenv /mnt/grubenv set did_fai_check=os_true
-            # our service does not wait for network-online.target,
-            # because it will wait for too long when we don't have a network
-            # connection. So, we wait for 10 seconds.
-            # ref: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
-            try-kexec ||:
-        fi
-    else
-        # we make sure there is only 1 grubenv,
-        # so grub can just find the first one, in whatever order
-        # if looks at them, which may not be the same as us.
-        # If the disk dies, we just lose the default boot option,
-        # we will have to do manual steps to replace it anyways.
-        rm -f /mnt/gruvenv
+               |sort); do
+  dev+=4
+  mount $dev /mnt
+  if $first; then
+    if [[ -e /mnt/grubenv ]]; then
+      set -x
+      source <(grub-editenv /mnt/grubenv list)
+      set +x
+    fi
+    first=false
+    # we could just as well check if last_boot != /debianbuster_boostrap
+    # the intent with this one is just a little clearer.
+    if [[ $did_fai_check == true ]]; then
+      grub-editenv /mnt/grubenv set did_fai_check=os_true
+      # our service does not wait for network-online.target,
+      # because it will wait for too long when we don't have a network
+      # connection. So, we wait for 10 seconds.
+      # ref: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
+      try-kexec ||:
     fi
-    umount /mnt
+  else
+    # we make sure there is only 1 grubenv,
+    # so grub can just find the first one, in whatever order
+    # if looks at them, which may not be the same as us.
+    # If the disk dies, we just lose the default boot option,
+    # we will have to do manual steps to replace it anyways.
+    rm -f /mnt/gruvenv
+  fi
+  umount /mnt
 done
 
 # the check for last_boot is not needed afaik, just sanity check.
-if [[ $did_fai_check == true && $last_boot != /debianstable_boostrap ]]; then
-    # no need to reboot if we actually want to boot into this os.
-    reboot
+if [[ $did_fai_check == true && $last_boot != /debianbuster_boostrap ]]; then
+  # no need to reboot if we actually want to boot into this os.
+  reboot
 fi