diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index d7001c8..5d1dbbe 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. @@ -25,16 +25,41 @@ # 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. # It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. # DONE +# Changed to show if no M.2 cards were found, if M.2 drives were found. +# +# Changed latest version check to download to /tmp and extract files to the script's location, +# replacing the existing .sh and readme.txt files. +# +# Added a timeouts when checking for newer script version in case github is down or slow. +# +# Added option to disable incompatible memory notifications. +# +# 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. +# +# 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 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. +# # Added check that M.2 volume support is enabled (on supported models). # # Added support for M.2 SATA drives. @@ -65,71 +90,103 @@ # Optionally disable "support_disk_compatibility". -scriptver="v1.1.14" +scriptver="v1.2.27" +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' +#Black='\e[0;30m' Red='\e[0;31m' -Green='\e[0;32m' +#Green='\e[0;32m' Yellow='\e[0;33m' -Blue='\e[0;34m' -Purple='\e[0;35m' +#Blue='\e[0;34m' +#Purple='\e[0;35m' Cyan='\e[0;36m' -White='\e[0;37m' +#White='\e[0;37m' Error='\e[41m' Off='\e[0m' -# 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 +usage(){ + cat <_host db and db.new file(s) + -n, --noupdate Prevent DSM updating the compatible drive databases + -m, --m2 Don't process M.2 drives + -f, --force Force DSM to not check drive compatibility + -r, --ram Disable memory compatibility checking + -h, --help Show this help message + -v, --version Show the script version + +EOF + exit 0 } -tag=$(get_latest_release "007revad/Synology_HDD_db") -if ! printf "%s\n%s\n" "$tag" "$scriptver" | - sort --check --version-sort &> /dev/null ; then - echo -e "${Cyan}There is a newer version of this script available.${Off}" - 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 [[ -f $scriptpath/$script-$shorttag.tar.gz ]]; then + # They have the latest version tar.gz downloaded but are using older version + echo "https://github.com/$repo/releases/latest" + sleep 10 + elif [[ -d $scriptpath/$script-$shorttag ]]; then + # They have the latest version extracted but are 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 cd /tmp; then + url="https://github.com/$repo/archive/refs/tags/$tag.tar.gz" + if ! curl -LJO -m 30 --connect-timeout 5 "$url"; + then + echo -e "${Error}ERROR ${Off} Failed to download"\ + "$script-$shorttag.tar.gz!" + else + if [[ -f /tmp/$script-$shorttag.tar.gz ]]; then + # Extract tar file to script location + if ! tar -xf "/tmp/$script-$shorttag.tar.gz" -C "/tmp"; + then + echo -e "${Error}ERROR ${Off} Failed to"\ + "extract $script-$shorttag.tar.gz!" + else + # Copy new files to script location + cp "/tmp/$script-$shorttag/CHANGES.txt" "$scriptpath" + cp "/tmp/$script-$shorttag/"*.sh "$scriptpath" + + # Delete downloaded .tar.gz file + if ! rm "/tmp/$script-$shorttag.tar.gz"; then + delerr=1 + echo -e "${Error}ERROR ${Off} Failed to delete"\ + "downloaded /tmp/$script-$shorttag.tar.gz!" + fi + # Delete extracted tmp files + if ! rm -r "/tmp/$script-$shorttag"; then + delerr=1 + echo -e "${Error}ERROR ${Off} Failed to delete"\ + "download /tmp/$script-$shorttag!" + fi + if [[ $delerr != 1 ]]; then + echo -e "\n$tag and changes.txt downloaded to:"\ + "$scriptpath" + echo -e "${Cyan}Do you want to stop this script"\ + "so you can run the new one?${Off} [y/n]" + read -r reply + if [[ ${reply,,} == "y" ]]; then exit; fi + fi + fi + else + echo -e "${Error}ERROR ${Off}"\ + "/tmp/$script-$shorttag.tar.gz not found!" + #ls /tmp | grep "$script" # debug + fi + fi + else + echo -e "${Error}ERROR ${Off} Failed to cd to /tmp!" + fi + fi + fi +fi + + +#------------------------------------------------------------------------------ +# Get list of installed SATA, SAS and M.2 NVMe/SATA drives, +# PCIe M.2 cards and connected Expansion Units. + +fixdrivemodel(){ + # Remove " 00Y" from end of Samsung/Lenovo SSDs + # To fix issue #13 + if [[ $1 =~ MZ.*" 00Y" ]]; then + hdmodel=$(printf "%s" "$1" | sed 's/ 00Y.*//') + fi + + # Brands that return "BRAND " and need "BRAND " removed. + if [[ $1 =~ ^[A-Za-z]{1,7}" ".* ]]; then + #see Smartmontools database in /var/lib/smartmontools/drivedb.db + 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 + fi +} + +getdriveinfo() { + # Skip removable drives (USB drives) + removable=$(cat "$1/removable") # Some DSM 7 RS models return 1 for internal drives! + if [[ $removable == "0" ]] || [[ $dsm -gt "6" ]]; then + # Get drive model and firmware version + hdmodel=$(cat "$1/device/model") + hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space + + # Fix dodgy model numbers + fixdrivemodel "$hdmodel" + + 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 +} + +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 (if M.2 drives found) + + if [[ $debug == "yes" ]]; then echo "debug 2: getcardmodel"; fi # debug + + if [[ ${#nvmelist[@]} -gt "0" ]]; then + cardmodel=$(synodisk --m2-card-model-get "$1") + + if [[ $debug == "yes" ]]; then echo "debug 3: cardmodel: $cardmodel"; fi # debug + + if [[ $cardmodel =~ M2D[0-9][0-9] ]]; then + + if [[ $debug == "yes" ]]; then echo "debug 4: cardmodel: M2D type"; fi # debug + + # M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + + if [[ $debug == "yes" ]]; then echo "debug 5: ${model}_${cardmodel,,}${version}.db"; fi # debug + + if [[ $debug == "yes" ]]; then echo "debug 5: cardlist qty ${#m2cardlist[@]}"; fi # debug + if [[ $debug == "yes" ]]; then echo "debug 5: carddblist qty ${#m2carddblist[@]}"; fi # debug + + elif [[ $cardmodel =~ E[0-9][0-9]+M.+ ]]; then + + if [[ $debug == "yes" ]]; then echo "debug 6: cardmodel: E type"; fi # debug + + # Ethernet + M2 adaptor card + m2carddblist+=("${model}_${cardmodel,,}${version}.db") # M.2 card's db file + m2cardlist+=("$cardmodel") # M.2 card + fi + fi +} + for d in /sys/block/*; do - #echo $d # debug case "$(basename -- "${d}")" in sd*|hd*) if [[ $d =~ [hs]d[a-z][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 + # 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 + getm2info "$d" "nvme" + # Get M.2 card model if in M.2 card - if [[ $nvmemodel ]] && [[ $nvmefw ]]; then - nvmelist+=("${nvmemodel},${nvmefw}") - fi - - #------------------------------------------------ - # Get M.2 card model - cardmodel=$(synodisk --m2-card-model-get "/dev/$d") - 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 - #------------------------------------------------ + if [[ $debug == "yes" ]]; then echo "debug 1: $d nvme"; fi # debug + getcardmodel "/dev/$d" fi fi ;; @@ -217,33 +442,12 @@ 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 + getm2info "$d" "nvc" + # Get M.2 card model if in M.2 card - #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 - - #------------------------------------------------ - # Get M.2 card model - cardmodel=$(synodisk --m2-card-model-get "/dev/$d") - 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 - #------------------------------------------------ + if [[ $debug == "yes" ]]; then echo "debug 1: $d SATA M.2 "; fi # debug + getcardmodel "/dev/$d" fi fi ;; @@ -255,7 +459,7 @@ done if [[ ${#hdlist[@]} -gt "0" ]]; then while IFS= read -r -d '' x; do hdds+=("$x") - done < <(printf "%s\0" "${hdlist[@]}" | sort -uz) + done < <(printf "%s\0" "${hdlist[@]}" | sort -uz) fi # Check hdds array isn't empty @@ -276,37 +480,32 @@ fi if [[ ${#nvmelist[@]} -gt "0" ]]; then while IFS= read -r -d '' x; do nvmes+=("$x") - done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz) + done < <(printf "%s\0" "${nvmelist[@]}" | sort -uz) 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 -#------------------------------------------------ - -#echo "M2 db list: ${m2carddblist[@]}" # debug -#echo "M2 card list: ${m2cardlist[@]}" # debug -#echo # debug - # M.2 card db files # Sort m2carddblist array into new m2carddbs array to remove duplicates if [[ ${#m2carddblist[@]} -gt "0" ]]; then while IFS= read -r -d '' x; do m2carddbs+=("$x") - done < <(printf "%s\0" "${m2carddblist[@]}" | sort -uz) + done < <(printf "%s\0" "${m2carddblist[@]}" | sort -uz) fi # M.2 cards @@ -314,50 +513,63 @@ fi if [[ ${#m2cardlist[@]} -gt "0" ]]; then while IFS= read -r -d '' x; do m2cards+=("$x") - done < <(printf "%s\0" "${m2cardlist[@]}" | sort -uz) + done < <(printf "%s\0" "${m2cardlist[@]}" | sort -uz) fi -#echo "M2 dbs: ${m2carddbs[@]}" # debug -#echo "M2 cards: ${m2cards[@]}" # debug -#echo # debug - # Check m2cards array isn't empty -if [[ ${#m2cards[@]} -gt "0" ]]; then - echo "M.2 card models found: ${#m2cards[@]}" +if [[ $m2 != "no" ]]; then + if [[ ${#m2cards[@]} -eq "0" ]]; then + echo -e "No M.2 cards found\n" + else + echo "M.2 card models found: ${#m2cards[@]}" + num="0" + while [[ $num -lt "${#m2cards[@]}" ]]; do + echo "${m2cards[num]}" + num=$((num +1)) + done + echo + fi +fi + + +# Expansion units +# Get list of connected expansion units (aka eunit/ebox) +path="/var/log/diskprediction" +# shellcheck disable=SC2012 +file=$(ls $path | tail -n1) +# shellcheck disable=SC2207 +eunitlist=($(grep -Eow "([FRD]XD?[0-9]{3,4})(RP|II|sas){0,2}" "$path/$file" | uniq)) + +# Sort eunitlist array into new eunits array to remove duplicates +if [[ ${#eunitlist[@]} -gt "0" ]]; then + while IFS= read -r -d '' x; do + eunits+=("$x") + done < <(printf "%s\0" "${eunitlist[@]}" | sort -uz) +fi + +# Check eunits array isn't empty +if [[ ${#eunits[@]} -eq "0" ]]; then + echo -e "No Expansion Units found\n" +else + #eunitexists="yes" + echo "Expansion Unit models found: ${#eunits[@]}" num="0" - while [[ $num -lt "${#m2cards[@]}" ]]; do - echo "${m2cards[num]}" + while [[ $num -lt "${#eunits[@]}" ]]; do + echo "${eunits[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 "$(dirname -- "$0";)/syno_hdd_db.test" ]]; then # In case I forget to remove the following - echo "Edit test db files? [y/n]:" - read -r answer - if [[ $answer == "y" ]]; then - if [[ $dsm -gt "6" ]]; then - x="72" # test - else - x="6" - fi - db1="/volume1/scripts/tmp/hdd/$x/${model}_host${version}.db" # test - db2="/volume1/scripts/tmp/hdd/$x/${model}_host${version}.db.new" # test - dbpath="/volume1/scripts/tmp/hdd/$x/" # test - fi -fi -#------------------------------------------------ +synoinfo="/etc.defaults/synoinfo.conf" if [[ ! -f "$db1" ]]; then echo -e "${Error}ERROR 3${Off} $db1 not found!" && exit 3; fi @@ -365,27 +577,32 @@ if [[ ! -f "$db1" ]]; then echo -e "${Error}ERROR 3${Off} $db1 not found!" && ex # new installs don't have a .db.new file -# Detect drive db type -if grep -F '{"disk_compatbility_info":' "$db1" >/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 +} -function backupdb() { +backupdb() { # Backup database file if needed if [[ ! -f "$1.bak" ]]; then + if [[ $(basename "$1") == "synoinfo.conf" ]]; then + echo "" >&2 + fi 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 @@ -396,18 +613,24 @@ function backupdb() { backupdb "$db1" || exit 5 -function updatedb() { +#------------------------------------------------------------------------------ +# Edit db files + +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\" @@ -433,7 +656,7 @@ function 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? @@ -442,9 +665,9 @@ function 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]}, @@ -459,7 +682,7 @@ function 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 @@ -473,6 +696,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 @@ -502,14 +741,20 @@ while [[ $num -lt "${#nvmes[@]}" ]]; do done +#------------------------------------------------------------------------------ +# Edit /etc.defaults/synoinfo.conf + +# Backup synoinfo.conf if needed +backupdb "$synoinfo" || exit 9 + # 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 @@ -517,8 +762,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 @@ -526,59 +771,110 @@ else 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})" +# Optionally disable "support_memory_compatibility" +smc=support_memory_compatibility +setting="$(get_key_value $synoinfo $smc)" +if [[ $ram == "yes" ]]; then if [[ $setting == "yes" ]]; then - echo -e "\nEnabled M.2 volume support." + # Disable support_memory_compatibility + sed -i "s/${smc}=\"yes\"/${smc}=\"no\"/" "$synoinfo" + setting="$(get_key_value "$synoinfo" $smc)" + if [[ $setting == "no" ]]; then + echo -e "\nDisabled support memory compatibility." + fi + fi +else + if [[ $setting == "no" ]]; then + # Enable support_memory_compatibility + sed -i "s/${smc}=\"no\"/${smc}=\"yes\"/" "$synoinfo" + setting="$(get_key_value "$synoinfo" $smc)" + if [[ $setting == "yes" ]]; then + echo -e "\nRe-enabled support memory compatibility." + fi fi -elif [[ $setting == "yes" ]]; then - echo -e "\nM.2 volume support already enabled." 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" +# 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 9${Off} Failed to backup $(basename -- "${file}")!" - exit 9 + echo -e "\n${Error}ERROR${Off} Failed to enable m2 volume support!" fi fi + fi +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=$url/drive_db_test_url=127.0.0.1/" "$file" - disabled="yes" - 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 "${Error}ERROR${Off} Failed to disable drive db auto updates!" - 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 + + # 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 "\n${Error}ERROR${Off} 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 + getdbtype "$db1" if [[ $dbtype -gt "6" ]];then # Show last 12 lines per drive + 4 lines=$(((db1Edits *12) +4)) @@ -589,7 +885,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