Browse Source

Update syno_hdd_db.sh

Added SAS drive support
pull/15/head
007revad 3 years ago
committed by GitHub
parent
commit
b775298c39
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 132
      syno_hdd_db.sh

132
syno_hdd_db.sh

@ -46,7 +46,7 @@
# Optionally disable "support_disk_compatibility". # Optionally disable "support_disk_compatibility".
scriptver="1.1.8" scriptver="1.1.9"
# Check latest release with GitHub API # Check latest release with GitHub API
get_latest_release() { get_latest_release() {
@ -111,32 +111,96 @@ fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Get list of installed HDDs and SATA SSDs # Get list of installed SATA, SAS and NVMe drives
# SATA drives, sata1, sata2 etc getModel() {
for drive in /dev/sata*; do hdmodel=$(smartctl -i "$1" | grep -i "Device Model:" | awk '{print $3 $4 $5}')
if [[ $drive =~ /dev/sata[1-9][0-9]?[0-9]?$ ]]; then if [[ ! $hdmodel ]]; then
tmp=$(hdparm -i "$drive" | grep Model) hdmodel=$(smartctl -i "$1" | grep -i "Product:" | awk '{print $2 $3 $4}')
hdmodel=$(printf %s "$tmp" | cut -d"," -f 1 | cut -d"=" -f 2) fi
#echo "Model: $hdmodel" # debug
# Brands that return "BRAND <model>" and need "BRAND " removed.
hdmodel=${hdmodel#"WDC "} # Remove "WDC " from start of model name
hdmodel=${hdmodel#"HGST "} # Remove "HGST " from start of model name
hdmodel=${hdmodel#"TOSHIBA "} # Remove "TOSHIBA " from start of model name
# Old drive brands
hdmodel=${hdmodel#"Hitachi "} # Remove "Hitachi " from start of model name
hdmodel=${hdmodel#"SAMSUNG "} # Remove "SAMSUNG " from start of model name
hdmodel=${hdmodel#"FUJISTU "} # Remove "FUJISTU " from start of model name
hdmodel=${hdmodel#"APPLE HDD "} # Remove "APPLE HDD " from start of model name
shopt -s extglob
hdmodel=${hdmodel/#*([[:space:]])} # Remove leading spaces
hdmodel=${hdmodel/%*([[:space:]])} # Remove trailing spaces
shopt -u extglob
#echo "Model: $hdmodel" # debug
}
getFwVersion() {
tmp=$(hdparm -i "$1" | grep Model)
fwrev=$(printf %s "$tmp" | cut -d"," -f 2 | cut -d"=" -f 2) fwrev=$(printf %s "$tmp" | cut -d"," -f 2 | cut -d"=" -f 2)
#echo "Firmware: $fwrev" # debug
}
getNVMeModel() {
nvmemodel=$(cat $1/model)
shopt -s extglob
nvmemodel=${nvmemodel/#*([[:space:]])} # Remove leading spaces
nvmemodel=${nvmemodel/%*([[:space:]])} # Remove trailing spaces
shopt -u extglob
#echo "NVMe Model: $nvmemodel" # debug
}
getNVMeFwVersion() {
nvmefw=$(cat $1/firmware_rev)
nvmefw=$(echo "$nvmefw" | xargs) # trim leading and trailing white space
#echo "NVMe Firmware: $nvmefw" # debug
}
for d in `cat /proc/partitions | awk '{print $4}'`; do
if [ ! -e /dev/$d ]; then
continue;
fi
#echo $d # debug
case "$d" in
hd*|sd*)
if [[ $d =~ [hs]d[a-z]{1,2}$ ]]; then
echo -e "\n$d" # debug
getModel "/dev/$d"
getFwVersion "/dev/$d"
if [[ $hdmodel ]] && [[ $fwrev ]]; then if [[ $hdmodel ]] && [[ $fwrev ]]; then
hdparm+=("${hdmodel},${fwrev}") hdparm+=("${hdmodel},${fwrev}")
fi fi
fi fi
done ;;
sas*|sata*)
# SATA drives sda, sdb etc if [[ $d =~ (sas|sata)[0-9][0-9]?[0-9]?$ ]]; then
for drive in /dev/sd*; do echo -e "\n$d" # debug
if [[ $drive =~ /dev/sd[a-z]{1,2}$ ]]; then getModel "/dev/$d"
tmp=$(hdparm -i "$drive" | grep Model) getFwVersion "/dev/$d"
hdmodel=$(printf %s "$tmp" | cut -d"," -f 1 | cut -d"=" -f 2)
fwrev=$(printf %s "$tmp" | cut -d"," -f 2 | cut -d"=" -f 2)
if [[ $hdmodel ]] && [[ $fwrev ]]; then if [[ $hdmodel ]] && [[ $fwrev ]]; then
hdparm+=("${hdmodel},${fwrev}") hdparm+=("${hdmodel},${fwrev}")
fi fi
fi fi
;;
nvme*)
if [[ $d =~ nvme[0-9][0-9]?n[0-9][0-9]?$ ]]; then
echo -e "\n$d" # debug
n=n$(printf "$d" | cut -d "n" -f 2)
getNVMeModel "/sys/class/nvme/$n"
getNVMeFwVersion "/sys/class/nvme/$n"
if [[ $nvmemodel ]] && [[ $nvmefw ]]; then
nvmelist+=("${nvmemodel},${nvmefw}")
fi
fi
;;
esac
done done
# Sort hdparm array into new hdds array to remove duplicates # Sort hdparm array into new hdds array to remove duplicates
if [[ ${#hdparm[@]} -gt "0" ]]; then if [[ ${#hdparm[@]} -gt "0" ]]; then
while IFS= read -r -d '' x; do while IFS= read -r -d '' x; do
@ -158,42 +222,17 @@ else
fi fi
#------------------------------------------------------------------------------ # Sort nvmelist array into new nvmes array to remove duplicates
# Get list of installed NVMe drives if [[ ${#nvmelist[@]} -gt "0" ]]; then
express=$(cat /proc/devices | grep nvme)
if [[ $express ]]; then
for path in /sys/class/nvme/*; do
nvmemodel=$(cat "$path"/model)
shopt -s extglob
nvmemodel=${nvmemodel/#*([[:space:]])} # Remove leading spaces
#echo "$nvmemodel" " Without leading spaces" # debug
nvmemodel=${nvmemodel/%*([[:space:]])} # Remove trailing spaces
#echo "$nvmemodel" " Without trailing spaces" # debug
shopt -u extglob
#if [[ $nvmemodel ]]; then echo "NVMe model: ${nvmemodel}"; fi # debug
nvmefw=$(cat "$path"/firmware_rev)
nvmefw=$(echo "$nvmefw" | xargs) # trim leading and trailing white space
#if [[ $nvmefw ]]; then echo "NVMe firmware: ${nvmefw}"; fi # debug
if [[ $nvmemodel ]] && [[ $nvmefw ]]; then
nvmelist+=("${nvmemodel},${nvmefw}")
fi
done
# Sort nvmelist array into new nvmes array to remove duplicates
if [[ ${#nvmelist[@]} -gt "0" ]]; then
while IFS= read -r -d '' x; do while IFS= read -r -d '' x; do
nvmes+=("$x") nvmes+=("$x")
done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz) done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz)
fi fi
# Check hdds array isn't empty # Check nvmes array isn't empty
if [[ ${#nvmes[@]} -eq "0" ]]; then if [[ ${#nvmes[@]} -eq "0" ]]; then
echo -e "No NVMe drives found\n" echo -e "No NVMe drives found\n"
else else
echo "NVMe drive models found: ${#nvmes[@]}" echo "NVMe drive models found: ${#nvmes[@]}"
num="0" num="0"
while [[ $num -lt "${#nvmes[@]}" ]]; do while [[ $num -lt "${#nvmes[@]}" ]]; do
@ -201,7 +240,6 @@ if [[ $express ]]; then
num=$((num +1)) num=$((num +1))
done done
echo echo
fi
fi fi

Loading…
Cancel
Save