From 67ed9f433091d3e0cca11c0211d8c74a11584660 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 23 May 2023 19:52:19 +1000 Subject: [PATCH 1/3] Update syno_hdd_db.sh Fix bug #77 --- syno_hdd_db.sh | 64 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 5269e67..437a012 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -3,7 +3,6 @@ #-------------------------------------------------------------------------------------------------- # Github: https://github.com/007revad/Synology_HDD_db # Script verified at https://www.shellcheck.net/ -# 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. @@ -15,11 +14,11 @@ # /volume1/scripts/syno_hdd_db.sh # replace /volume1/scripts/ with path to script # # To run in a shell (replace /volume1/scripts/ with path to script): -# sudo /volume1/scripts/syno_hdd_db.sh +# sudo -i /volume1/scripts/syno_hdd_db.sh # or -# sudo /volume1/scripts/syno_hdd_db.sh -showedits +# sudo -i /volume1/scripts/syno_hdd_db.sh -showedits # or -# sudo /volume1/scripts/syno_hdd_db.sh -force -showedits +# sudo -i /volume1/scripts/syno_hdd_db.sh -force -showedits #-------------------------------------------------------------------------------------------------- # TODO @@ -149,12 +148,13 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.2.45" +scriptver="v2.2.46" script=Synology_HDD_db repo="007revad/Synology_HDD_db" # Check BASH variable is is non-empty and posix mode is off, else abort with error. [ "$BASH" ] && ! shopt -qo posix || { + printf \\a printf >&2 "This is a bash script, don't run it with sh\n" exit 1 } @@ -173,6 +173,9 @@ Cyan='\e[0;36m' Error='\e[41m' Off='\e[0m' +ding(){ + printf \\a +} usage(){ cat </dev/null; done - for f in "${dbpath}"*db.newr; do rm "$f">/dev/null; done + for f in "${dbpath}"*dbr; do + if [[ -f $f ]]; then + rm "$f" >/dev/null + fi + done + for f in "${dbpath}"*db.newr; do + if [[ -f $f ]]; then + rm "$f" >/dev/null + fi + done # Update .db files from Synology syno_disk_db_update --update @@ -520,7 +532,7 @@ fixdrivemodel(){ fi } -getdriveinfo() { +getdriveinfo(){ # $1 is /sys/block/sata1 etc # Skip USB drives @@ -543,7 +555,7 @@ getdriveinfo() { fi } -getm2info() { +getm2info(){ # $1 is /sys/block/nvme0n1 etc nvmemodel=$(cat "$1/device/model") nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space @@ -559,7 +571,7 @@ getm2info() { fi } -getcardmodel() { +getcardmodel(){ # Get M.2 card model (if M.2 drives found) # $1 is /dev/nvme0n1 etc if [[ ${#nvmelist[@]} -gt "0" ]]; then @@ -639,6 +651,7 @@ fi # Check hdds array isn't empty if [[ ${#hdds[@]} -eq "0" ]]; then + ding echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2 else echo -e "\nHDD/SSD models found: ${#hdds[@]}" @@ -757,6 +770,7 @@ done if [[ ${#db1list[@]} -eq "0" ]]; then + ding echo -e "${Error}ERROR 4${Off} Host db file not found!" && exit 4 fi # Don't check .db.new as new installs don't have a .db.new file @@ -778,7 +792,7 @@ getdbtype(){ } -backupdb() { +backupdb(){ # Backup database file if needed if [[ ! -f "$1.bak" ]]; then if [[ $(basename "$1") == "synoinfo.conf" ]]; then @@ -797,12 +811,14 @@ backupdb() { # Backup host database file if needed for i in "${!db1list[@]}"; do backupdb "${db1list[i]}" ||{ + ding echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db1list[i]}")!" exit 5 } done for i in "${!db2list[@]}"; do backupdb "${db2list[i]}" ||{ + ding echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db2list[i]}")!" exit 5 # maybe don't exit for .db.new file } @@ -821,10 +837,10 @@ editcount(){ fi } - editdb7(){ if [[ $1 == "append" ]]; then # model not in db file - if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # append + #if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # append + if sed -i "s/}}}/}},\"${hdmodel//\//\\/}\":{$fwstrng$default/" "$2"; then # append echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" editcount "$2" else @@ -833,7 +849,8 @@ editdb7(){ fi elif [[ $1 == "insert" ]]; then # model and default exists - if sed -i "s/\"$hdmodel\":{/\"$hdmodel\":{$fwstrng/" "$2"; then # insert firmware + #if sed -i "s/\"$hdmodel\":{/\"$hdmodel\":{$fwstrng/" "$2"; then # insert firmware + if sed -i "s/\"${hdmodel//\//\\/}\":{/\"${hdmodel//\//\\/}\":{$fwstrng/" "$2"; then # insert firmware echo -e "Updated ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" #editcount "$2" else @@ -842,7 +859,8 @@ editdb7(){ fi elif [[ $1 == "empty" ]]; then # db file only contains {} - if sed -i "s/{}/{\"$hdmodel\":{$fwstrng${default}}/" "$2"; then # empty + #if sed -i "s/{}/{\"$hdmodel\":{$fwstrng${default}}/" "$2"; then # empty + if sed -i "s/{}/{\"${hdmodel//\//\\/}\":{$fwstrng${default}}/" "$2"; then # empty echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" editcount "$2" else @@ -854,7 +872,7 @@ editdb7(){ } -updatedb() { +updatedb(){ hdmodel=$(printf "%s" "$1" | cut -d"," -f 1) fwrev=$(printf "%s" "$1" | cut -d"," -f 2) @@ -907,9 +925,11 @@ updatedb() { startstring="{\"success\":1,\"list\":\[" # example: # {"success":1,"list":[{"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, - if sed -i "s/$startstring/$startstring$string/" "$2"; then + #if sed -i "s/$startstring/$startstring$string/" "$2"; then + if sed -i "s/${startstring//\//\\/}/${startstring//\//\\/}$string/" "$2"; then echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" else + ding echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" >&2 exit 8 fi @@ -973,7 +993,7 @@ done # Edit /etc.defaults/synoinfo.conf # Backup synoinfo.conf if needed -backupdb "$synoinfo" || exit 9 +backupdb "$synoinfo" || ding && exit 9 # Optionally disable "support_disk_compatibility" sdc=support_disk_compatibility @@ -1074,7 +1094,8 @@ if [[ $m2 != "no" ]]; then enabled="" if [[ ! $setting ]]; then # Add support_m2_pool="yes" - echo 'support_m2_pool="yes"' >> "$synoinfo" + #echo 'support_m2_pool="yes"' >> "$synoinfo" + synosetkeyvalue "$synoinfo" "$smp" "yes" enabled="yes" elif [[ $setting == "no" ]]; then # Change support_m2_pool="no" to "yes" @@ -1104,7 +1125,8 @@ 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" + #echo 'drive_db_test_url="127.0.0.1"' >> "$synoinfo" + synosetkeyvalue "$synoinfo" "$dtu" "127.0.0.1" disabled="yes" elif [[ $url != "127.0.0.1" ]]; then # Edit drive_db_test_url= From a7cb0d1ffbe7745016e0463ad60e1a44b8c6ccc1 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 24 May 2023 02:09:43 +1000 Subject: [PATCH 2/3] Update README.md Updated reboot info --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b108b4c..ec09f34 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,9 @@ #### What the script does: * Optionally edits max supported memory to match the amount of memory installed, if installed memory is greater than the current max memory setting. * Checks that M.2 volume support is enabled (on models that have M.2 slots or PCIe slots). * Enables creating M.2 storage pools and volumes from within Storage Manager **(newer models only?)**. -* Makes DSM recheck disk compatibility so rebooting is not needed (DSM 7 only). -* Reminds you that you may need to reboot the Synology after running the script (DSM 6 only). +* Makes DSM recheck disk compatibility so rebooting is not needed if you don't have M.2 drives (DSM 7 only). + * **If you have M.2 drives you may need to reboot.** + * Reminds you that you may need to reboot the Synology after running the script (DSM 6 only). * Checks if there is a newer version of this script and offers to download it for you. * The new version available messages time out so they don't prevent the script running if it is scheduled to run unattended. @@ -40,7 +41,7 @@ ### When to run the script You would need to re-run the script after a DSM update. If you have DSM set to auto update the best option is to run the script every time the Synology boots, and the best way to do that is to setup a scheduled task to run the the script at boot-up. -**Note:** For DSM 6, after you first run the script you may need to reboot the Synology to see the effect of the changes. +**Note:** After you first run the script you may need to reboot the Synology to see the effect of the changes. ### Options when running the script From 6264173c7a6339afe76c3eadaa9a5aa2fe031fa2 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 24 May 2023 02:38:41 +1000 Subject: [PATCH 3/3] Update syno_hdd_db.sh --- syno_hdd_db.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 437a012..9cce579 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -148,7 +148,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.2.46" +scriptver="v2.2.47" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -805,6 +805,7 @@ backupdb(){ return 1 fi fi + return 0 } @@ -812,14 +813,14 @@ backupdb(){ for i in "${!db1list[@]}"; do backupdb "${db1list[i]}" ||{ ding - echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db1list[i]}")!" + #echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${db1list[i]}")!" exit 5 } done for i in "${!db2list[@]}"; do backupdb "${db2list[i]}" ||{ ding - echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${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 @@ -993,7 +994,10 @@ done # Edit /etc.defaults/synoinfo.conf # Backup synoinfo.conf if needed -backupdb "$synoinfo" || ding && exit 9 +backupdb "$synoinfo" ||{ + ding + exit 9 +} # Optionally disable "support_disk_compatibility" sdc=support_disk_compatibility @@ -1203,12 +1207,15 @@ if [[ -f /usr/syno/sbin/synostgdisk ]]; then # DSM 6.2.3 does not have synostgd status=$? if [[ $status -eq "0" ]]; then echo -e "\nDSM successfully checked disk compatibility." + echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." else # 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 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." + #if [[ $m2 != "no" ]] && [[ ${#m2cards[@]} -gt "0" ]]; then + echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." + #fi fi fi fi