kernel:
  #image: nemunaire/kernel:5.10.62-0b705d955f5e283f62583c4e227d64a7924c138f-amd64
  image: linuxkit/kernel:6.6.13
  cmdline: "console=ttyS0 console=tty0"


init:
  - nemunaire/mdadm:04814350d71ba9417e1f861be1685de26adf7a67
  - linuxkit/metadata:f35b5aafc7d19bb6a44a900840727902dad78e44
  - alpine:latest


files:
  - path: /init
    contents: |
      #!/bin/sh -x
      modprobe xhci_pci
      modprobe ahci
      modprobe megaraid_sas
      modprobe e1000e
      modprobe tg3
      modprobe bnxt_en

      echo -n "Waiting module loading... "
      sleep 3
      echo

      mount -t devtmpfs none /dev
      mount -t proc none /proc
      mount -t sysfs none /sys

      mdev -s

       if [ -b /dev/sdb ]; then
          mdadm --auto-detect
          mdadm --assemble /dev/md2 /dev/sd*1
          BOOT_PART=/dev/md2
          META_PART=/dev/md3
      else
          BOOT_PART=/dev/sda1
          META_PART=/dev/sda2
      fi

      ip link set eth0 up
      udhcpc -i eth0

      mkdir -p /boot

      GW=$(ip r | grep default | awk '{ print $3 }')

      # Wait e1000e launched
      if ! ping -W 2 -c 1 "${GW}"
      then
         sleep 4
      fi

      while ! ping -W 10 -c 1 "${GW}"
      do
        echo "Unable to contact ${GW}"
        echo "Exit the shell when connection established."
        /bin/ash
      done

      mount "${BOOT_PART}" /boot/ &&
        /root/update_imgs "${GW}" "${META_PART}" ||
        /bin/ash

      umount /boot &&
        sync &&
        reboot -f

      /bin/ash
    mode: "0755"

  - path: root/update_imgs
    source: configs/update_imgs.sh
    mode: "0755"