summaryrefslogtreecommitdiff
path: root/etc/rc.d/raidframe
blob: 94bc62621dae2eae6131720401e691e7206bc2a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#
# $NetBSD: raidframe,v 1.12 2022/07/21 07:49:36 kre Exp $
#

# PROVIDE: raidframe
# REQUIRE: devpubd
# BEFORE:  DISKS

$_rc_subr_loaded . /etc/rc.subr

name=raidframe
rcvar=$name
start_cmd=raidframe_start
stop_cmd=:

raidframe_start()
{
	# Configure non-auto-configured raid devices.
	# Ensure order by globbing raid[0-9] before raid[1-9][0-9].
	# Assume no mixing of /etc/conf/raid/* and /etc/raid*.conf styles

	devices=$(sysctl -n hw.disknames)
	for cfg in 					\
		/etc/conf/raid/raid[0-9]		\
		/etc/conf/raid/raid[1-9][0-9]		\
		/etc/conf/raid/raid[1-9][0-9][0-9]	\
		/etc/raid[0-9].conf			\
		/etc/raid[1-9][0-9].conf		\
	; do
		[ -f "$cfg" ] && [ -s "$cfg" ] || continue

		dev=${cfg##*/}
		dev=${dev%.conf}

		# This test should never fail with the possible
		# config file patterns included, but for safety
		case "${dev}" in
		raid[0-9]|raid[1-9][0-9]|raid[1-9][0-9][0-9])	;;
		*)	: "$dev not raidNN"; continue;;
		esac

		case " ${devices} " in
		*" ${dev} "*)	: "$dev configured already"; continue;;
		esac

		raidctl -c "$cfg" "$dev" &&
			devices="${devices} ${dev}"
	done
}

load_rc_config $name
run_rc_command "$1"