#!/bin/sh -efu
# ***** BEGIN LICENSE BLOCK *****
# * Copyright (C) 2007  Alexey Gladkov <legion@altlinux.org>
# * Copyright (C) 2008  Michael Shigorin <mike@altlinux.org>
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
# ***** END LICENSE BLOCK *****

. install2-init-functions

# software raid (Kb/s)
sync_speed_min=10000
sync_speed_max=500000

fstab="$destdir/etc/fstab"

[ -s "$fstab" ] || exit 0

# look into the root (or for)
rootdev="`awk '/[[:space:]]\/[[:space:]]/ { print $1; }' "$fstab"`"

# resolve further if not a device yet
case "$rootdev" in
UUID=*|LABEL=*)
	rootdev="`blkid -l -t "$rootdev" | cut -f1 -d:`";;
esac

# shouldn't happen -- log it then?
[ -n "$rootdev" ] || exit 0

# get root raid sync speed up, if applicable
rootmdknobs="/sys/block/${rootdev#/dev/}/md/"
[ ! -d "$rootmdknobs" ] || {
	echo "$sync_speed_min" > "$rootmdknobs/sync_speed_min"
	echo "$sync_speed_max" > "$rootmdknobs/sync_speed_max"
}
