#!/bin/bash

dracut_install mdadm partx


# XXX: mdmon really needs to run as non-root?
#      If so, write only the user it needs in the initrd's /etc/passwd (and maybe /etc/group)
#      in a similar fashion to modules.d/95nfs.  Do not copy /etc/passwd and /etc/group from 
#      the system into the initrd.
#      dledford has hardware to test this, so he should be able to clean this up.
# inst /etc/passwd
# inst /etc/group

if [ ! -x /lib/udev/vol_id ]; then
    inst_rules 64-md-raid.rules
fi

inst_rules "$moddir/65-md-incremental-imsm.rules"

if ! mdadm -Q -e imsm /dev/null &> /dev/null; then    
    inst_hook pre-trigger 30 "$moddir/md-noimsm.sh"
fi

if [[ $hostonly ]]; then 
    [ -f /etc/mdadm/mdadm.conf ] && inst /etc/mdadm/mdadm.conf /etc/mdadm.conf
    [ -f /etc/mdadm.conf ] && inst /etc/mdadm.conf
fi

if [ -x  /sbin/mdmon ] ; then
    dracut_install mdmon
    inst_hook pre-pivot 30 "$moddir/mdmon-pre-pivot.sh"
fi 

inst "$moddir/mdraid_start.sh" /sbin/mdraid_start
inst_hook pre-trigger 30 "$moddir/parse-md.sh"
inst_hook pre-pivot 30 "$moddir/mdraid-cleanup.sh"
inst_hook pre-pivot 60 "$moddir/mdraid-cleanup.sh"