Browse Source

Update syno_hdd_db.sh

- Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4. This will also ensure the script still works if:
    - Synology append different numbers to the db file names in DSM 8 etc.
    - The detected NAS model name does not match the .db files' model name.
- Now backs up the .db.new files (as well as the .db files).
- Now shows max memory in GB instead of MB.
- Now shows status of "Support disk compatibility" setting even if it wasn't changed.
- Now shows status of "Support memory compatibility" setting even if it wasn't changed.
pull/63/head
Dave Russell 3 years ago
committed by GitHub
parent
commit
99e513c621
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 167
      syno_hdd_db.sh

167
syno_hdd_db.sh

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1083,SC2054,SC2121 # shellcheck disable=SC1083,SC2054,SC2121,SC2207
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
# Github: https://github.com/007revad/Synology_HDD_db # Github: https://github.com/007revad/Synology_HDD_db
# Script verified at https://www.shellcheck.net/ # Script verified at https://www.shellcheck.net/
@ -31,6 +31,17 @@
# DONE # DONE
# Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4. # Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4.
# This will also ensure the script still works if:
# Synology append different numbers to the db file names in DSM 8 etc.
# The detected NAS model name does not match the .db files' model name.
#
# Now backs up the .db.new files (as well as the .db files).
#
# Now shows max memory in GB instead of MB.
#
# Now shows status of "Support disk compatibility" setting even if it wasn't changed.
#
# Now shows status of "Support memory compatibility" setting even if it wasn't changed.
# #
# #
# Improved shell output when editing max memory setting. # Improved shell output when editing max memory setting.
@ -174,7 +185,7 @@ EOF
# Save options used # Save options used
args="$@" args="$*"
# Check for flags with getopt # Check for flags with getopt
@ -374,14 +385,12 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
# Delete downloaded .tar.gz file # Delete downloaded .tar.gz file
if ! rm "/tmp/$script-$shorttag.tar.gz"; then if ! rm "/tmp/$script-$shorttag.tar.gz"; then
#delerr=1
echo -e "${Error}ERROR ${Off} Failed to delete"\ echo -e "${Error}ERROR ${Off} Failed to delete"\
"downloaded /tmp/$script-$shorttag.tar.gz!" "downloaded /tmp/$script-$shorttag.tar.gz!"
fi fi
# Delete extracted tmp files # Delete extracted tmp files
if ! rm -r "/tmp/$script-$shorttag"; then if ! rm -r "/tmp/$script-$shorttag"; then
#delerr=1
echo -e "${Error}ERROR ${Off} Failed to delete"\ echo -e "${Error}ERROR ${Off} Failed to delete"\
"downloaded /tmp/$script-$shorttag!" "downloaded /tmp/$script-$shorttag!"
fi fi
@ -531,7 +540,6 @@ for d in /sys/block/*; do
fi fi
;; ;;
nvc*) # M.2 SATA drives (in PCIe card only?) nvc*) # M.2 SATA drives (in PCIe card only?)
#if [[ $d =~ nvc[0-9][0-9]?p[0-9][0-9]?$ ]]; then
if [[ $d =~ nvc[0-9][0-9]?$ ]]; then if [[ $d =~ nvc[0-9][0-9]?$ ]]; then
if [[ $m2 != "no" ]]; then if [[ $m2 != "no" ]]; then
getm2info "$d" "nvc" getm2info "$d" "nvc"
@ -629,7 +637,6 @@ fi
path="/var/log/diskprediction" path="/var/log/diskprediction"
# shellcheck disable=SC2012 # shellcheck disable=SC2012
file=$(ls $path | tail -n1) 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)) 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 # Sort eunitlist array into new eunits array to remove duplicates
@ -658,18 +665,30 @@ fi
# Check databases and add our drives if needed # Check databases and add our drives if needed
dbpath="/var/lib/disk-compatibility/" dbpath="/var/lib/disk-compatibility/"
db1list=("$(find "$dbpath" -maxdepth 1 -name "*_host*.db")")
db2list=("$(find "$dbpath" -maxdepth 1 -name "*_host*.db.new")") # Host db files
db1list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db"))
db2list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db.new"))
# Expansion Unit db files
for i in "${!eunits[@]}"; do
eunitdb1list=($(find "$dbpath" -maxdepth 1 -name "${eunits[i],,}*.db"))
eunitdb2list=($(find "$dbpath" -maxdepth 1 -name "${eunits[i],,}*.db.new"))
done
# M.2 Card db files
for i in "${!m2cards[@]}"; do
m2carddb1list=($(find "$dbpath" -maxdepth 1 -name "*_${m2cards[i],,}*.db"))
m2carddb2list=($(find "$dbpath" -maxdepth 1 -name "*_${m2cards[i],,}*.db.new"))
done
synoinfo="/etc.defaults/synoinfo.conf" synoinfo="/etc.defaults/synoinfo.conf"
#if [[ ! -f "$db1" ]]; then echo -e "${Error}ERROR 3${Off} $db1 not found!" && exit 3; fi
if [[ ${#db1list[@]} -eq "0" ]]; then if [[ ${#db1list[@]} -eq "0" ]]; then
echo -e "${Error}ERROR 4${Off} Host db file not found!" && exit 4 echo -e "${Error}ERROR 4${Off} Host db file not found!" && exit 4
fi fi
##if [[ ! -f "$db2" ]]; then echo -e "${Error}ERROR 4${Off} $db2 not found!" && exit 4; fi # Don't check .db.new as new installs don't have a .db.new file
## new installs don't have a .db.new file
getdbtype(){ getdbtype(){
@ -705,9 +724,17 @@ backupdb() {
# Backup host database file if needed # Backup host database file if needed
#backupdb "$db1" || exit 5 for i in "${!db1list[@]}"; do
backupdb "${db1list[i]}" ||{
echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db1list[i]}")!"
exit 5
}
done
for i in "${!db2list[@]}"; do for i in "${!db2list[@]}"; do
backupdb "${db2list[i]}" || exit 5 backupdb "${db2list[i]}" ||{
echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db2list[i]}")!"
exit 5 # maybe don't exit for .db.new file
}
done done
@ -716,10 +743,8 @@ done
editcount(){ editcount(){
# Count drives added to host db files # Count drives added to host db files
#if [[ $1 == "$db1" ]]; then
if [[ $1 =~ .*\.db$ ]]; then if [[ $1 =~ .*\.db$ ]]; then
db1Edits=$((db1Edits +1)) db1Edits=$((db1Edits +1))
#elif [[ $1 == "$db2" ]]; then
elif [[ $1 =~ .*\.db.new ]]; then elif [[ $1 =~ .*\.db.new ]]; then
db2Edits=$((db2Edits +1)) db2Edits=$((db2Edits +1))
fi fi
@ -785,17 +810,17 @@ updatedb() {
if grep '"disk_compatbility_info":{}' "$2" >/dev/null; then if grep '"disk_compatbility_info":{}' "$2" >/dev/null; then
# Replace "disk_compatbility_info":{} with "disk_compatbility_info":{"WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}} # Replace "disk_compatbility_info":{} with "disk_compatbility_info":{"WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}}
echo "Edit empty db file" #echo "Edit empty db file:" # debug
editdb7 "empty" "$2" editdb7 "empty" "$2"
elif grep '"'"$hdmodel"'":' "$2" >/dev/null; then elif grep '"'"$hdmodel"'":' "$2" >/dev/null; then
# Replace "WD40PURX-64GVNY0":{ with "WD40PURX-64GVNY0":{"80.00A80":{ ... }}}, # Replace "WD40PURX-64GVNY0":{ with "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},
echo "Insert firmware version" #echo "Insert firmware version:" # debug
editdb7 "insert" "$2" editdb7 "insert" "$2"
else else
# Add "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}} # Add "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}
echo "Append drive and firmware" #echo "Append drive and firmware:" # debug
editdb7 "append" "$2" editdb7 "append" "$2"
fi fi
@ -807,24 +832,10 @@ updatedb() {
string="{\"model\":\"${hdmodel}\",\"firmware\":\"\",\"rec_intvl\":\[1\]}," string="{\"model\":\"${hdmodel}\",\"firmware\":\"\",\"rec_intvl\":\[1\]},"
# {"success":1,"list":[ # {"success":1,"list":[
startstring="{\"success\":1,\"list\":\[" startstring="{\"success\":1,\"list\":\["
#echo "$startstring" >&2 # debug
#echo "$string" >&2 # debug
#echo >&2 # debug
# example: # example:
# {"success":1,"list":[{"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, # {"success":1,"list":[{"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]},
if sed -ir "s/$startstring/$startstring$string/" "$2"; then if sed -ir "s/$startstring/$startstring$string/" "$2"; then
echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" 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
#editcount "$2"
else else
echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" >&2 echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" >&2
exit 8 exit 8
@ -836,10 +847,6 @@ updatedb() {
# HDDs and SATA SSDs # HDDs and SATA SSDs
num="0" num="0"
while [[ $num -lt "${#hdds[@]}" ]]; do while [[ $num -lt "${#hdds[@]}" ]]; do
#updatedb "${hdds[$num]}" "$db1"
#if [[ -f "$db2" ]]; then
# updatedb "${hdds[$num]}" "$db2"
#fi
for i in "${!db1list[@]}"; do for i in "${!db1list[@]}"; do
updatedb "${hdds[$num]}" "${db1list[i]}" updatedb "${hdds[$num]}" "${db1list[i]}"
done done
@ -849,16 +856,13 @@ while [[ $num -lt "${#hdds[@]}" ]]; do
#------------------------------------------------ #------------------------------------------------
# Expansion Units # Expansion Units
num2="0" for i in "${!eunitdb1list[@]}"; do
while [[ $num2 -lt "${#eunits[@]}" ]]; do backupdb "${eunitdb1list[i]}" &&\
eudb="${dbpath}${eunits[$num2],,}${version}.db" updatedb "${hdds[$num]}" "${eunitdb1list[i]}"
if [[ -f "$eudb" ]]; then done
backupdb "$eudb" &&\ for i in "${!eunitdb2list[@]}"; do
updatedb "${hdds[$num]}" "$eudb" backupdb "${eunitdb2list[i]}" &&\
else updatedb "${hdds[$num]}" "${eunitdb2list[i]}"
echo -e "${Error}ERROR 11${Off} $eudb not found!"
fi
num2=$((num2 +1))
done done
#------------------------------------------------ #------------------------------------------------
@ -868,28 +872,22 @@ done
# M.2 NVMe/SATA drives # M.2 NVMe/SATA drives
num="0" num="0"
while [[ $num -lt "${#nvmes[@]}" ]]; do while [[ $num -lt "${#nvmes[@]}" ]]; do
#updatedb "${hdds[$num]}" "$db1"
#if [[ -f "$db2" ]]; then
# updatedb "${hdds[$num]}" "$db2"
#fi
for i in "${!db1list[@]}"; do for i in "${!db1list[@]}"; do
updatedb "${nvmes[$num]}" "$i" updatedb "${nvmes[$num]}" "${db1list[i]}"
done done
for i in "${!db2list[@]}"; do for i in "${!db2list[@]}"; do
updatedb "${nvmes[$num]}" "$i" updatedb "${nvmes[$num]}" "${db2list[i]}"
done done
#------------------------------------------------ #------------------------------------------------
# M.2 adaptor cards # M.2 adaptor cards
num2="0" for i in "${!m2carddb1list[@]}"; do
while [[ $num2 -lt "${#m2carddbs[@]}" ]]; do backupdb "${m2carddb1list[i]}" &&\
if [[ -f "${dbpath}${m2carddbs[$num2]}" ]]; then updatedb "${nvmes[$num]}" "${m2carddb1list[i]}"
backupdb "${dbpath}${m2carddbs[$num2]}" &&\ done
updatedb "${nvmes[$num]}" "${dbpath}${m2carddbs[$num2]}" for i in "${!m2carddb2list[@]}"; do
else backupdb "${m2carddb2list[i]}" &&\
echo -e "${Error}ERROR 10${Off} ${m2carddbs[$num2]} not found!" updatedb "${nvmes[$num]}" "${m2carddb2list[i]}"
fi
num2=$((num2 +1))
done done
#------------------------------------------------ #------------------------------------------------
@ -909,22 +907,24 @@ setting="$(get_key_value $synoinfo $sdc)"
if [[ $force == "yes" ]]; then if [[ $force == "yes" ]]; then
if [[ $setting == "yes" ]]; then if [[ $setting == "yes" ]]; then
# Disable support_disk_compatibility # Disable support_disk_compatibility
#sed -i "s/${sdc}=\"yes\"/${sdc}=\"no\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$sdc" "no" synosetkeyvalue "$synoinfo" "$sdc" "no"
setting="$(get_key_value "$synoinfo" $sdc)" setting="$(get_key_value "$synoinfo" $sdc)"
if [[ $setting == "no" ]]; then if [[ $setting == "no" ]]; then
echo -e "\nDisabled support disk compatibility." echo -e "\nDisabled support disk compatibility."
fi fi
elif [[ $setting == "no" ]]; then
echo -e "\nSupport disk compatibility already disabled."
fi fi
else else
if [[ $setting == "no" ]]; then if [[ $setting == "no" ]]; then
# Enable support_disk_compatibility # Enable support_disk_compatibility
#sed -i "s/${sdc}=\"no\"/${sdc}=\"yes\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$sdc" "yes" synosetkeyvalue "$synoinfo" "$sdc" "yes"
setting="$(get_key_value "$synoinfo" $sdc)" setting="$(get_key_value "$synoinfo" $sdc)"
if [[ $setting == "yes" ]]; then if [[ $setting == "yes" ]]; then
echo -e "\nRe-enabled support disk compatibility." echo -e "\nRe-enabled support disk compatibility."
fi fi
elif [[ $setting == "yes" ]]; then
echo -e "\nSupport disk compatibility already enabled."
fi fi
fi fi
@ -935,26 +935,28 @@ setting="$(get_key_value $synoinfo $smc)"
if [[ $ram == "yes" ]]; then if [[ $ram == "yes" ]]; then
if [[ $setting == "yes" ]]; then if [[ $setting == "yes" ]]; then
# Disable support_memory_compatibility # Disable support_memory_compatibility
#sed -i "s/${smc}=\"yes\"/${smc}=\"no\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$smc" "no" synosetkeyvalue "$synoinfo" "$smc" "no"
setting="$(get_key_value "$synoinfo" $smc)" setting="$(get_key_value "$synoinfo" $smc)"
if [[ $setting == "no" ]]; then if [[ $setting == "no" ]]; then
echo -e "\nDisabled support memory compatibility." echo -e "\nDisabled support memory compatibility."
fi fi
elif [[ $setting == "no" ]]; then
echo -e "\nSupport memory compatibility already disabled."
fi fi
else else
if [[ $setting == "no" ]]; then if [[ $setting == "no" ]]; then
# Enable support_memory_compatibility # Enable support_memory_compatibility
#sed -i "s/${smc}=\"no\"/${smc}=\"yes\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$smc" "yes" synosetkeyvalue "$synoinfo" "$smc" "yes"
setting="$(get_key_value "$synoinfo" $smc)" setting="$(get_key_value "$synoinfo" $smc)"
if [[ $setting == "yes" ]]; then if [[ $setting == "yes" ]]; then
echo -e "\nRe-enabled support memory compatibility." echo -e "\nRe-enabled support memory compatibility."
fi fi
elif [[ $setting == "yes" ]]; then
echo -e "\nSupport memory compatibility already enabled."
fi fi
fi fi
# Optioanlly set mem_max_mb to the amount of installed memory # Optionally set mem_max_mb to the amount of installed memory
if [[ $ram == "yes" ]]; then if [[ $ram == "yes" ]]; then
# Get total amount of installed memory # Get total amount of installed memory
IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep -i 'size') IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep -i 'size')
@ -982,7 +984,9 @@ if [[ $ram == "yes" ]]; then
echo -e "\n${Error}ERROR${Off} Failed to change max memory!" echo -e "\n${Error}ERROR${Off} Failed to change max memory!"
fi fi
elif [[ $setting == "$ramtotal" ]]; then elif [[ $setting == "$ramtotal" ]]; then
echo -e "\nMax memory already set to $ramtotal MB." #echo -e "\nMax memory already set to $ramtotal MB."
ramgb=$((ramtotal / 1024))
echo -e "\nMax memory already set to $ramgb GB."
fi fi
fi fi
@ -1000,7 +1004,6 @@ if [[ $m2 != "no" ]]; then
enabled="yes" enabled="yes"
elif [[ $setting == "no" ]]; then elif [[ $setting == "no" ]]; then
# Change support_m2_pool="no" to "yes" # Change support_m2_pool="no" to "yes"
#sed -i "s/${smp}=\"no\"/${smp}=\"yes\"/" "$synoinfo"
synosetkeyvalue "$synoinfo" "$smp" "yes" synosetkeyvalue "$synoinfo" "$smp" "yes"
enabled="yes" enabled="yes"
elif [[ $setting == "yes" ]]; then elif [[ $setting == "yes" ]]; then
@ -1031,7 +1034,6 @@ if [[ $nodbupdate == "yes" ]]; then
disabled="yes" disabled="yes"
elif [[ $url != "127.0.0.1" ]]; then elif [[ $url != "127.0.0.1" ]]; then
# Edit drive_db_test_url= # Edit drive_db_test_url=
#sed -i "s/drive_db_test_url=.*/drive_db_test_url=\"127.0.0.1\"/" "$synoinfo" >/dev/null
synosetkeyvalue "$synoinfo" "$dtu" "127.0.0.1" synosetkeyvalue "$synoinfo" "$dtu" "127.0.0.1"
disabled="yes" disabled="yes"
fi fi
@ -1052,7 +1054,6 @@ else
#if [[ $url == "127.0.0.1" ]]; then #if [[ $url == "127.0.0.1" ]]; then
if [[ $url ]]; then if [[ $url ]]; then
# Delete "drive_db_test_url=127.0.0.1" line (inc. line break) # Delete "drive_db_test_url=127.0.0.1" line (inc. line break)
#sed -i "/drive_db_test_url=\"127.0.0.1\"/d" "/etc.defaults/synoinfo.conf"
sed -i "/drive_db_test_url=*/d" "/etc.defaults/synoinfo.conf" sed -i "/drive_db_test_url=*/d" "/etc.defaults/synoinfo.conf"
# Check if we re-enabled drive db auto updates # Check if we re-enabled drive db auto updates
@ -1073,8 +1074,8 @@ fi
# Show the changes # Show the changes
if [[ ${showedits,,} == "yes" ]]; then if [[ ${showedits,,} == "yes" ]]; then
for i in "${!db1list[@]}"; do if [[ ${#db1list[@]} -gt "0" ]]; then
getdbtype "$i" getdbtype "${db1list[0]}"
if [[ $dbtype -gt "6" ]]; then if [[ $dbtype -gt "6" ]]; then
# Show 11 lines after hdmodel line # Show 11 lines after hdmodel line
lines=11 lines=11
@ -1084,28 +1085,19 @@ if [[ ${showedits,,} == "yes" ]]; then
fi fi
# HDDs/SSDs # HDDs/SSDs
if [[ ${#hdds[@]} -gt "0" ]]; then for i in "${!hdds[@]}"; do
num="0" hdmodel=$(printf "%s" "${hdds[i]}" | cut -d"," -f 1)
while [[ $num -lt "${#hdds[@]}" ]]; do
hdmodel=$(printf "%s" "${hdds[$num]}" | cut -d"," -f 1)
echo echo
jq . "$i" | grep -A "$lines" "$hdmodel" jq . "${db1list[0]}" | grep -A "$lines" "$hdmodel"
num=$((num +1))
done done
fi
# NVMe drives # NVMe drives
if [[ ${#nvmes[@]} -gt "0" ]]; then for i in "${!nvmes[@]}"; do
num="0" hdmodel=$(printf "%s" "${nvmes[i]}" | cut -d"," -f 1)
while [[ $num -lt "${#nvmes[@]}" ]]; do
nvmemodel=$(printf "%s" "${nvmes[$num]}" | cut -d"," -f 1)
echo echo
jq . "$i" | grep -A "$lines" "$nvmemodel" jq . "${db1list[0]}" | grep -A "$lines" "$hdmodel"
num=$((num +1))
done done
fi fi
done
fi fi
@ -1117,6 +1109,7 @@ if [[ -f /usr/syno/sbin/synostgdisk ]]; then # DSM 6.2.3 does not have synostgd
echo -e "\nDSM successfully checked disk compatibility." echo -e "\nDSM successfully checked disk compatibility."
else else
# Ignore DSM 6.2.4 as it returns 255 for "synostgdisk --check-all-disks-compatibility" # Ignore DSM 6.2.4 as it returns 255 for "synostgdisk --check-all-disks-compatibility"
# and DSM 6.2.3 and lower have no synostgdisk command
if [[ $dsm -gt "6" ]]; then if [[ $dsm -gt "6" ]]; then
echo -e "\nDSM ${Red}failed${Off} to check disk compatibility with exit code $status" echo -e "\nDSM ${Red}failed${Off} to check disk compatibility with exit code $status"
echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes."

Loading…
Cancel
Save