summaryrefslogtreecommitdiff
blob: 43731b48e0cae61f30073b3c82fb8105f284ae6d (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
#!/bin/sh

test -x /usr/bin/cciss_vol_status || exit 0

# WARNING: For the hpsa driver, we only support /dev/sda through
# /dev/sdz and /dev/sg0 through /dev/sg9.
DEVICES=$(find /dev -type b \( -path '/dev/cciss/c*d0' \
                               -or \
                               -path '/dev/sd[a-z]' \
                               -or \
                               -path '/dev/sg[0-9]' \))

if [ -n "${DEVICES}" ]; then
    #
    # Unsupported devices will generate an error (to stderr) of the form,
    #
    #   cciss_vol_status: /dev/sda: Unknown SCSI device.
    #
    # We want to ignore these, and fortunately, an exit code of zero
    # is returned in this case. So we need only hide the output by
    # redirecting stderr elsewhere. But, that also hides errors of the
    # form,
    #
    #   cciss_vol_status: open /dev/sda: Permission denied
    #
    # which we DO want to present to the user. So instead of sending
    # stderr to stdout, we redirect it to a temporary file. We then
    # show the content of the temporary file to the user if it
    # contains errors other than "Unknown SCSI device."
    #
    TMPFILE=$( mktemp )
    if [ $? -ne 0 ] || [ ! -f "${TMPFILE}" ];  then
	echo "${0}: error creating temporary file." >&2
	exit 2
    fi

    OUTPUT=$( /usr/bin/cciss_vol_status ${DEVICES} 2> "${TMPFILE}" )
    if [ $? -ne 0 ];  then
	printf "%s\n" "$OUTPUT"
	rm -f "${TMPFILE}"
	exit 1
    fi

    ERRORS=$( GREP_OPTIONS="" grep -v "Unknown SCSI device" "${TMPFILE}" )
    rm -f "${TMPFILE}"
    if [ -n "${ERRORS}" ]; then
	echo "${ERRORS}" >&2
	exit 3
    fi
fi

exit 0