From 7312b4c324a2bbb70a3ad7ac736ab52587f375d4 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:28:00 +1100 Subject: [PATCH 1/6] Update syno_hdd_db.sh v3.5.105 - Bug fix for drives that return "HCST " as the model, like HGST drives do. Issue #389 --- syno_hdd_db.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index e1af1ef..7264a9f 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -29,7 +29,7 @@ # /var/packages/StorageManager/target/ui/storage_panel.js -scriptver="v3.5.104" +scriptver="v3.5.105" script=Synology_HDD_db repo="007revad/Synology_HDD_db" scriptname=syno_hdd_db @@ -884,6 +884,9 @@ fixdrivemodel(){ hdmodel=${hdmodel#"HGST "} # Remove "HGST " from start of model name hdmodel=${hdmodel#"TOSHIBA "} # Remove "TOSHIBA " from start of model name + # Chinese brand? + hdmodel=${hdmodel#"HCST "} # Remove "HCST " from start of model name. Issue #389 + # Old drive brands hdmodel=${hdmodel#"Hitachi "} # Remove "Hitachi " from start of model name hdmodel=${hdmodel#"SAMSUNG "} # Remove "SAMSUNG " from start of model name @@ -932,7 +935,7 @@ getdriveinfo(){ # Get drive GB size size_gb=$(get_size_gb "$1") - if [ -n "$size_gb" ]; then + if [[ -n "$size_gb" ]]; then # PR #187 if [[ $hdmodel ]] && [[ $fwrev ]]; then if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then # Is SATA M.2 SSD From 1f88c519239904ee32d19cc10797d1cf70a320aa Mon Sep 17 00:00:00 2001 From: Curtis Doty Date: Sun, 15 Dec 2024 15:04:17 -0800 Subject: [PATCH 2/6] Normalize line endings --- syno_hdd_vendor_ids.txt | 49 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/syno_hdd_vendor_ids.txt b/syno_hdd_vendor_ids.txt index fe52af8..9bb8246 100644 --- a/syno_hdd_vendor_ids.txt +++ b/syno_hdd_vendor_ids.txt @@ -1,25 +1,24 @@ -# You can add your drive's vendor id and vendor name here. -# -# Only edit this file if the script warns you about a missing vendor id. - -0x025e="Solidigm" -0x05dc="Lexar" -0x0ed1="aigo" -0x10ec="TEAMGROUP" -0x137e="Patriot" -0x1458="Gigabyte" -0x1462="MSI" -0x196e="PNY" -0x1987="Phison" -0x1b1c="Corsair" -0x1bdc="Apacer" -0x1c5c="SK Hynix" -0x1cc4="UMIS" -0x1cfa="Corsair" -0x1d79="Transcend" -0x1dbe="ADATA" -0x1e0f="KIOXIA" -0x1e49="ZHITAI" -0x1e4b="FIKWOT" -0x1f40="Netac" - +# You can add your drive's vendor id and vendor name here. +# +# Only edit this file if the script warns you about a missing vendor id. + +0x025e="Solidigm" +0x05dc="Lexar" +0x0ed1="aigo" +0x10ec="TEAMGROUP" +0x137e="Patriot" +0x1458="Gigabyte" +0x1462="MSI" +0x196e="PNY" +0x1987="Phison" +0x1b1c="Corsair" +0x1bdc="Apacer" +0x1c5c="SK Hynix" +0x1cc4="UMIS" +0x1cfa="Corsair" +0x1d79="Transcend" +0x1dbe="ADATA" +0x1e0f="KIOXIA" +0x1e49="ZHITAI" +0x1e4b="FIKWOT" +0x1f40="Netac" From 46d3a2e6735493ea37620c80b46e40a5f5c20b00 Mon Sep 17 00:00:00 2001 From: Curtis Doty Date: Sun, 15 Dec 2024 15:05:00 -0800 Subject: [PATCH 3/6] Make executable --- syno_hdd_db.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 syno_hdd_db.sh diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh old mode 100644 new mode 100755 From f9944334661982e5328104b257ce7a31cfb50f10 Mon Sep 17 00:00:00 2001 From: Curtis Doty Date: Sun, 15 Dec 2024 15:16:54 -0800 Subject: [PATCH 4/6] Make debugger pretty --- syno_hdd_db.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 7264a9f..e68bb26 100755 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -197,9 +197,25 @@ else fi +PS4func() { + local lineno="$1" + local i f='' + local c="\033[0;36m" y="\033[0;33m" n="\033[0m" + local d=$((${#FUNCNAME[@]}-2)) + + if [[ $lineno == 1 ]] + then lineno=0 + fi + + for ((i=d; i>0; i--)) + do printf -v f "%s%s()" "$f" "${FUNCNAME[i]}" + done + + printf "$y%s:%04d$c%s$n " "${BASH_SOURCE[1]##*/}" "$lineno" "$f" +} if [[ $debug == "yes" ]]; then - set -x - export PS4='`[[ $? == 0 ]] || echo "\e[1;31;40m($?)\e[m\n "`:.$LINENO:' + PS4='\r$(PS4func $LINENO)' + set -o xtrace fi From 8e7f56b80faaa118c964709e9f3e440ca7959a6c Mon Sep 17 00:00:00 2001 From: Curtis Doty Date: Sun, 15 Dec 2024 16:46:18 -0800 Subject: [PATCH 5/6] De-spaghettifi shell code - reduce excesive subshells/piplines - improve readability - speed up performance - fixes #397 --- syno_hdd_db.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index e68bb26..a2716ed 100755 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -378,11 +378,24 @@ echo "Running from: ${scriptpath}/$scriptfile" # Warn if script located on M.2 drive -scriptvol=$(echo "$scriptpath" | cut -d"/" -f2) -vg=$(lvdisplay | grep /volume_"${scriptvol#volume}" | cut -d"/" -f3) -md=$(pvdisplay | grep -B 1 -E '[ ]'"$vg" | grep /dev/ | cut -d"/" -f3) -# shellcheck disable=SC2002 # Don't warn about "Useless cat" -if cat /proc/mdstat | grep "$md" | grep -q nvme; then +get_script_vol() { + local script_root vol_num vg_name + script_root="${scriptpath#/*}" + script_root="${script_root%%/*}" + if [[ $script_root =~ ^volume ]] + then + vol_num="${script_root:6}" + vg_name=$(lvs --noheadings --select=lv_name="volume_$vol_num" --options=vg_name) + vg_name="${vg_name// }" + vol_name=$(pvs --noheadings --select=vg_name="$vg_name" --options=pv_name) + vol_name="${vol_name// }" + else + vol_name=$(df --output=source "/$script_root" |sed 1d) + fi +} +get_script_vol # sets $vol_name to /dev/whatever +if grep -qE "^${vol_name#/dev/} .+ nvme" /proc/mdstat +then echo -e "\n${Yellow}WARNING${Off} Don't store this script on an NVMe volume!" fi From aa4aacd3af25b015a3ca0721b42ed5dd3fe99bf7 Mon Sep 17 00:00:00 2001 From: Curtis Doty Date: Sun, 15 Dec 2024 16:46:18 -0800 Subject: [PATCH 6/6] De-spaghettifi shell code - reduce excesive subshells/piplines - improve readability - speed up performance - fixes #397 --- syno_hdd_db.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 7264a9f..4e0139f 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -362,11 +362,24 @@ echo "Running from: ${scriptpath}/$scriptfile" # Warn if script located on M.2 drive -scriptvol=$(echo "$scriptpath" | cut -d"/" -f2) -vg=$(lvdisplay | grep /volume_"${scriptvol#volume}" | cut -d"/" -f3) -md=$(pvdisplay | grep -B 1 -E '[ ]'"$vg" | grep /dev/ | cut -d"/" -f3) -# shellcheck disable=SC2002 # Don't warn about "Useless cat" -if cat /proc/mdstat | grep "$md" | grep -q nvme; then +get_script_vol() { + local script_root vol_num vg_name + script_root="${scriptpath#/*}" + script_root="${script_root%%/*}" + if [[ $script_root =~ ^volume ]] + then + vol_num="${script_root:6}" + vg_name=$(lvs --noheadings --select=lv_name="volume_$vol_num" --options=vg_name) + vg_name="${vg_name// }" + vol_name=$(pvs --noheadings --select=vg_name="$vg_name" --options=pv_name) + vol_name="${vol_name// }" + else + vol_name=$(df --output=source "/$script_root" |sed 1d) + fi +} +get_script_vol # sets $vol_name to /dev/whatever +if grep -qE "^${vol_name#/dev/} .+ nvme" /proc/mdstat +then echo -e "\n${Yellow}WARNING${Off} Don't store this script on an NVMe volume!" fi