From 0728fae53c1306b074fb91b003820ecd2c3e4c9e Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Fri, 17 Mar 2023 19:24:46 +1100 Subject: [PATCH 01/18] Update CHANGES.txt Updated to v1.1.15 --- CHANGES.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 5c03984..20b5d3d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,12 @@ +v1.1.15 +- Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). +- Improved flags/options checking and added usage help. +- Can now download the latest script version for you (if you have user home service enabled in DSM). +- Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf + - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. +- Changed Synology model detection to be more reliable (for models that came in different variations). +- Changed checking drive_db_test_url setting to be more durable. + v1.1.14 - Minor bug fix. From e5ca4bb449befdd3cc842e3f4193314614de8817 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Fri, 17 Mar 2023 19:25:59 +1100 Subject: [PATCH 02/18] Update syno_hdd_db.sh v1.1.15 - Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). - Improved flags/options checking and added usage help. - Can now download the latest script version for you (if you have user home service enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. - Changed Synology model detection to be more reliable (for models that came in different variations). - Changed checking drive_db_test_url setting to be more durable. --- syno_hdd_db.sh | 547 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 384 insertions(+), 163 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 61d0052..a17b6b2 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -23,17 +23,32 @@ #-------------------------------------------------------------------------------------------------- # TODO +# Bypass M.2 volume lock for unsupported M.2 drives. +# # Detect if expansion unit(s) connected and get model(s) and edit expansion unit db files. # Or add support for specifying user's expansion unit model(s) as arguments. # Or maybe use the shotgun approach and update all expansion unit db files. # -# Add support for M.2 SATA and NVMe drives on a M2D17 PCI card. -# -# Maybe also edit the other disk compatibility DB in synoboot, used during boot time. +# Maybe also edit the other disk compatibility db in synoboot, used during boot time. # It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. # DONE -# Added check that M.2 volume support is enabled. +# Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). +# +# Improved flags/options checking and added usage help. +# +# Can now download the latest script version for you (if you have user home service enabled in DSM). +# +# Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf +# to (hopefully) prevent losing your SSH created M2 volume when running this script on models +# that DSM 7.2 Beta does not list as supported for creating M2 volumes. +# +# Changed Synology model detection to be more reliable (for models that came in different variations). +# +# Changed checking drive_db_test_url setting to be more durable. +# +# +# Added check that M.2 volume support is enabled (on supported models). # # Added support for M.2 SATA drives. # @@ -63,58 +78,100 @@ # Optionally disable "support_disk_compatibility". -scriptver="v1.1.14" +scriptver="v1.1.15" +script=Synology_HDD_db +repo="007revad/Synology_HDD_db" -# Check latest release with GitHub API -get_latest_release() { - curl --silent "https://api.github.com/repos/$1/releases/latest" | - grep '"tag_name":' | # Get tag line - sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value + +# Shell Colors +#Black='\e[0;30m' +Red='\e[0;31m' +#Green='\e[0;32m' +Yellow='\e[0;33m' +#Blue='\e[0;34m' +#Purple='\e[0;35m' +Cyan='\e[0;36m' +#White='\e[0;37m' +Error='\e[41m' +Off='\e[0m' + + +usage(){ + cat < /dev/null ; then - echo -e "\e[0;36mThere is a newer version of this script available.\e[0m" - echo -e "Current version: ${scriptver}\nLatest version: $tag" - echo "https://github.com/007revad/Synology_HDD_db/releases/latest" - echo "" - sleep 10 -fi +scriptversion(){ + cat < /dev/null ; then + echo -e "${Cyan}There is a newer version of this script available.${Off}" + echo -e "Current version: ${scriptver}\nLatest version: $tag" + if [[ ! -d $HOME ]]; then + # Can't download to home + echo "https://github.com/$repo/releases/latest" + sleep 10 + elif [[ -f $HOME/$script-$shorttag.tar.gz ]]; then + # Latest version tar.gz in home but they're using older version + echo "https://github.com/$repo/releases/latest" + sleep 10 + else + echo -e "${Cyan}Do you want to download $tag now?${Off} {y/n]" + read -r -t 30 reply + if [[ ${reply,,} == "y" ]]; then + if ! curl -LJO "https://github.com/$repo/archive/refs/tags/$tag.tar.gz"; then + echo -e "${Error}ERROR ${Off} Failed to download $script-$shorttag.tar.gz!" + else + if [[ -f $HOME/$script-$shorttag.tar.gz ]]; then + if ! tar -xf "$HOME/$script-$shorttag.tar.gz"; then + echo -e "${Error}ERROR ${Off} Failed to extract $script-$shorttag.tar.gz!" + else + if ! rm "$HOME/$script-$shorttag.tar.gz"; then + echo -e "${Error}ERROR ${Off} Failed to delete downloaded $script-$shorttag.tar.gz!" + else + echo -e "\n$tag and changes.txt are in ${Cyan}$shorthome/$script-$shorttag${Off}" + echo -e "${Cyan}Do you want to stop this script so you can run the new one?${Off} {y/n]" + read -r -t 30 reply + if [[ ${reply,,} == "y" ]]; then exit; fi + fi + fi + else + echo -e "${Error}ERROR ${Off} $shorthome/$script-$shorttag.tar.gz not found!" + #ls $HOME/ | grep "$script" # debug + fi + fi + fi + fi fi #------------------------------------------------------------------------------ # Get list of installed SATA, SAS and M.2 NVMe/SATA drives +getdriveinfo() { + # Get drive model and firmware version + hdmodel=$(cat "$1/device/model") + hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space + + fwrev=$(cat "$1/device/rev") + fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space + + if [[ $hdmodel ]] && [[ $fwrev ]]; then + hdlist+=("${hdmodel},${fwrev}") + fi +} + +getm2info() { + nvmemodel=$(cat "$1/device/model") + nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space + if [[ $2 == "nvme" ]]; then + nvmefw=$(cat "$1/device/firmware_rev") + elif [[ $2 == "nvc" ]]; then + nvmefw=$(cat "$1/device/rev") + fi + nvmefw=$(printf "%s" "$nvmefw" | xargs) # trim leading and trailing white space + + if [[ $nvmemodel ]] && [[ $nvmefw ]]; then + nvmelist+=("${nvmemodel},${nvmefw}") + fi +} + +getcardmodel() { + # Get M.2 card model + cardmodel=$(synodisk --m2-card-model-get "$1") + if [[ $cardmodel =~ M2D[0-9][0-9] ]]; then + # M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + elif [[ $cardmodel =~ E[0-9][0-9]+M.+ ]]; then + # Ethernet + M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + fi +} + + for d in /sys/block/*; do - #echo $d # debug case "$(basename -- "${d}")" in sd*|hd*) - if [[ $d =~ [hs]d[a-z]$ ]]; then - hdmodel=$(cat "$d/device/model") - hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space - #echo "Model: '$hdmodel'" # debug - - fwrev=$(cat "$d/device/rev") - fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space - #echo "Firmware: '$fwrev'" # debug - - if [[ $hdmodel ]] && [[ $fwrev ]]; then - hdlist+=("${hdmodel},${fwrev}") - fi + if [[ $d =~ [hs]d[a-z][a-z]?$ ]]; then + # Get drive model and firmware version + getdriveinfo "$d" fi ;; sata*|sas*) if [[ $d =~ (sas|sata)[0-9][0-9]?[0-9]?$ ]]; then - hdmodel=$(cat "$d/device/model") - hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space - #echo "Model: '$hdmodel'" # debug - - fwrev=$(cat "$d/device/rev") - fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space - #echo "Firmware: '$fwrev'" # debug - - if [[ $hdmodel ]] && [[ $fwrev ]]; then - hdlist+=("${hdmodel},${fwrev}") - fi + # Get drive model and firmware version + getdriveinfo "$d" fi ;; nvme*) if [[ $d =~ nvme[0-9][0-9]?n[0-9][0-9]?$ ]]; then if [[ $m2 != "no" ]]; then - nvmemodel=$(cat "$d/device/model") - nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space - #echo "NVMe Model: '$nvmemodel'" # debug - - nvmefw=$(cat "$d/device/firmware_rev") - nvmefw=$(printf "%s" "$nvmefw" | xargs) # trim leading and trailing white space - #echo "NVMe Firmware: '$nvmefw'" # debug - - if [[ $nvmemodel ]] && [[ $nvmefw ]]; then - nvmelist+=("${nvmemodel},${nvmefw}") - fi + getm2info "$d" "nvme" + # Get M.2 card model if in M.2 card + getcardmodel "/dev/$d" fi fi ;; @@ -187,18 +332,9 @@ for d in /sys/block/*; do #if [[ $d =~ nvc[0-9][0-9]?p[0-9][0-9]?$ ]]; then if [[ $d =~ nvc[0-9][0-9]?$ ]]; then if [[ $m2 != "no" ]]; then - nvmemodel=$(cat "$d/device/model") - nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space - #echo "M.2 SATA Model: '$nvmemodel'" # debug - - #nvmefw=$(cat "$d/device/firmware_rev") - nvmefw=$(cat "$d/device/rev") - nvmefw=$(printf "%s" "$nvmefw" | xargs) # trim leading and trailing white space - #echo "M.2 SATA Firmware: '$nvmefw'" # debug - - if [[ $nvmemodel ]] && [[ $nvmefw ]]; then - nvmelist+=("${nvmemodel},${nvmefw}") - fi + getm2info "$d" "nvc" + # Get M.2 card model if in M.2 card + getcardmodel "/dev/$d" fi fi ;; @@ -206,16 +342,25 @@ for d in /sys/block/*; do done +sortarray(){ + # Sort $1 array into new $2 array to remove duplicates + local -n inarray=$1 + outarray=() + if [[ ${#inarray[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + outarray+=("$x") + done < <(printf "%s\0" "${inarray[@]}" | sort -uz) + fi +} + + # Sort hdlist array into new hdds array to remove duplicates -if [[ ${#hdlist[@]} -gt "0" ]]; then - while IFS= read -r -d '' x; do - hdds+=("$x") - done < <(printf "%s\0" "${hdlist[@]}" | sort -uz) -fi +sortarray "hdlist" +hdds=${outarray[*]} # Check hdds array isn't empty if [[ ${#hdds[@]} -eq "0" ]]; then - echo -e "\e[41mERROR\e[0m No drives found!" && exit 2 + echo -e "${Error}ERROR${Off} No drives found!" && exit 2 else echo "HDD/SSD models found: ${#hdds[@]}" num="0" @@ -228,11 +373,8 @@ fi # Sort nvmelist array into new nvmes array to remove duplicates -if [[ ${#nvmelist[@]} -gt "0" ]]; then - while IFS= read -r -d '' x; do - nvmes+=("$x") - done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz) -fi +sortarray "nvmelist" +nvmes=${outarray[*]} # Check nvmes array isn't empty if [[ ${#nvmes[@]} -eq "0" ]]; then @@ -250,14 +392,40 @@ else fi +# M.2 card db files +# Sort m2carddblist array into new m2carddbs array to remove duplicates +sortarray "m2carddblist" +m2carddbs=${outarray[*]} + +# M.2 cards +# Sort m2cardlist array into new m2cards array to remove duplicates +sortarray "m2cardlist" +m2cards=${outarray[*]} + +# Check m2cards array isn't empty +if [[ ${#m2cards[@]} -gt "0" ]]; then + echo "M.2 card models found: ${#m2cards[@]}" + num="0" + while [[ $num -lt "${#m2cards[@]}" ]]; do + echo "${m2cards[num]}" + num=$((num +1)) + done + echo +fi + + #------------------------------------------------------------------------------ -# Check database and add our drives if needed +# Check databases and add our drives if needed db1="/var/lib/disk-compatibility/${model}_host${version}.db" db2="/var/lib/disk-compatibility/${model}_host${version}.db.new" +dbpath="/var/lib/disk-compatibility/" -if [[ ! -f "$db1" ]]; then echo -e "\e[41mERROR\e[0m $db1 not found!" && exit 3; fi -#if [[ ! -f "$db2" ]]; then echo -e "\e[41mERROR\e[0m $db2 not found!" && exit 4; fi +synoinfo="/etc.defaults/synoinfo.conf" + + +if [[ ! -f "$db1" ]]; then echo -e "${Error}ERROR 3${Off} $db1 not found!" && exit 3; fi +#if [[ ! -f "$db2" ]]; then echo -e "${Error}ERROR 4${Off} $db2 not found!" && exit 4; fi # new installs don't have a .db.new file @@ -269,30 +437,36 @@ elif grep -F '{"success":1,"list":[' "$db1" >/dev/null; then # DSM 6 drive db files start with {"success":1,"list":[ dbtype=6 else - echo -e "\e[41mERROR\e[0m Unknown database type $(basename -- "${db1}")!" + echo -e "${Error}ERROR${Off} Unknown database type $(basename -- "${db1}")!" exit 7 fi #echo "dbtype: $dbtype" # debug -# Backup database file if needed -if [[ ! -f "$db1.bak" ]]; then - if cp "$db1" "$db1.bak"; then - echo -e "Backed up database to $(basename -- "${db1}").bak\n" - else - echo -e "\e[41mERROR\e[0m Failed to backup $(basename -- "${db1}")!" - exit 5 +backupdb() { + # Backup database file if needed + if [[ ! -f "$1.bak" ]]; then + if cp "$1" "$1.bak"; then + echo -e "\nBacked up $(basename -- "${1}") database.\n" + else + echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${1}")!" + return 1 + fi fi -fi +} -# Shell Colors -Yellow='\e[0;33m' -Cyan='\e[0;36m' -Red='\e[0;31m' -Off=$'\e[0m' +# Backup host database file if needed +backupdb "$db1" || exit 5 + +# Backup synoinfo.conf if needed +backupdb "$synoinfo" || exit 9 + + +#------------------------------------------------------------------------------ +# Edit db files -function updatedb() { +updatedb() { hdmodel=$(printf "%s" "$1" | cut -d"," -f 1) fwrev=$(printf "%s" "$1" | cut -d"," -f 2) @@ -317,13 +491,16 @@ function updatedb() { #if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # Don't need to add firmware version? if sed -i "s/}}}/}},\"$hdmodel\":{$default/" "$2"; then echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" + + # Count drives added to host db files if [[ $2 == "$db1" ]]; then db1Edits=$((db1Edits +1)) elif [[ $2 == "$db2" ]]; then db2Edits=$((db2Edits +1)) fi + else - echo -e "\n\e[41mERROR\e[0m Failed to update v7 $(basename -- "$2")${Off}" + echo -e "\n${Error}ERROR 6${Off} Failed to update v7 $(basename -- "$2")${Off}" exit 6 fi else @@ -343,13 +520,16 @@ function updatedb() { # {"success":1,"list":[{"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, if sed -ir "s/$startstring/$startstring$string/" "$2"; then echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" + + # Count drives added to host db files if [[ $2 == "$db1" ]]; then db1Edits=$((db1Edits +1)) elif [[ $2 == "$db2" ]]; then db2Edits=$((db2Edits +1)) fi + else - echo -e "\n\e[41mERROR\e[0m Failed to update $(basename -- "$2")${Off}" + echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" exit 8 fi fi @@ -373,18 +553,36 @@ while [[ $num -lt "${#nvmes[@]}" ]]; do if [[ -f "$db2" ]]; then updatedb "${nvmes[$num]}" "$db2" fi + + #------------------------------------------------ + # M.2 adaptor cards + num2="0" + while [[ $num2 -lt "${#m2carddbs[@]}" ]]; do + if [[ -f "${dbpath}${m2carddbs[$num2]}" ]];then + backupdb "${dbpath}${m2carddbs[$num2]}" &&\ + updatedb "${nvmes[$num]}" "${dbpath}${m2carddbs[$num2]}" + else + echo -e "${Error}ERROR 10${Off} ${m2carddbs[$num2]} not found!" + fi + num2=$((num2 +1)) + done + #------------------------------------------------ + num=$((num +1)) done +#------------------------------------------------------------------------------ +# Edit /etc.defaults/synoinfo.conf + # Optionally disable "support_disk_compatibility" sdc=support_disk_compatibility -setting="$(get_key_value /etc.defaults/synoinfo.conf $sdc)" +setting="$(get_key_value $synoinfo $sdc)" if [[ $force == "yes" ]]; then if [[ $setting == "yes" ]]; then # Disable support_disk_compatibility - sed -i "s/${sdc}=\"yes\"/${sdc}=\"no\"/" "/etc.defaults/synoinfo.conf" - setting="$(get_key_value /etc.defaults/synoinfo.conf $sdc)" + sed -i "s/${sdc}=\"yes\"/${sdc}=\"no\"/" "$synoinfo" + setting="$(get_key_value "$synoinfo" $sdc)" if [[ $setting == "no" ]]; then echo -e "\nDisabled support disk compatibility." fi @@ -392,8 +590,8 @@ if [[ $force == "yes" ]]; then else if [[ $setting == "no" ]]; then # Enable support_disk_compatibility - sed -i "s/${sdc}=\"no\"/${sdc}=\"yes\"/" "/etc.defaults/synoinfo.conf" - setting="$(get_key_value /etc.defaults/synoinfo.conf $sdc)" + sed -i "s/${sdc}=\"no\"/${sdc}=\"yes\"/" "$synoinfo" + setting="$(get_key_value "$synoinfo" $sdc)" if [[ $setting == "yes" ]]; then echo -e "\nRe-enabled support disk compatibility." fi @@ -403,53 +601,76 @@ fi # Check m2 volume support enabled smp=support_m2_pool -setting="$(get_key_value /etc.defaults/synoinfo.conf ${smp})" -if [[ $setting == "no" ]]; then - sed -i "s/${smp}=\"no\"/${smp}=\"yes\"/" "/etc.defaults/synoinfo.conf" - setting="$(get_key_value /etc.defaults/synoinfo.conf ${smp})" +setting="$(get_key_value $synoinfo ${smp})" +enabled="" +if [[ ! $setting ]]; then + # Add support_m2_pool"yes" + echo 'support_m2_pool="yes"' >> "$synoinfo" + enabled="yes" +elif [[ $setting == "no" ]]; then + # Change support_m2_pool"no" to "yes" + sed -i "s/${smp}=\"no\"/${smp}=\"yes\"/" "$synoinfo" + enabled="yes" +elif [[ $setting == "yes" ]]; then + echo -e "\nM.2 volume support already enabled." +fi + +# Check if we enabled m2 volume support +setting="$(get_key_value $synoinfo ${smp})" +if [[ $enabled == "yes" ]]; then if [[ $setting == "yes" ]]; then echo -e "\nEnabled M.2 volume support." + else + echo -e "${Error}ERROR${Off} Failed to enable m2 volume support!" fi fi -# Edit synoinfo.conf to prevent DB updates -#if [[ $nodbupdate == "yes" ]]; then # For future use - file=/etc.defaults/synoinfo.conf - if [[ -f $file ]]; then - # Backup synoinfo.conf if needed - if [[ ! -f "$file.bak" ]]; then - if cp "$file" "$file.bak"; then - echo "Backed up synoinfo.conf to $(basename -- "${file}").bak" - else - echo -e "\e[41mERROR\e[0m Failed to backup $(basename -- "${file}")!" - exit 6 - fi - fi +# Edit synoinfo.conf to prevent drive db updates +dtu=drive_db_test_url +url="$(get_key_value $synoinfo ${dtu})" +disabled="" +if [[ $nodbupdate == "yes" ]]; then + if [[ ! $url ]]; then + # Add drive_db_test_url="127.0.0.1" + echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo" + disabled="yes" + elif [[ $url != "127.0.0.1" ]]; then + # Edit drive_db_test_url= + sed -i "s/drive_db_test_url=.*/drive_db_test_url=\"127.0.0.1\"/" "$synoinfo" >/dev/null + disabled="yes" + fi - url=$(get_key_value "$file" drive_db_test_url) # returns a linefeed if key doesn't exist - if [[ ! $url ]]; then - # Add drive_db_test_url=127.0.0.1 - echo 'drive_db_test_url="127.0.0.1"' >> "$file" - disabled="yes" - elif [[ $url != "127.0.0.1" ]]; then - # Edit drive_db_test_url= - sed -i "s/drive_db_test_url=.*/drive_db_test_url=\"127.0.0.1\"/" "$file" - disabled="yes" + # Check if we disabled drive db auto updates + url="$(get_key_value $synoinfo drive_db_test_url)" + if [[ $disabled == "yes" ]]; then + if [[ $url == "127.0.0.1" ]]; then + echo -e "\nDisabled drive db auto updates." + else + echo -e "${Error}ERROR${Off} Failed to disable drive db auto updates!" fi - - url=$(get_key_value "$file" drive_db_test_url) - if [[ $disabled == "yes" ]]; then - if [[ $url == "127.0.0.1" ]]; then - echo "Disabled drive db auto updates." - else - echo -e "\e[41mERROR\e[0m Failed to disable drive db auto updates!" - fi + fi +else + # Re-enable drive db updates + if [[ $url == "127.0.0.1" ]]; then + # Edit drive_db_test_url= + sed -z "s/drive_db_test_url=\"127\.0\.0\.1\"\n//" "$synoinfo" >/dev/null + #sed -i "s/drive_db_test_url=\"127\.0\.0\.1\"//" "$synoinfo" # works but leaves line feed + + # Check if we re-enabled drive db auto updates + url="$(get_key_value $synoinfo drive_db_test_url)" + if [[ $url != "127.0.0.1" ]]; then + echo -e "\nRe-enabled drive db auto updates." fi + else + echo -e "\nDrive db auto updates already enabled." fi -#fi +fi +#------------------------------------------------------------------------------ +# Finished + # Show the changes if [[ ${showedits,,} == "yes" ]]; then if [[ $dbtype -gt "6" ]];then From 0cca7b862098190062ee0dc028de849fcdd25ebd Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:25:51 +1100 Subject: [PATCH 03/18] Update syno_hdd_db.sh - Fixed bug where removable drives were being detected and added to drive database. --- syno_hdd_db.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index a17b6b2..95686a1 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -47,6 +47,8 @@ # # Changed checking drive_db_test_url setting to be more durable. # +# Fixed bug where removable drives were being detected and added to drive database. +# # # Added check that M.2 volume support is enabled (on supported models). # @@ -263,15 +265,19 @@ fi # Get list of installed SATA, SAS and M.2 NVMe/SATA drives getdriveinfo() { - # Get drive model and firmware version - hdmodel=$(cat "$1/device/model") - hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space - - fwrev=$(cat "$1/device/rev") - fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space - - if [[ $hdmodel ]] && [[ $fwrev ]]; then - hdlist+=("${hdmodel},${fwrev}") + # Skip removable drives (USB drives) + removable=$(cat "$1/removable") + if [[ $removable == "0" ]]; then + # Get drive model and firmware version + hdmodel=$(cat "$1/device/model") + hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space + + fwrev=$(cat "$1/device/rev") + fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space + + if [[ $hdmodel ]] && [[ $fwrev ]]; then + hdlist+=("${hdmodel},${fwrev}") + fi fi } From 1543e2723d868a0c5817d4ae050ba586a37760b8 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:26:34 +1100 Subject: [PATCH 04/18] Update CHANGES.txt - Fixed bug where removable drives were being detected and added to drive database. --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 20b5d3d..db525a1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,7 @@ v1.1.15 - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. - Changed Synology model detection to be more reliable (for models that came in different variations). - Changed checking drive_db_test_url setting to be more durable. +- Fixed bug where removable drives were being detected and added to drive database. v1.1.14 - Minor bug fix. From 7c37061e4d412df865df538a30eb70bef9b233ef Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 11:07:08 +1100 Subject: [PATCH 05/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 63 ++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 95686a1..c523e09 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -84,6 +84,7 @@ scriptver="v1.1.15" script=Synology_HDD_db repo="007revad/Synology_HDD_db" +#echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug # Shell Colors #Black='\e[0;30m' @@ -297,16 +298,18 @@ getm2info() { } getcardmodel() { - # Get M.2 card model - cardmodel=$(synodisk --m2-card-model-get "$1") - if [[ $cardmodel =~ M2D[0-9][0-9] ]]; then - # M2 adaptor card - m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file - m2cardlist+=("$cardmodel") # M.2 card - elif [[ $cardmodel =~ E[0-9][0-9]+M.+ ]]; then - # Ethernet + M2 adaptor card - m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file - m2cardlist+=("$cardmodel") # M.2 card + # Get M.2 card model (if M.2 drives found) + if [[ ${#nvmelist[@]} -gt "0" ]]; then + cardmodel=$(synodisk --m2-card-model-get "$1") + if [[ $cardmodel =~ M2D[0-9][0-9] ]]; then + # M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + elif [[ $cardmodel =~ E[0-9][0-9]+M.+ ]]; then + # Ethernet + M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + fi fi } @@ -348,21 +351,12 @@ for d in /sys/block/*; do done -sortarray(){ - # Sort $1 array into new $2 array to remove duplicates - local -n inarray=$1 - outarray=() - if [[ ${#inarray[@]} -gt "0" ]]; then - while IFS= read -r -d '' x; do - outarray+=("$x") - done < <(printf "%s\0" "${inarray[@]}" | sort -uz) - fi -} - - # Sort hdlist array into new hdds array to remove duplicates -sortarray "hdlist" -hdds=${outarray[*]} +if [[ ${#hdlist[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + hdds+=("$x") + done < <(printf "%s\0" "${hdlist[@]}" | sort -uz) +fi # Check hdds array isn't empty if [[ ${#hdds[@]} -eq "0" ]]; then @@ -379,8 +373,11 @@ fi # Sort nvmelist array into new nvmes array to remove duplicates -sortarray "nvmelist" -nvmes=${outarray[*]} +if [[ ${#nvmelist[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + nvmes+=("$x") + done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz) +fi # Check nvmes array isn't empty if [[ ${#nvmes[@]} -eq "0" ]]; then @@ -400,13 +397,19 @@ fi # M.2 card db files # Sort m2carddblist array into new m2carddbs array to remove duplicates -sortarray "m2carddblist" -m2carddbs=${outarray[*]} +if [[ ${#m2carddblist[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + m2carddbs+=("$x") + done < <(printf "%s\0" "${m2carddblist[@]}" | sort -uz) +fi # M.2 cards # Sort m2cardlist array into new m2cards array to remove duplicates -sortarray "m2cardlist" -m2cards=${outarray[*]} +if [[ ${#m2cardlist[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + m2cards+=("$x") + done < <(printf "%s\0" "${m2cardlist[@]}" | sort -uz) +fi # Check m2cards array isn't empty if [[ ${#m2cards[@]} -gt "0" ]]; then From 24d971a12be8d234c9c0216a1a6bd2eea3741e6e Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 11:14:35 +1100 Subject: [PATCH 06/18] Update CHANGES.txt --- CHANGES.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index db525a1..d6e94e9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,12 +1,12 @@ v1.1.15 - Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). -- Improved flags/options checking and added usage help. -- Can now download the latest script version for you (if you have user home service enabled in DSM). +- Improved flags/options checking and added usage help (-h or --help) and version info (-v or --version). +- Can now download the latest script version for you (if you have 'user home service' enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. -- Changed Synology model detection to be more reliable (for models that came in different variations). +- Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). - Changed checking drive_db_test_url setting to be more durable. -- Fixed bug where removable drives were being detected and added to drive database. +- Fixed bug where removable drives were being added to the drive database. v1.1.14 - Minor bug fix. From 3e0ed022b8e6b25ce596fec0d2eb7f78bf2997e4 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 11:43:06 +1100 Subject: [PATCH 07/18] Update CHANGES.txt --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index d6e94e9..0858283 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,7 @@ v1.1.15 - Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). - Changed checking drive_db_test_url setting to be more durable. - Fixed bug where removable drives were being added to the drive database. +- Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. v1.1.14 - Minor bug fix. From 85479bc766d6eda67da4d01336a7a063260cf260 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 11:45:37 +1100 Subject: [PATCH 08/18] Update syno_hdd_db.sh Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. --- syno_hdd_db.sh | 72 ++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index c523e09..f18e97f 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -49,6 +49,8 @@ # # Fixed bug where removable drives were being detected and added to drive database. # +# Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. +# # # Added check that M.2 volume support is enabled (on supported models). # @@ -380,18 +382,19 @@ if [[ ${#nvmelist[@]} -gt "0" ]]; then fi # Check nvmes array isn't empty -if [[ ${#nvmes[@]} -eq "0" ]]; then - if [[ $m2 != "no" ]]; then +if [[ $m2 != "no" ]]; then + if [[ ${#nvmes[@]} -eq "0" ]]; then echo -e "No M.2 drives found\n" + else + m2exists="yes" + echo "M.2 drive models found: ${#nvmes[@]}" + num="0" + while [[ $num -lt "${#nvmes[@]}" ]]; do + echo "${nvmes[num]}" + num=$((num +1)) + done + echo fi -else - echo "M.2 drive models found: ${#nvmes[@]}" - num="0" - while [[ $num -lt "${#nvmes[@]}" ]]; do - echo "${nvmes[num]}" - num=$((num +1)) - done - echo fi @@ -608,29 +611,34 @@ else fi -# Check m2 volume support enabled -smp=support_m2_pool -setting="$(get_key_value $synoinfo ${smp})" -enabled="" -if [[ ! $setting ]]; then - # Add support_m2_pool"yes" - echo 'support_m2_pool="yes"' >> "$synoinfo" - enabled="yes" -elif [[ $setting == "no" ]]; then - # Change support_m2_pool"no" to "yes" - sed -i "s/${smp}=\"no\"/${smp}=\"yes\"/" "$synoinfo" - enabled="yes" -elif [[ $setting == "yes" ]]; then - echo -e "\nM.2 volume support already enabled." -fi +# Enable m2 volume support +if [[ $m2 != "no" ]]; then + if [[ $m2exists == "yes" ]]; then + # Check if m2 volume support is enabled + smp=support_m2_pool + setting="$(get_key_value $synoinfo ${smp})" + enabled="" + if [[ ! $setting ]]; then + # Add support_m2_pool"yes" + echo 'support_m2_pool="yes"' >> "$synoinfo" + enabled="yes" + elif [[ $setting == "no" ]]; then + # Change support_m2_pool"no" to "yes" + sed -i "s/${smp}=\"no\"/${smp}=\"yes\"/" "$synoinfo" + enabled="yes" + elif [[ $setting == "yes" ]]; then + echo -e "\nM.2 volume support already enabled." + fi -# Check if we enabled m2 volume support -setting="$(get_key_value $synoinfo ${smp})" -if [[ $enabled == "yes" ]]; then - if [[ $setting == "yes" ]]; then - echo -e "\nEnabled M.2 volume support." - else - echo -e "${Error}ERROR${Off} Failed to enable m2 volume support!" + # Check if we enabled m2 volume support + setting="$(get_key_value $synoinfo ${smp})" + if [[ $enabled == "yes" ]]; then + if [[ $setting == "yes" ]]; then + echo -e "\nEnabled M.2 volume support." + else + echo -e "${Error}ERROR${Off} Failed to enable m2 volume support!" + fi + fi fi fi From 6a2ae6c3c2b0a1290b97cb584f7548966c9d9547 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 21:28:02 +1100 Subject: [PATCH 09/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0858283..1decd2d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,7 +4,7 @@ v1.1.15 - Can now download the latest script version for you (if you have 'user home service' enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. -- Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). +- Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). issue # and issue #10 - Changed checking drive_db_test_url setting to be more durable. - Fixed bug where removable drives were being added to the drive database. - Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. From 64811801e179098fbaa7b04ff0650a693ae0751c Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sat, 18 Mar 2023 21:28:20 +1100 Subject: [PATCH 10/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1decd2d..989c6f7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,7 +4,7 @@ v1.1.15 - Can now download the latest script version for you (if you have 'user home service' enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. -- Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). issue # and issue #10 +- Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). issue #2 and issue #10 - Changed checking drive_db_test_url setting to be more durable. - Fixed bug where removable drives were being added to the drive database. - Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. From 3a01ba75babc811abd5b25f10204570515a18cc9 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sun, 19 Mar 2023 06:42:37 +1100 Subject: [PATCH 11/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 989c6f7..5b30bd4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,5 @@ v1.1.15 -- Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). +- Added support for M.2 drives on a PCI card (M2Dxx and E10M20-T1 and future models). - Improved flags/options checking and added usage help (-h or --help) and version info (-v or --version). - Can now download the latest script version for you (if you have 'user home service' enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf From 0cb23f8279f5b8b109c6f3a7e4b92a752898e11d Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sun, 19 Mar 2023 06:43:54 +1100 Subject: [PATCH 12/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index f18e97f..fbec9d7 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -3,7 +3,7 @@ #-------------------------------------------------------------------------------------------------- # Github: https://github.com/007revad/Synology_HDD_db # Script verified at https://www.shellcheck.net/ -# Tested on DSM 7.1.1 and DSM 6.2.4 +# Tested on DSM 7.2 beta, 7.1.1 and DSM 6.2.4 # # Easiest solution: # Edit /etc.defaults/synoinfo.conf and change support_disk_compatibility="yes" to "no" and reboot. @@ -33,7 +33,7 @@ # It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. # DONE -# Added support for M.2 drives on a PCI card (M2Dxx and E10G18-T1 and future models). +# Added support for M.2 drives on a PCI card (M2Dxx and E10M20-T1 and future models). # # Improved flags/options checking and added usage help. # From f2df7109e164f6a76df3737aa6c281d02553d0bc Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Sun, 19 Mar 2023 18:44:32 +1100 Subject: [PATCH 13/18] Update syno_hdd_db.sh Changed model detection method, again. --- syno_hdd_db.sh | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index fbec9d7..baff3e8 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -185,23 +185,9 @@ if [[ $dsm -gt "6" ]]; then version="_v$dsm" fi -# Get Synology model -model=$(cat /proc/sys/kernel/syno_hw_version) # not always the actual model number - -modeltype=$(printf "%s" "$model" | sed 's/[0-9].*//') # DS, RS etc - -unique=$(get_key_value /etc/synoinfo.conf unique | cut -d'_' -f3) # 920+ etc - -# Remove extra text from end, like DS213pv10-j and DS1817+-j -#[[ $model =~ ([0-9]{3,}) ]] && modelnum=${BASH_REMATCH[1]} -[[ $model =~ ([0-9]{3,}(RP\+|RPxs|RP|\+II|xsII|xs\+|xs|\+|j|slim|play|se|air|D)?) ]] &&\ - modelnum=${BASH_REMATCH[1]} - -if [[ $modelnum != "$unique" ]]; then - model="$modeltype$unique" -fi - -model=${model,,} # convert to lower case +# Get Synology model from host db file +model=$(ls -lh /var/lib/disk-compatibility | grep -E ".*host(_v7)?\.db$" |\ + rev | cut -d" " -f1 | rev | cut -d"_" -f1) #------------------------------------------------------------------------------ From 5447ec6fff6057d35f25e23297d047dee9336cbc Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Mon, 20 Mar 2023 00:31:48 +1100 Subject: [PATCH 14/18] Update CHANGES.txt --- CHANGES.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5b30bd4..2c1e8ab 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,9 +1,11 @@ -v1.1.15 -- Added support for M.2 drives on a PCI card (M2Dxx and E10M20-T1 and future models). +v1.2.15 +- Now finds your expansion units' model numbers and adds your drives to their db files. +- Now adds your M.2 drives to your M.2 PCI card's db files (supports M2Dxx and E10M20-T1 and future models with similar model names). - Improved flags/options checking and added usage help (-h or --help) and version info (-v or --version). - Can now download the latest script version for you (if you have 'user home service' enabled in DSM). - Now adds 'support_m2_pool="yes"' line for models that don't have support_m2_pool in synoinfo.conf - To (hopefully) prevent losing your SSH created M2 volume when running this script on models that DSM 7.2 Beta does not list as supported for creating M2 volumes. +- Added removal of " 00Y" from end of Samsung/Lenovo SSDs to fix issue #13. - Changed Synology NAS model detection to be more reliable (for models that came in different variations and report extra text after model). issue #2 and issue #10 - Changed checking drive_db_test_url setting to be more durable. - Fixed bug where removable drives were being added to the drive database. From bdfe8e88f9cf48a476721479a18e7ccaf7920541 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Mon, 20 Mar 2023 00:37:34 +1100 Subject: [PATCH 15/18] Update syno_hdd_db.sh - Now finds your expansion units' model numbers and adds your drives to their db files. - Now adds your M.2 drives to your M.2 PCI cards db files (M2Dxx and E10M20-T1 and future models) --- syno_hdd_db.sh | 153 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 109 insertions(+), 44 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index baff3e8..1692d97 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -25,15 +25,13 @@ # TODO # Bypass M.2 volume lock for unsupported M.2 drives. # -# Detect if expansion unit(s) connected and get model(s) and edit expansion unit db files. -# Or add support for specifying user's expansion unit model(s) as arguments. -# Or maybe use the shotgun approach and update all expansion unit db files. -# # Maybe also edit the other disk compatibility db in synoboot, used during boot time. # It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. # DONE -# Added support for M.2 drives on a PCI card (M2Dxx and E10M20-T1 and future models). +# Now finds your expansion units' model numbers and adds your drives to their db files. +# +# Now adds your M.2 drives to your M.2 PCI cards db files (M2Dxx and E10M20-T1 and future models). # # Improved flags/options checking and added usage help. # @@ -47,6 +45,8 @@ # # Changed checking drive_db_test_url setting to be more durable. # +# Added removal of " 00Y" from end of Samsung/Lenovo SSDs to fix issue #13. +# # Fixed bug where removable drives were being detected and added to drive database. # # Fixed bug where "M.2 volume support already enabled" message appeared when NAS had no M.2 drives. @@ -82,7 +82,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v1.1.15" +scriptver="v1.2.15" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -123,18 +123,17 @@ exit 0 scriptversion(){ cat </dev/null; then - # DSM 7 drive db files start with {"disk_compatbility_info": - dbtype=7 -elif grep -F '{"success":1,"list":[' "$db1" >/dev/null; then - # DSM 6 drive db files start with {"success":1,"list":[ - dbtype=6 -else - echo -e "${Error}ERROR${Off} Unknown database type $(basename -- "${db1}")!" - exit 7 -fi -#echo "dbtype: $dbtype" # debug +getdbtype(){ + # Detect drive db type + if grep -F '{"disk_compatbility_info":' "$1" >/dev/null; then + # DSM 7 drive db files start with {"disk_compatbility_info": + dbtype=7 + elif grep -F '{"success":1,"list":[' "$1" >/dev/null; then + # DSM 6 drive db files start with {"success":1,"list":[ + dbtype=6 + else + echo -e "${Error}ERROR${Off} Unknown database type $(basename -- "${1}")!" >&2 + dbtype=1 + fi + #echo "db type: $dbtype" >&2 # debug +} backupdb() { # Backup database file if needed if [[ ! -f "$1.bak" ]]; then if cp "$1" "$1.bak"; then - echo -e "\nBacked up $(basename -- "${1}") database.\n" + echo -e "Backed up $(basename -- "${1}")" >&2 else - echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${1}")!" + echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${1}")!" >&2 return 1 fi fi @@ -457,9 +501,6 @@ backupdb() { # Backup host database file if needed backupdb "$db1" || exit 5 -# Backup synoinfo.conf if needed -backupdb "$synoinfo" || exit 9 - #------------------------------------------------------------------------------ # Edit db files @@ -468,14 +509,17 @@ updatedb() { hdmodel=$(printf "%s" "$1" | cut -d"," -f 1) fwrev=$(printf "%s" "$1" | cut -d"," -f 2) - #echo arg1 "$1" # debug - #echo arg2 "$2" # debug - #echo hdmodel "$hdmodel" # debug - #echo fwrev "$fwrev" # debug + #echo arg1 "$1" >&2 # debug + #echo arg2 "$2" >&2 # debug + #echo hdmodel "$hdmodel" >&2 # debug + #echo fwrev "$fwrev" >&2 # debug if grep "$hdmodel" "$2" >/dev/null; then - echo -e "${Yellow}$hdmodel${Off} already exists in ${Cyan}$(basename -- "$2")${Off}" + echo -e "${Yellow}$hdmodel${Off} already exists in ${Cyan}$(basename -- "$2")${Off}" >&2 else + # Check if db file is new or old style + getdbtype "$2" + if [[ $dbtype -gt "6" ]];then # Don't need to add firmware version? fwstrng=\"$fwrev\" @@ -501,7 +545,7 @@ updatedb() { echo -e "\n${Error}ERROR 6${Off} Failed to update v7 $(basename -- "$2")${Off}" exit 6 fi - else + elif [[ $dbtype -eq "6" ]];then # example: # {"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, # Don't need to add firmware version? @@ -510,9 +554,9 @@ updatedb() { # {"success":1,"list":[ startstring="{\"success\":1,\"list\":\[" - #echo "$startstring" # debug - #echo "$string" # debug - #echo # debug + #echo "$startstring" >&2 # debug + #echo "$string" >&2 # debug + #echo >&2 # debug # example: # {"success":1,"list":[{"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, @@ -527,7 +571,7 @@ updatedb() { fi else - echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" + echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" >&2 exit 8 fi fi @@ -541,6 +585,22 @@ while [[ $num -lt "${#hdds[@]}" ]]; do if [[ -f "$db2" ]]; then updatedb "${hdds[$num]}" "$db2" fi + + #------------------------------------------------ + # Expansion Units + num2="0" + while [[ $num2 -lt "${#eunits[@]}" ]]; do + eudb="${dbpath}${eunits[$num2],,}${version}.db" + if [[ -f "$eudb" ]];then + backupdb "$eudb" &&\ + updatedb "${hdds[$num]}" "$eudb" + else + echo -e "${Error}ERROR 11${Off} $eudb not found!" + fi + num2=$((num2 +1)) + done + #------------------------------------------------ + num=$((num +1)) done @@ -573,6 +633,10 @@ done #------------------------------------------------------------------------------ # Edit /etc.defaults/synoinfo.conf +# Backup synoinfo.conf if needed +echo "" +backupdb "$synoinfo" || exit 9 + # Optionally disable "support_disk_compatibility" sdc=support_disk_compatibility setting="$(get_key_value $synoinfo $sdc)" @@ -676,6 +740,7 @@ fi # Show the changes if [[ ${showedits,,} == "yes" ]]; then + getdbtype "$db1" if [[ $dbtype -gt "6" ]];then # Show last 12 lines per drive + 4 lines=$(((db1Edits *12) +4)) @@ -686,7 +751,7 @@ if [[ ${showedits,,} == "yes" ]]; then echo -e "\nChanges to ${Cyan}$(basename -- "$db2")${Off}" jq . "$db2" | tail -n "$lines" fi - else + elif [[ $dbtype -eq "6" ]];then # Show first 8 lines per drive + 2 lines=$(((db1Edits *8) +2)) if [[ $db1Edits -gt "0" ]]; then From 1d5f70295d3fc075bd8571ec2ba07ff365c95ef4 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Mon, 20 Mar 2023 01:12:37 +1100 Subject: [PATCH 16/18] Update syno_hdd_db.sh Changed model detection to also be DSM 6 compatible. --- syno_hdd_db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 1692d97..113fef8 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -187,7 +187,7 @@ fi # Get Synology model model=$(find /var/lib/disk-compatibility -regextype egrep -regex ".*host(_v7)?\.db$" |\ - rev | cut -d"/" -f1 | rev | cut -d"_" -f1) + cut -d"/" -f5 | cut -d"_" -f1 | uniq) #------------------------------------------------------------------------------ From e0749b5443b6b0061e1c259e505d2bc65767adc7 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Mon, 20 Mar 2023 01:46:47 +1100 Subject: [PATCH 17/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 113fef8..fefdeb7 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -186,8 +186,20 @@ if [[ $dsm -gt "6" ]]; then fi # Get Synology model -model=$(find /var/lib/disk-compatibility -regextype egrep -regex ".*host(_v7)?\.db$" |\ - cut -d"/" -f5 | cut -d"_" -f1 | uniq) + +# This doesn't work for drives migrated from different model +#model=$(find /var/lib/disk-compatibility -regextype egrep -regex ".*host(_v7)?\.db$" |\ +# cut -d"/" -f5 | cut -d"_" -f1 | uniq) + +model=$(cat /proc/sys/kernel/syno_hw_version) +model=${model,,} # convert to lower case + +# Check for dodgy characters after model number +if [[ $model =~ 'pv10-j'$ ]]; then # GitHub issue #10 + model=${model%??????}+ # replace last 6 chars with + +elif [[ $model =~ '-j'$ ]]; then # GitHub issue #2 + model=${model%??} # remove last 2 chars +fi #------------------------------------------------------------------------------ From 500119e1e34cb485dba1c7314a37ffec63f08973 Mon Sep 17 00:00:00 2001 From: 007revad <39733752+007revad@users.noreply.github.com> Date: Mon, 20 Mar 2023 07:27:48 +1100 Subject: [PATCH 18/18] Update README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3de6623..72ca773 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ # Synology HDD db ### Description -Add your SATA or SAS HDDs and SSDs plus SATA and NVMe M.2 drives to your Synology's compatible drive databases. +Add your SATA or SAS HDDs and SSDs plus SATA and NVMe M.2 drives to your Synology's compatible drive databases, including your M.2 card and Expansion Unit databases. The script works in DSM 7 and DSM 6. @@ -14,7 +14,7 @@ #### What the script does: * Gets the Synology NAS model and DSM version (so it knows which db files to edit). * Gets a list of the HDD, SSD, SAS and NVMe drives installed in your Synology NAS. * Gets each drive's model number and firmware version. -* Backs up the database file if there is no backup already. +* Backs up the database files if there is no backup already. * Checks if each drive is already in the Synology's compatible-drive database. * Adds any missing drives to the Synology's compatible-drive database. * Prevents DSM auto updating the drive database. @@ -25,9 +25,6 @@ #### What the script does: **Planned updates:** * Allow unsupported M.2 drives for use as volumes in DSM 7.2 (for models that supported M.2 volumes). -* Detect any connected expansion units and get the model(s) and edit the correct expansion unit db files. - * Or add support for users to specify their expansion unit model(s) as arguments. - * Or maybe use the shotgun approach and update all expansion unit db files. ### Download the script