#!/bin/bash

# Add md0 uuid to kernel command line arguments.
# https://bugzilla.redhat.com/show_bug.cgi?id=1084766

GRUB_CONF=/boot/grub2/grub.cfg

if grep -q "rd\.md\.uuid=" $GRUB_CONF; then
  echo "Your system looks to be already configured. Exiting."
else
  ROOT_MD="`df / | grep /dev/md | cut -d' ' -f1`"
  if [ "$ROOT_MD" ]; then
    export `mdadm --detail $ROOT_MD --export`
    sed -i~ "s|^\(\s*linux\s.*\)$|\1 rd.md.uuid=$MD_UUID|" $GRUB_CONF
  else
    echo "No md device found."
  fi
fi
