From 138fc73a434cab6c3bb76731981a9eb9f41f9be4 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 31 May 2023 20:29:55 +1000 Subject: [PATCH 01/18] Update CHANGES.txt --- CHANGES.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 64f312c..0f4d343 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,9 @@ +v2.3.48 +- Now the script reloads itself after updating. +- Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. + - Autoupdate adds success/failed entry to the DSM system log. +- Added -w, --wdda option to disable WDDA. + v2.2.47 - Updated reboot info in readme. - Added reboot message for DSM 7. From a33689af0539059f07d82944ad598f75555b0428 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 31 May 2023 20:36:16 +1000 Subject: [PATCH 02/18] Update syno_hdd_db.sh - Now the script reloads itself after updating. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - Autoupdate logs update success or errors to DSM system log. - Added -w, --wdda option to disable WDDA. --- syno_hdd_db.sh | 152 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 115 insertions(+), 37 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 9cce579..df51eb2 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -29,13 +29,19 @@ # It's also parsed and checked and probably in some cases it could be more critical to patch that one instead. # DONE +# Now the script reloads itself after updating. +# +# Added --autoupdate option to auto update synology_hdd_db x days after new version released. +# Autoupdate logs update success or errors to DSM system log. +# Added -w, --wdda option to disable WDDA +# +# # Added --restore info to --help # # Updated restore option to download the latest db files from Synology # # Now warns you if you try to run it in sh with "sh scriptname.sh" # -# # Fixed DSM 6 bug where the drives were being duplicated in the .db files each time the script was run. # # Fixed DSM 6 bug where the .db files were being duplicated as .dbr each time the db files were edited. @@ -148,7 +154,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.2.47" +scriptver="v2.3.48" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -184,15 +190,19 @@ $script $scriptver - by 007revad Usage: $(basename "$0") [options] Options: - -s, --showedits Show edits made to _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 - --restore Undo all changes made by the script - -h, --help Show this help message - -v, --version Show the script version - + -s, --showedits Show edits made to _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 + -w, --wdda Disable WD WDDA + --restore Undo all changes made by the script + --autoupdate=[age] Auto update script (useful when script is scheduled) + 'age' is how old a release must be in days before + auto-updating, and must be a number: 0 or greater + -h, --help Show this help message + -v, --version Show the script version + EOF exit 0 } @@ -209,12 +219,13 @@ EOF # Save options used -args="$*" +args=("$@") # Check for flags with getopt -if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \ - -l restore,showedits,noupdate,nodbupdate,m2,force,ram,help,version,debug -- "$@")"; then +if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ + restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,autoupdate:,help,version,debug \ + -- "$@")"; then eval set -- "$options" while true; do case "${1,,}" in @@ -237,6 +248,18 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \ -r|--ram) # Disable "support_memory_compatibility" ram=yes ;; + -w|--wdda) # Disable "support_memory_compatibility" + wdda=no + ;; + --autoupdate) # Auto update script + autoupdate=yes + if [[ $2 =~ ^[0-9]+$ ]]; then + delay="$2" + shift + else + delay="0" + fi + ;; -h|--help) # Show usage options usage ;; @@ -320,7 +343,7 @@ elif [[ $model =~ '-j'$ ]]; then # GitHub issue #2 fi # Show options used -echo "Using options: $args" +echo "Using options: ${args[*]}" #echo "" # To keep output readable @@ -328,18 +351,37 @@ echo "Using options: $args" #------------------------------------------------------------------------------ # Check latest release with GitHub API -get_latest_release(){ - # Curl timeout options: - # https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout - curl --silent -m 10 --connect-timeout 5 \ - "https://api.github.com/repos/$1/releases/latest" | - grep '"tag_name":' | # Get tag line - sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +syslog_set(){ + if [[ ${1,,} == "info" ]] || [[ ${1,,} == "warn" ]] || [[ ${1,,} == "err" ]]; then + if [[ $autoupdate == "yes" ]]; then + # Add entry to Synology system log + synologset1 sys "$1" 0x11100000 "$2" + fi + fi } -tag=$(get_latest_release "$repo") + +# Get latest release info +# Curl timeout options: +# https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout +release=$(curl --silent -m 10 --connect-timeout 5 \ + "https://api.github.com/repos/$repo/releases/latest") + +# Release version +tag=$(echo "$release" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') shorttag="${tag:1}" -#scriptpath=$(dirname -- "$0") + +# Release published date +published=$(echo "$release" | grep '"published_at":' | sed -E 's/.*"([^"]+)".*/\1/') +published="${published:0:10}" +published=$(date -d "$published" '+%s') + +# Today's date +now=$(date '+%s') + +# Days since release published +age=$(((now - published)/(60*60*24))) + # Get script location # https://stackoverflow.com/questions/59895/ @@ -368,8 +410,17 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | 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 [[ $autoupdate == "yes" ]]; then + if [[ $age -gt "$delay" ]] || [[ $age -eq "$delay" ]]; then + echo "Downloading $tag" + reply=y + else + echo "Skipping as $tag is less than $delay days old." + fi + else + echo -e "${Cyan}Do you want to download $tag now?${Off} [y/n]" + read -r -t 30 reply + fi if [[ ${reply,,} == "y" ]]; then if cd /tmp; then url="https://github.com/$repo/archive/refs/tags/$tag.tar.gz" @@ -377,36 +428,40 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | then echo -e "${Error}ERROR ${Off} Failed to download"\ "$script-$shorttag.tar.gz!" + syslog_set warn "$script $tag failed to download" else if [[ -f /tmp/$script-$shorttag.tar.gz ]]; then # Extract tar file to /tmp/ if ! tar -xf "/tmp/$script-$shorttag.tar.gz" -C "/tmp"; then echo -e "${Error}ERROR ${Off} Failed to"\ "extract $script-$shorttag.tar.gz!" + syslog_set warn "$script failed to extract $script-$shorttag.tar.gz!" else # Copy new script sh files to script location if ! cp -p "/tmp/$script-$shorttag/"*.sh "$scriptpath"; then copyerr=1 echo -e "${Error}ERROR ${Off} Failed to copy"\ "$script-$shorttag .sh file(s) to:\n $scriptpath" + syslog_set warn "$script failed to copy $tag to script location" else - # Set permsissions on CHANGES.txt + # Set permsissions on script sh files if ! chmod 744 "$scriptpath/"*.sh ; then permerr=1 echo -e "${Error}ERROR ${Off} Failed to set permissions on:" echo "$scriptpath *.sh file(s)" + syslog_set warn "$script failed to set permissions on $tag" fi fi # Copy new CHANGES.txt file to script location if ! cp -p "/tmp/$script-$shorttag/CHANGES.txt" "$scriptpath"; then - copyerr=1 + if [[ $autoupdate != "yes" ]]; then copyerr=1; fi echo -e "${Error}ERROR ${Off} Failed to copy"\ "$script-$shorttag/CHANGES.txt to:\n $scriptpath" else # Set permsissions on CHANGES.txt if ! chmod 744 "$scriptpath/CHANGES.txt"; then - permerr=1 + if [[ $autoupdate != "yes" ]]; then permerr=1; fi echo -e "${Error}ERROR ${Off} Failed to set permissions on:" echo "$scriptpath/CHANGES.txt" fi @@ -416,32 +471,38 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | if ! rm "/tmp/$script-$shorttag.tar.gz"; then echo -e "${Error}ERROR ${Off} Failed to delete"\ "downloaded /tmp/$script-$shorttag.tar.gz!" + syslog_set warn "$script update failed to delete tmp files" fi # Delete extracted tmp files if ! rm -r "/tmp/$script-$shorttag"; then echo -e "${Error}ERROR ${Off} Failed to delete"\ "downloaded /tmp/$script-$shorttag!" + syslog_set warn "$script update failed to delete tmp files" fi # Notify of success (if there were no errors) if [[ $copyerr != 1 ]] && [[ $permerr != 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 + echo -e "\n$tag and changes.txt downloaded to: ${scriptpath}\n" + syslog_set info "$script successfully updated to $tag" + + # Reload script + printf -- '-%.0s' {1..79}; echo # print 79 - + exec "$0" "${args[@]}" + else + syslog_set warn "$script update to $tag had errors" fi fi else echo -e "${Error}ERROR ${Off}"\ "/tmp/$script-$shorttag.tar.gz not found!" #ls /tmp | grep "$script" # debug + syslog_set warn "/tmp/$script-$shorttag.tar.gz not found" fi fi else echo -e "${Error}ERROR ${Off} Failed to cd to /tmp!" + syslog_set warn "$script update failed to cd to /tmp" fi fi fi @@ -813,14 +874,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 @@ -1169,6 +1230,23 @@ else fi +# Optionally disable "support_wdda" +wdda=support_wdda +setting="$(get_key_value $synoinfo $wdda)" +if [[ $wdda == "no" ]]; then + if [[ $setting == "yes" ]]; then + # Disable support_memory_compatibility + synosetkeyvalue "$synoinfo" "$wdda" "no" + setting="$(get_key_value "$synoinfo" $wdda)" + if [[ $setting == "no" ]]; then + echo -e "\nDisabled support WDDA." + fi + elif [[ $setting == "no" ]]; then + echo -e "\nSupport WDDA already disabled." + fi +fi + + #------------------------------------------------------------------------------ # Finished From 2b63ff2eaacc071571816dc7a4a48e42c95f290f Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Wed, 31 May 2023 20:36:42 +1000 Subject: [PATCH 03/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0f4d343..a5f3fb4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,7 +1,7 @@ v2.3.48 - Now the script reloads itself after updating. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - - Autoupdate adds success/failed entry to the DSM system log. + - Autoupdate logs update success or errors to DSM system log. - Added -w, --wdda option to disable WDDA. v2.2.47 From 11bd2b03f740a272095adb61e74848847d779b28 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Sun, 11 Jun 2023 20:14:50 +1000 Subject: [PATCH 04/18] Update CHANGES.txt --- CHANGES.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index a5f3fb4..92f3bfa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,15 @@ -v2.3.48 +v2.3.49 +- Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). +- Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). +- Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). +- Fixed error if /run/synostorage/disks/nvme0n1/m2_pool_support doesn't exist yet (for DSM 7.2). +- Fixed drive db update still being disabled in /etc/synoinfo.conf after script run without -n or --noupdate option. +- Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. +- Fixed permissions on restored files being incorrect after script run with --restore option. +- Fixed permissions on backup files. +- Now skips checking the amount of installed memory in DSM 6 (because it was never working). - Now the script reloads itself after updating. +- Added "You may need to reboot" message when NVMe drives were detected. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - Autoupdate logs update success or errors to DSM system log. - Added -w, --wdda option to disable WDDA. From ddedd6e72ba9b75ec626c2cde265cddb6f3e771e Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Sun, 11 Jun 2023 20:15:04 +1000 Subject: [PATCH 05/18] Update syno_hdd_db.sh v2.3.49 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). - Fixed error if /run/synostorage/disks/nvme0n1/m2_pool_support doesn't exist yet (for DSM 7.2). - Fixed drive db update still being disabled in /etc/synoinfo.conf after script run without -n or --noupdate option. - Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. - Fixed permissions on restored files being incorrect after script run with --restore option. - Fixed permissions on backup files. - Now skips checking the amount of installed memory in DSM 6 (because it was never working). - Now the script reloads itself after updating. - Added "You may need to reboot" message when NVMe drives were detected. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - Autoupdate logs update success or errors to DSM system log. - Added -w, --wdda option to disable WDDA. --- syno_hdd_db.sh | 189 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 63 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index df51eb2..af495cc 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -27,12 +27,36 @@ # # 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. +# +# Solve issue of --restore option restoring files that were backed up with older DSM version. # DONE +# +# Added "You may need to reboot" message when NVMe drives were detected. +# +# Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). +# +# Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). +# +# Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). +# +# Fixed error if /run/synostorage/disks/nvme0n1/m2_pool_support doesn't exist yet (for DSM 7.2). +# +# Fixed drive db update still being disabled in /etc/synoinfo.conf after script run without -n or --noupdate option. +# +# Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. +# +# Fixed permissions on restored files being incorrect after script run with --restore option. +# +# Fixed permissions on backup files. +# +# Now skips checking the amount of installed memory in DSM 6 (because it was never working). +# # Now the script reloads itself after updating. # -# Added --autoupdate option to auto update synology_hdd_db x days after new version released. +# Added --autoupdate=AGE option to auto update synology_hdd_db x days after new version released. # Autoupdate logs update success or errors to DSM system log. +# # Added -w, --wdda option to disable WDDA # # @@ -154,7 +178,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.48" +scriptver="v2.3.49" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -190,18 +214,18 @@ $script $scriptver - by 007revad Usage: $(basename "$0") [options] Options: - -s, --showedits Show edits made to _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 - -w, --wdda Disable WD WDDA - --restore Undo all changes made by the script - --autoupdate=[age] Auto update script (useful when script is scheduled) - 'age' is how old a release must be in days before - auto-updating, and must be a number: 0 or greater - -h, --help Show this help message - -v, --version Show the script version + -s, --showedits Show edits made to _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 (DSM 7.x only) + -w, --wdda Disable WD WDDA + --restore Undo all changes made by the script + --autoupdate=AGE Auto update script (useful when script is scheduled) + AGE is how many days old a release must be before + auto-updating. AGE must be a number: 0 or greater + -h, --help Show this help message + -v, --version Show the script version EOF exit 0 @@ -444,7 +468,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | "$script-$shorttag .sh file(s) to:\n $scriptpath" syslog_set warn "$script failed to copy $tag to script location" else - # Set permsissions on script sh files + # Set permissions on script sh files if ! chmod 744 "$scriptpath/"*.sh ; then permerr=1 echo -e "${Error}ERROR ${Off} Failed to set permissions on:" @@ -459,7 +483,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | echo -e "${Error}ERROR ${Off} Failed to copy"\ "$script-$shorttag/CHANGES.txt to:\n $scriptpath" else - # Set permsissions on CHANGES.txt + # Set permissions on CHANGES.txt if ! chmod 744 "$scriptpath/CHANGES.txt"; then if [[ $autoupdate != "yes" ]]; then permerr=1; fi echo -e "${Error}ERROR ${Off} Failed to set permissions on:" @@ -523,8 +547,9 @@ if [[ $restore == "yes" ]]; then # Restore synoinfo.conf from backup if [[ -f ${synoinfo}.bak ]]; then - if mv "${synoinfo}.bak" "${synoinfo}"; then - echo "Restored $(basename -- "$synoinfo")" + #if mv "${synoinfo}.bak" "${synoinfo}"; then + if cp -p "${synoinfo}.bak" "${synoinfo}"; then + echo -e "Restored $(basename -- "$synoinfo")\n" else restoreerr=1 echo -e "${Error}ERROR${Off} Failed to restore synoinfo.conf!\n" @@ -533,12 +558,13 @@ if [[ $restore == "yes" ]]; then # Restore .db files from backups for f in "${!dbbakfiles[@]}"; do - deleteme="${dbbakfiles[f]%.bak}" # Remove .bak - if mv "${dbbakfiles[f]}" "$deleteme"; then - echo "Restored $(basename -- "$deleteme")" + replaceme="${dbbakfiles[f]%.bak}" # Remove .bak + #if mv "${dbbakfiles[f]}" "$replaceme"; then + if cp -p "${dbbakfiles[f]}" "$replaceme"; then + echo "Restored $(basename -- "$replaceme")" else restoreerr=1 - echo -e "${Error}ERROR${Off} Failed to restore $(basename -- "$deleteme")!\n" + echo -e "${Error}ERROR${Off} Failed to restore $(basename -- "$replaceme")!\n" fi done @@ -554,6 +580,9 @@ if [[ $restore == "yes" ]]; then fi done + # Delete "drive_db_test_url=127.0.0.1" line (inc. line break) from /etc/synoinfo.conf + sed -i "/drive_db_test_url=*/d" /etc/synoinfo.conf + # Update .db files from Synology syno_disk_db_update --update @@ -572,8 +601,7 @@ fi # PCIe M.2 cards and connected Expansion Units. fixdrivemodel(){ - # Remove " 00Y" from end of Samsung/Lenovo SSDs - # To fix issue #13 + # Remove " 00Y" from end of Samsung/Lenovo SSDs # Github issue #13 if [[ $1 =~ MZ.*" 00Y" ]]; then hdmodel=$(printf "%s" "$1" | sed 's/ 00Y.*//') fi @@ -597,7 +625,7 @@ getdriveinfo(){ # $1 is /sys/block/sata1 etc # Skip USB drives - usb=$(grep "$(basename -- "$1")" /proc/mounts | grep usb | cut -d" " -f1-2) + usb=$(grep "$(basename -- "$1")" /proc/mounts | grep "[Uu][Ss][Bb]" | cut -d" " -f1-2) if [[ ! $usb ]]; then # Get drive model and firmware version @@ -607,8 +635,12 @@ getdriveinfo(){ # Fix dodgy model numbers fixdrivemodel "$hdmodel" - fwrev=$(cat "$1/device/rev") - fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space + #fwrev=$(cat "$1/device/rev") + #fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space + + #fwrev=$(syno_hdd_util --ssd_detect | grep "/dev/$d" | awk '{print $2}') # GitHub issue #86, 87 + # Account for SSD drives with spaces in their model name/number + fwrev=$(syno_hdd_util --ssd_detect | grep "/dev/$d" | awk '{print $(NF-3)}') # GitHub issue #86, 87 if [[ $hdmodel ]] && [[ $fwrev ]]; then hdlist+=("${hdmodel},${fwrev}") @@ -659,6 +691,11 @@ getcardmodel(){ fi } +m2_pool_support(){ + if [[ -f /run/synostorage/disks/"$(basename -- "$1")"/m2_pool_support ]]; then # GitHub issue #86, 87 + echo 1 > /run/synostorage/disks/"$(basename -- "$1")"/m2_pool_support + fi +} for d in /sys/block/*; do # $d is /sys/block/sata1 etc @@ -683,7 +720,9 @@ for d in /sys/block/*; do getcardmodel "/dev/$(basename -- "${d}")" # Enable creating M.2 storage pool and volume in Storage Manager - echo 1 > /run/synostorage/disks/"$(basename -- "$d")"/m2_pool_support + m2_pool_support "$d" + + rebootmsg=yes # Show reboot message at end fi fi ;; @@ -695,7 +734,9 @@ for d in /sys/block/*; do getcardmodel "/dev/$(basename -- "${d}")" # Enable creating M.2 storage pool and volume in Storage Manager - echo 1 > /run/synostorage/disks/"$(basename -- "$d")"/m2_pool_support + m2_pool_support "$d" + + rebootmsg=yes # Show reboot message at end fi fi ;; @@ -857,15 +898,20 @@ backupdb(){ # Backup database file if needed if [[ ! -f "$1.bak" ]]; then if [[ $(basename "$1") == "synoinfo.conf" ]]; then - echo "" >&2 + echo "" >&2 # Formatting for stdout fi - if cp "$1" "$1.bak"; then + if cp -p "$1" "$1.bak"; then echo -e "Backed up $(basename -- "${1}")" >&2 else echo -e "${Error}ERROR 5${Off} Failed to backup $(basename -- "${1}")!" >&2 return 1 fi fi + # Fix permissions if needed + octal=$(stat -c "%a %n" "$1" | cut -d" " -f1) + if [[ ! $octal -eq 644 ]]; then + chmod 644 "$1" + fi return 0 } @@ -1116,36 +1162,53 @@ else fi # Optionally set mem_max_mb to the amount of installed memory -if [[ $ram == "yes" ]]; then - # Get total amount of installed memory - IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep -i 'size') - if [[ ${#array[@]} -gt "0" ]]; then - num="0" - while [[ $num -lt "${#array[@]}" ]]; do - ramsize=$(printf %s "${array[num]}" | cut -d" " -f2) - if [[ $ramtotal ]]; then - ramtotal=$((ramtotal +ramsize)) - else - ramtotal="$ramsize" - fi - num=$((num +1)) - done - fi - # Set mem_max_mb to the amount of installed memory - setting="$(get_key_value $synoinfo mem_max_mb)" - if [[ $ramtotal -gt $setting ]]; then - synosetkeyvalue "$synoinfo" mem_max_mb "$ramtotal" - # Check we changed mem_max_mb +if [[ $dsm -gt "6" ]]; then # DSM 6 as has no /proc/meminfo + if [[ $ram == "yes" ]]; then + # Get total amount of installed memory + IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep "[Ss]ize") # GitHub issue #86, 87 + if [[ ${#array[@]} -gt "0" ]]; then + num="0" + while [[ $num -lt "${#array[@]}" ]]; do + #ramsize=$(printf %s "${array[num]}" | cut -d" " -f2) + ramsize=$(printf %s "${array[num]}" | awk '{print $2}') # GitHub issue #86, 87 + bytes=$(printf %s "${array[num]}" | awk '{print $3}') # GitHub issue #86, 87 + if [[ $ramsize =~ ^[0-9]+$ ]]; then # Check $ramsize is numeric # GitHub issue #86, 87 + if [[ $ramtotal ]]; then + ramtotal=$((ramtotal +ramsize)) + else + ramtotal="$ramsize" + fi + else + echo -e "\n${Error}ERROR${Off} Memory size is not numeric: '$ramsize'" + fi + num=$((num +1)) + done + fi + # Set mem_max_mb to the amount of installed memory setting="$(get_key_value $synoinfo mem_max_mb)" - if [[ $setting == "$ramtotal" ]]; then - echo -e "\nSet max memory to $ramtotal MB." + if [[ $ramtotal =~ ^[0-9]+$ ]]; then # Check $ramtotal is numeric + if [[ $bytes == "GB" ]]; then # DSM 7.2 dmidecode returns GB + ramtotal=$((ramtotal * 1024)) # Convert to MB + fi + if [[ $ramtotal -gt $setting ]]; then + synosetkeyvalue "$synoinfo" mem_max_mb "$ramtotal" + # Check we changed mem_max_mb + setting="$(get_key_value $synoinfo mem_max_mb)" + if [[ $setting == "$ramtotal" ]]; then + #echo -e "\nSet max memory to $ramtotal MB." + ramgb=$((ramtotal / 1024)) + echo -e "\nSet max memory to $ramtotal GB." + else + echo -e "\n${Error}ERROR${Off} Failed to change max memory!" + fi + elif [[ $setting == "$ramtotal" ]]; then + #echo -e "\nMax memory already set to $ramtotal MB." + ramgb=$((ramtotal / 1024)) + echo -e "\nMax memory already set to $ramgb GB." + fi else - echo -e "\n${Error}ERROR${Off} Failed to change max memory!" + echo -e "\n${Error}ERROR${Off} Total memory size is not numeric: '$ramtotal'" fi - elif [[ $setting == "$ramtotal" ]]; then - #echo -e "\nMax memory already set to $ramtotal MB." - ramgb=$((ramtotal / 1024)) - echo -e "\nMax memory already set to $ramgb GB." fi fi @@ -1216,6 +1279,7 @@ else if [[ $url ]]; then # Delete "drive_db_test_url=127.0.0.1" line (inc. line break) sed -i "/drive_db_test_url=*/d" "$synoinfo" + sed -i "/drive_db_test_url=*/d" /etc/synoinfo.conf # Check if we re-enabled drive db auto updates url="$(get_key_value $synoinfo drive_db_test_url)" @@ -1285,20 +1349,19 @@ 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." + rebootmsg=yes # Show reboot message at end 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" - #if [[ $m2 != "no" ]] && [[ ${#m2cards[@]} -gt "0" ]]; then - echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." - #fi + rebootmsg=yes # Show reboot message at end fi fi fi -if [[ $dsm -eq "6" ]]; then +# Show reboot message if required +if [[ $dsm -eq "6" ]] || [[ $rebootmsg == "yes" ]]; then echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." fi From 8d26e2b2cf40fc04f120fe8c11452fe2ebb8a9a9 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:07:58 +1000 Subject: [PATCH 06/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index af495cc..2a87358 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -36,7 +36,7 @@ # # Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). # -# Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). +# Fixed detecting the amount of installed memory (for DSM 7.2 which now reports GB instead of MB). # # Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). # @@ -178,7 +178,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.49" +scriptver="v2.3.50" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -628,19 +628,21 @@ getdriveinfo(){ usb=$(grep "$(basename -- "$1")" /proc/mounts | grep "[Uu][Ss][Bb]" | cut -d" " -f1-2) if [[ ! $usb ]]; then - # Get drive model and firmware version + # Get drive model hdmodel=$(cat "$1/device/model") hdmodel=$(printf "%s" "$hdmodel" | xargs) # trim leading and trailing white space # Fix dodgy model numbers fixdrivemodel "$hdmodel" + # Get drive firmware version #fwrev=$(cat "$1/device/rev") #fwrev=$(printf "%s" "$fwrev" | xargs) # trim leading and trailing white space - #fwrev=$(syno_hdd_util --ssd_detect | grep "/dev/$d" | awk '{print $2}') # GitHub issue #86, 87 + device="/dev/$(basename -- "$1")" + #fwrev=$(syno_hdd_util --ssd_detect | grep "$device" | awk '{print $2}') # GitHub issue #86, 87 # Account for SSD drives with spaces in their model name/number - fwrev=$(syno_hdd_util --ssd_detect | grep "/dev/$d" | awk '{print $(NF-3)}') # GitHub issue #86, 87 + fwrev=$(syno_hdd_util --ssd_detect | grep "$device" | awk '{print $(NF-3)}') # GitHub issue #86, 87 if [[ $hdmodel ]] && [[ $fwrev ]]; then hdlist+=("${hdmodel},${fwrev}") From fdbcc53b106aa87afdb2f5b5da50ec626662a840 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:08:51 +1000 Subject: [PATCH 07/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 92f3bfa..8829523 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -v2.3.49 +v2.3.50 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). From 3938527dd0dcd5205615f9e717100dd3be577b9f Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:14:58 +1000 Subject: [PATCH 08/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8829523..be401a7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -v2.3.50 +v2.3.51 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). From 14356645da06a88eb109cf8d0e49912c46377909 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:15:22 +1000 Subject: [PATCH 09/18] Update syno_hdd_db.sh --- 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 2a87358..46ffe24 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -178,7 +178,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.50" +scriptver="v2.3.51" script=Synology_HDD_db repo="007revad/Synology_HDD_db" From 836a150c16c3b7912de5b92d35e9e70304ab4215 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:56:20 +1000 Subject: [PATCH 10/18] Update CHANGES.txt --- CHANGES.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index be401a7..5ffe7fb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -v2.3.51 +v2.3.52 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). @@ -7,8 +7,9 @@ v2.3.51 - Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. - Fixed permissions on restored files being incorrect after script run with --restore option. - Fixed permissions on backup files. -- Now skips checking the amount of installed memory in DSM 6 (because it was never working). +- Now skips checking the amount of installed memory in DSM 6 (because it was never working in DSM 6). - Now the script reloads itself after updating. +- Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. - Added "You may need to reboot" message when NVMe drives were detected. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - Autoupdate logs update success or errors to DSM system log. From 3d9b62889a74abefa3a87f53cd8891842988bd48 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Mon, 12 Jun 2023 20:59:15 +1000 Subject: [PATCH 11/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index 46ffe24..f96ee35 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -22,15 +22,13 @@ #-------------------------------------------------------------------------------------------------- # TODO -# Bypass M.2 volume lock for unsupported M.2 drives. -# See https://github.com/007revad/Synology_enable_M2_volume -# # 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. # # Solve issue of --restore option restoring files that were backed up with older DSM version. # DONE +# Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. # # Added "You may need to reboot" message when NVMe drives were detected. # @@ -178,7 +176,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.51" +scriptver="v2.3.52" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -811,9 +809,9 @@ fi # Check m2cards array isn't empty if [[ $m2 != "no" ]]; then if [[ ${#m2cards[@]} -eq "0" ]]; then - echo -e "No M.2 cards found\n" + echo -e "No M.2 PCIe cards found\n" else - echo "M.2 card models found: ${#m2cards[@]}" + echo "M.2 PCIe card models found: ${#m2cards[@]}" num="0" while [[ $num -lt "${#m2cards[@]}" ]]; do echo "${m2cards[num]}" From 720932c425f01a4f3b12d389d787c6cc0f44c935 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:25:58 +1000 Subject: [PATCH 12/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5ffe7fb..ce78926 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -v2.3.52 +v2.3.53 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). From a97daa6214b7cb3bfd54458019f5be73cbc8ca83 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:27:09 +1000 Subject: [PATCH 13/18] Update CHANGES.txt --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index ce78926..a9619e6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ v2.3.53 - Fixed permissions on backup files. - Now skips checking the amount of installed memory in DSM 6 (because it was never working in DSM 6). - Now the script reloads itself after updating. +- Changed help to show -r, --ram also sets max memory to the amount of installed memory. - Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. - Added "You may need to reboot" message when NVMe drives were detected. - Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. From 6e96d4e6d1b92e8953e35ee70c564e8a5cac85b4 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:27:47 +1000 Subject: [PATCH 14/18] Update syno_hdd_db.sh --- syno_hdd_db.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index f96ee35..43181d5 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -28,6 +28,8 @@ # Solve issue of --restore option restoring files that were backed up with older DSM version. # DONE +# Changed help to show -r, --ram also sets max memory to the amount of installed memory. +# # Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. # # Added "You may need to reboot" message when NVMe drives were detected. @@ -176,7 +178,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.52" +scriptver="v2.3.53" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -216,7 +218,8 @@ Options: -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 (DSM 7.x only) + -r, --ram Disable memory compatibility checking (DSM 7.x only), + and sets max memory to the amount of installed memory -w, --wdda Disable WD WDDA --restore Undo all changes made by the script --autoupdate=AGE Auto update script (useful when script is scheduled) @@ -1169,17 +1172,20 @@ if [[ $dsm -gt "6" ]]; then # DSM 6 as has no /proc/meminfo if [[ ${#array[@]} -gt "0" ]]; then num="0" while [[ $num -lt "${#array[@]}" ]]; do - #ramsize=$(printf %s "${array[num]}" | cut -d" " -f2) - ramsize=$(printf %s "${array[num]}" | awk '{print $2}') # GitHub issue #86, 87 - bytes=$(printf %s "${array[num]}" | awk '{print $3}') # GitHub issue #86, 87 - if [[ $ramsize =~ ^[0-9]+$ ]]; then # Check $ramsize is numeric # GitHub issue #86, 87 - if [[ $ramtotal ]]; then - ramtotal=$((ramtotal +ramsize)) + check=$(printf %s "${array[num]}" | awk '{print $1}') + if [[ ${check,,} == "size:" ]]; then + #ramsize=$(printf %s "${array[num]}" | cut -d" " -f2) + ramsize=$(printf %s "${array[num]}" | awk '{print $2}') # GitHub issue #86, 87 + bytes=$(printf %s "${array[num]}" | awk '{print $3}') # GitHub issue #86, 87 + if [[ $ramsize =~ ^[0-9]+$ ]]; then # Check $ramsize is numeric # GitHub issue #86, 87 + if [[ $ramtotal ]]; then + ramtotal=$((ramtotal +ramsize)) + else + ramtotal="$ramsize" + fi else - ramtotal="$ramsize" + echo -e "\n${Error}ERROR${Off} Memory size is not numeric: '$ramsize'" fi - else - echo -e "\n${Error}ERROR${Off} Memory size is not numeric: '$ramsize'" fi num=$((num +1)) done From d284226e4f33d40f8a337ce0b2066c52b530eeee Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:48:12 +1000 Subject: [PATCH 15/18] Update CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index a9619e6..e368a04 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -v2.3.53 +v2.3.54 - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). From e44e0ec48e5144ae4b29c8ef6d9a0bd766967d0d Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:51:16 +1000 Subject: [PATCH 16/18] Update syno_hdd_db.sh --- 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 43181d5..da7ff06 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -178,7 +178,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.53" +scriptver="v2.3.54" script=Synology_HDD_db repo="007revad/Synology_HDD_db" From 8c7347abcd6d2ccc8b43d411c326acd3a8830e12 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:44:14 +1000 Subject: [PATCH 17/18] Update syno_hdd_db.sh - Now enables any installed Synology M.2 PCIe cards for models that don't officially support them. - You can use a M2D20, M2D18, M2D17 or E10M20-T1 on any model with a PCIe slot (not Mini PCIe). - Added -i, --immutable option to enable immutable snapshots on models older than '20 series running DSM 7.2. --- syno_hdd_db.sh | 102 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index da7ff06..2722c3e 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -28,7 +28,11 @@ # Solve issue of --restore option restoring files that were backed up with older DSM version. # DONE -# Changed help to show -r, --ram also sets max memory to the amount of installed memory. +# Now enables any installed Synology M.2 PCIe cards for models that don't officially support them. +# +# Added -i, --immutable option to enable immutable snapshots on models older than '20 series running DSM 7.2. +# +# Changed help to show that -r, --ram also sets max memory to the amount of installed memory. # # Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. # @@ -58,6 +62,9 @@ # Autoupdate logs update success or errors to DSM system log. # # Added -w, --wdda option to disable WDDA +# https://kb.synology.com/en-us/DSM/tutorial/Which_Synology_NAS_supports_WDDA +# https://www.youtube.com/watch?v=cLGi8sPLkLY +# https://community.synology.com/enu/forum/1/post/159537 # # # Added --restore info to --help @@ -178,16 +185,16 @@ # Optionally disable "support_disk_compatibility". -scriptver="v2.3.54" +scriptver="v3.0.55" 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 || { +# Check BASH variable is bash +if [ ! "$(basename "$BASH")" = bash ]; then + echo "This is a bash script. Do not run it with $(basename "$BASH")" printf \\a - printf >&2 "This is a bash script, don't run it with sh\n" exit 1 -} +fi #echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug @@ -221,6 +228,8 @@ Options: -r, --ram Disable memory compatibility checking (DSM 7.x only), and sets max memory to the amount of installed memory -w, --wdda Disable WD WDDA + -i, --immutable Enable immutable snapshots on models older than + 20-series (DSM 7.2 and newer only). --restore Undo all changes made by the script --autoupdate=AGE Auto update script (useful when script is scheduled) AGE is how many days old a release must be before @@ -249,7 +258,7 @@ args=("$@") # Check for flags with getopt if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ - restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,autoupdate:,help,version,debug \ + restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,immutable,autoupdate:,help,version,debug \ -- "$@")"; then eval set -- "$options" while true; do @@ -273,6 +282,9 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ -r|--ram) # Disable "support_memory_compatibility" ram=yes ;; + -i|--immutable) # Enable "support_worm" (immutable snapshots) + immutable=yes + ;; -w|--wdda) # Disable "support_memory_compatibility" wdda=no ;; @@ -337,6 +349,7 @@ fi # cut -d"/" -f5 | cut -d"_" -f1 | uniq) model=$(cat /proc/sys/kernel/syno_hw_version) +modelname="$model" # Show script version @@ -360,10 +373,12 @@ model=${model,,} # Check for dodgy characters after model number if [[ $model =~ 'pv10-j'$ ]]; then # GitHub issue #10 - model=${model%??????}+ # replace last 6 chars with + + modelname=${modelname%??????}+ # replace last 6 chars with + + model=${model%??????}+ # replace last 6 chars with + echo -e "\nUsing model: $model" elif [[ $model =~ '-j'$ ]]; then # GitHub issue #2 - model=${model%??} # remove last 2 chars + modelname=${modelname%??} # remove last 2 chars + model=${model%??} # remove last 2 chars echo -e "\nUsing model: $model" fi @@ -1100,6 +1115,52 @@ while [[ $num -lt "${#nvmes[@]}" ]]; do done +#------------------------------------------------------------------------------ +# Enable unsupported Synology M2 PCIe cards + +enable_card(){ + if [[ -f $1 ]] && [[ -n $2 ]]; then + # Check if section exists + if ! grep '^\['"$2"'\]$' "$1"; then + echo -e "Section [$2] not found in $(basename -- "$1")!" >&2 + return + fi + # Check if already enabled + val=$(get_section_key_value "$1" "$2" "$modelname") + if [[ $val != "yes" ]]; then + if set_section_key_value "$1" "$2" "$modelname" yes; then + echo -e "Enabled $1 for $modelname" >&2 + else + echo -e "${Error}ERROR 5${Off} Failed to enable $1 for ${modelname}!" >&2 + fi + else + echo -e "$1 already enabled for $modelname" >&2 + fi + fi +} + +for c in "${!m2cards[@]}"; do + echo "" + m2cardconf="/usr/syno/etc.defaults/adapter_cards.conf" + case "$c" in + E10M20-T1) + enable_card "$m2cardconf" E10M20-T1_sup_nvme + enable_card "$m2cardconf" E10M20-T1_sup_sata + ;; + M2D20) + enable_card "$m2cardconf" M2D20_sup_nvme + ;; + M2D18) + enable_card "$m2cardconf" M2D18_sup_nvme + enable_card "$m2cardconf" M2D18_sup_sata + ;; + M2D17) + enable_card "$m2cardconf" M2D17_sup_sata + ;; + esac +done + + #------------------------------------------------------------------------------ # Edit /etc.defaults/synoinfo.conf @@ -1301,13 +1362,12 @@ fi # Optionally disable "support_wdda" -wdda=support_wdda -setting="$(get_key_value $synoinfo $wdda)" +setting="$(get_key_value $synoinfo support_wdda)" if [[ $wdda == "no" ]]; then if [[ $setting == "yes" ]]; then # Disable support_memory_compatibility - synosetkeyvalue "$synoinfo" "$wdda" "no" - setting="$(get_key_value "$synoinfo" $wdda)" + synosetkeyvalue "$synoinfo" support_wdda "no" + setting="$(get_key_value "$synoinfo" support_wdda)" if [[ $setting == "no" ]]; then echo -e "\nDisabled support WDDA." fi @@ -1317,6 +1377,22 @@ if [[ $wdda == "no" ]]; then fi +# Optionally enable "support_worm" (immutable snapshots) +setting="$(get_key_value $synoinfo support_worm)" +if [[ $immutable == "yes" ]]; then + if [[ $setting != "yes" ]]; then + # Disable support_memory_compatibility + synosetkeyvalue "$synoinfo" support_worm "yes" + setting="$(get_key_value "$synoinfo" support_worm)" + if [[ $setting == "yes" ]]; then + echo -e "\nEnabled Immutable Snapshots." + fi + elif [[ $setting == "no" ]]; then + echo -e "\nImmutable Snapshots already enabled." + fi +fi + + #------------------------------------------------------------------------------ # Finished From 7afea5768d1415b99cabecc3728a06a63f2dc5f1 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:44:31 +1000 Subject: [PATCH 18/18] Update CHANGES.txt --- CHANGES.txt | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e368a04..abf7652 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,15 @@ -v2.3.54 +v3.0.55 +- Now enables any installed Synology M.2 PCIe cards for models that don't officially support them. + - You can use a M2D20, M2D18, M2D17 or E10M20-T1 on any model with a PCIe slot (not Mini PCIe). +- Now the script reloads itself after updating. +- Added -i, --immutable option to enable immutable snapshots on models older than '20 series running DSM 7.2. +- Added -w, --wdda option to disable WDDA (to prevent warnings when WD drives have been running more than 3 years). +- Added "You may need to reboot" message when NVMe drives were detected. +- Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. + - Autoupdate logs update success or errors to DSM system log. +- Changed help to show -r, --ram also sets max memory to the amount of installed memory. +- Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. +- Changed to skip checking the amount of installed memory in DSM 6 (because it was never working in DSM 6). - Fixed HDD/SSD firmware versions always being 4 characters long (for DSM 7.2 and 6.2.4 Update 7). - Fixed detecting amount of installed memory (for DSM 7.2 which now reports GB instead of MB). - Fixed USB drives sometimes being detected as internal drives (for DSM 7.2). @@ -7,14 +18,6 @@ v2.3.54 - Fixed drive db update still being disabled in /etc/synoinfo.conf after script run with --restore option. - Fixed permissions on restored files being incorrect after script run with --restore option. - Fixed permissions on backup files. -- Now skips checking the amount of installed memory in DSM 6 (because it was never working in DSM 6). -- Now the script reloads itself after updating. -- Changed help to show -r, --ram also sets max memory to the amount of installed memory. -- Changed the "No M.2 cards found" to "No M.2 PCIe cards found" to make it clearer. -- Added "You may need to reboot" message when NVMe drives were detected. -- Added --autoupdate=[age] option to auto update synology_hdd_db x days after new version released. - - Autoupdate logs update success or errors to DSM system log. -- Added -w, --wdda option to disable WDDA. v2.2.47 - Updated reboot info in readme.