#!/bin/sh
CF=/target/etc/mdadm/mdadm.conf
if [ ! -s "$CF" ] && [ -e /proc/mdstat ] && \
   grep ^md /proc/mdstat >/dev/null; then
	mkdir -p ${CF%/*}
	echo "# Autogenerated by partman-md. See mdadm.conf(5) for more details on this file." > $CF
	echo "DEVICE partitions" >> $CF
	if [ "$(udpkg --print-os)" = "kfreebsd" ]; then
		mount -t linprocfs proc /target/proc
	else
		mount -t proc proc /target/proc
	fi
	chroot /target mdadm --detail --scan >> $CF
	umount /target/proc
fi
