#!/bin/sh

[ -f /proc/mdstat ] || exit 0

WITHOUT_RC_COMPAT=1
. /etc/init.d/functions

if [ -f /etc/mdadm.conf ] && absolute mdadm >/dev/null 2>&1; then
	raidstop='mdadm --stop'
elif [ -f /etc/raidtab ] && absolute raidstop >/dev/null 2>&1; then
	raidstop=raidstop
else
	exit 1
fi

mdlist="$(sed -ne 's/^\(md[^[:space:]]*\).*/\1/p' /proc/mdstat)"
[ -n "$mdlist" ] || exit 0

rootdev="$(mount 2>/dev/null |awk '$2=="on" && $3=="/" {print $1}')"
rootdev="${rootdev#/dev/}"

for mddev in ${mdlist}; do
	[ "$mddev" != "$rootdev" ] || continue
	action "Turning off RAID for $mddev:" $raidstop "/dev/$mddev"
done
