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