Determine the right TYPE between scanned and auto
This commit is contained in:
parent
3b016ae797
commit
fb1094308d
|
@ -3,7 +3,7 @@
|
||||||
# NOTE: Must be run as root, so you probably need to setup sudo for this.
|
# NOTE: Must be run as root, so you probably need to setup sudo for this.
|
||||||
|
|
||||||
# Vars {{{
|
# Vars {{{
|
||||||
debug="1"
|
debug="0"
|
||||||
|
|
||||||
## Colors {{{
|
## Colors {{{
|
||||||
c_redb='\033[1;31m'
|
c_redb='\033[1;31m'
|
||||||
|
@ -29,9 +29,11 @@ is_disk_support_smart() {
|
||||||
|
|
||||||
if test -f "${_smarctl_support_result}"; then rm -f "${_smarctl_support_result}"; fi
|
if test -f "${_smarctl_support_result}"; then rm -f "${_smarctl_support_result}"; fi
|
||||||
|
|
||||||
## Get only "support" lines from disk's informations
|
## Grep only "support" lines from disk's informations
|
||||||
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
||||||
|
|
||||||
|
## TODO: Test if grep successfully got something
|
||||||
|
|
||||||
## Parse all "support" lines
|
## Parse all "support" lines
|
||||||
while IFS= read -r _LINE; do
|
while IFS= read -r _LINE; do
|
||||||
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
||||||
|
@ -49,6 +51,31 @@ is_disk_support_smart() {
|
||||||
rm -f -- "${_smarctl_support_result}"
|
rm -f -- "${_smarctl_support_result}"
|
||||||
}
|
}
|
||||||
## }}}
|
## }}}
|
||||||
|
## Test the type of disk with smartctl {{{
|
||||||
|
choose_correct_type() {
|
||||||
|
_disk="${1}"
|
||||||
|
_scanned_type="${2}"
|
||||||
|
_default_type="auto"
|
||||||
|
|
||||||
|
TYPE=""
|
||||||
|
SMART_SUPPORT_MSG=""
|
||||||
|
|
||||||
|
for test_type in "${_default_type}" "${_scanned_type}"; do
|
||||||
|
is_disk_support_smart "${_disk}" "${test_type}"
|
||||||
|
|
||||||
|
## If no message, the type is correct
|
||||||
|
if [ -z "${smart_support_msg}" ]; then
|
||||||
|
TYPE="${test_type}"
|
||||||
|
SMART_SUPPORT_MSG=""
|
||||||
|
return
|
||||||
|
else
|
||||||
|
SMART_SUPPORT_MSG="${smart_support_msg}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
## }}}
|
||||||
|
|
||||||
if test -f /tmp/dres; then rm -f /tmp/dres; fi
|
if test -f /tmp/dres; then rm -f /tmp/dres; fi
|
||||||
if test -f /tmp/dscan; then rm -f /tmp/dscan; fi
|
if test -f /tmp/dscan; then rm -f /tmp/dscan; fi
|
||||||
|
@ -56,23 +83,25 @@ if test -f /tmp/dscan; then rm -f /tmp/dscan; fi
|
||||||
# Get the list of all available devices
|
# Get the list of all available devices
|
||||||
smartctl --scan > /tmp/dscan
|
smartctl --scan > /tmp/dscan
|
||||||
|
|
||||||
|
# TODO: Test if the file is not empty
|
||||||
|
|
||||||
while IFS= read -r LINE; do
|
while IFS= read -r LINE; do
|
||||||
## Get device and type
|
## Get device path
|
||||||
DISK=$(echo "${LINE}" | cut -d" " -f1)
|
DISK=$(echo "${LINE}" | cut -d" " -f1)
|
||||||
TYPE=$(echo "${LINE}" | cut -d" " -f3)
|
## Try to determine the best type
|
||||||
|
SCANNED_TYPE=$(echo "${LINE}" | cut -d" " -f3)
|
||||||
|
choose_correct_type "${DISK}" "${SCANNED_TYPE}"
|
||||||
|
|
||||||
is_disk_support_smart "${DISK}" "${TYPE}"
|
## If no correct type was found for this device
|
||||||
|
if [ -z "${TYPE}" ]; then
|
||||||
## If SMART is supported on the disk
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART is not fully supported."
|
||||||
if [ -z "${smart_support_msg}" ]; then
|
DRES=$(printf '%s' "${SMART_SUPPORT_MSG}")
|
||||||
|
DCODE="2"
|
||||||
|
else
|
||||||
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART seems fully supported, proceed normally."
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART seems fully supported, proceed normally."
|
||||||
### Get SMART Health Status and return code
|
### Get SMART Health Status and return code
|
||||||
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
|
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
|
||||||
DCODE=$?
|
DCODE=$?
|
||||||
else
|
|
||||||
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART is not fully supported, get ."
|
|
||||||
DRES=$(printf '%s' "${smart_support_msg}")
|
|
||||||
DCODE="2"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DSTBY=$(( DCODE & 2 ))
|
DSTBY=$(( DCODE & 2 ))
|
||||||
|
|
Loading…
Reference in New Issue