From a9da09fc898a6597c461b44e94c4181b49b26e10 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Fri, 23 Jan 2026 11:33:18 +1100 Subject: [PATCH] Update script version to v3.6.120 and add reboot option Added a new option to reboot the NAS after DSM updates if the build number has changed, specifically for NVMe volumes or PCIe cards requiring a second reboot. --- syno_hdd_db.sh | 111 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 31 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index b5b14a1..364d98f 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -29,7 +29,7 @@ # /var/packages/StorageManager/target/ui/storage_panel.js -scriptver="v3.6.119" +scriptver="v3.6.120" script=Synology_HDD_db repo="007revad/Synology_HDD_db" scriptname=syno_hdd_db @@ -90,6 +90,9 @@ Options: recent model IronWolf and IronWolf Pro drives. For NAS with x86_64 CPUs only Installs IHM on '22 series and newer models (untested) + --reboot Reboot after a DSM update when build number has changed + Only needed if NVMe volume or PCIe card need a 2nd + reboot after DSM update -h, --help Show this help message -v, --version Show the script version @@ -113,7 +116,8 @@ args=("$@") # Check for flags with getopt if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \ - ssd:,ihm,restore,showedits,noupdate,nodbupdate,m2,force,incompatible,ram,pcie,wdda,email,autoupdate:,help,version,debug \ + ssd:,ihm,restore,showedits,noupdate,nodbupdate,m2,force,\ + incompatible,ram,pcie,wdda,email,autoupdate:,reboot,help,version,debug \ -- "$@")"; then eval set -- "$options" while true; do @@ -181,6 +185,9 @@ if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \ delay="0" fi ;; + --reboot) # Reboot once more after major DSM update + do_reboot="yes" + ;; -h|--help) # Show usage options usage ;; @@ -238,6 +245,7 @@ if [[ $color != "no" ]]; then Cyan='\e[0;36m' # ${Cyan} #White='\e[0;37m' # ${White} Error='\e[41m' # ${Error} + Warn='\e[47;31m' # ${Warn} Off='\e[0m' # ${Off} else echo "" # For task scheduler email readability @@ -251,6 +259,18 @@ if [[ $( whoami ) != "root" ]]; then exit 1 fi +detect_scheduler(){ + # Check if stdin is a terminal (interactive) + [ ! -t 0 ] && return 0 + + # Check parent process + local parent + parent=$(ps -p $PPID -o comm=) + [[ "$parent" =~ (systemd-run|sched|crond) ]] && return 0 + + return 1 +} + # Get DSM major version dsm=$(/usr/syno/bin/synogetkeyvalue /etc.defaults/VERSION majorversion) if [[ $dsm -gt "6" ]]; then @@ -306,7 +326,7 @@ fi # Get StorageManager version storagemgrver=$(/usr/syno/bin/synopkg version StorageManager) # Show StorageManager version -if [[ $storagemgrver ]]; then echo -e "StorageManager $storagemgrver"; fi +if [[ $storagemgrver ]]; then echo -e "- StorageManager $storagemgrver"; fi # Get SynoOnlinePack version if [[ $dsmversion -gt "72" ]]; then @@ -321,19 +341,20 @@ if [[ $dsmversion -gt "72" ]]; then SOPinfo="/var/packages/SynoOnlinePack/INFO" fi SOPpkgver="$(/usr/syno/bin/synogetkeyvalue $SOPinfo version)" - echo -e "SynoOnlinePack$v2 version $SOPpkgver\n" -else - echo "" + #echo -e "SynoOnlinePack$v2 version $SOPpkgver\n" + echo "- SynoOnlinePack$v2 version $SOPpkgver" +#else +# echo "" fi # Show host drive db version if [[ -f "/var/lib/disk-compatibility/${model}_host_v7.version" ]]; then - echo -n "${model}_host_v7 version " + echo -n "- ${model}_host_v7 version " cat "/var/lib/disk-compatibility/${model}_host_v7.version" echo -e "\n" fi if [[ -f "/var/lib/disk-compatibility/${model}_host.version" ]]; then - echo -n "${model}_host version " + echo -n "- ${model}_host version " cat "/var/lib/disk-compatibility/${model}_host.version" echo -e "\n" fi @@ -361,7 +382,7 @@ pause(){ # Check latest release with GitHub API syslog_set(){ - if [[ ${1,,} == "info" ]] || [[ ${1,,} == "warn" ]] || [[ ${1,,} == "err" ]]; then + if [[ ${1,,} == "info" || ${1,,} == "warn" || ${1,,} == "err" ]]; then if [[ $autoupdate == "yes" ]]; then # Add entry to Synology system log /usr/syno/bin/synologset1 sys "$1" 0x11100000 "$2" @@ -447,7 +468,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | echo -e "\n${Cyan}There is a newer version of this script available.${Off}" echo -e "Current version: ${scriptver}\nLatest version: $tag" scriptdl="$scriptpath/$script-$shorttag" - if [[ -f ${scriptdl}.tar.gz ]] || [[ -f ${scriptdl}.zip ]]; then + if [[ -f ${scriptdl}.tar.gz || -f ${scriptdl}.zip ]]; then # They have the latest version tar.gz downloaded but are using older version echo "You have the latest version downloaded but are using an older version" sleep 10 @@ -457,7 +478,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | sleep 10 else if [[ $autoupdate == "yes" ]]; then - if [[ $age -gt "$delay" ]] || [[ $age -eq "$delay" ]]; then + if [[ $age -gt "$delay" || $age -eq "$delay" ]]; then echo "Downloading $tag" reply=y else @@ -557,7 +578,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | cleanup_tmp # Notify of success (if there were no errors) - if [[ $copyerr != 1 ]] && [[ $permerr != 1 ]]; then + if [[ $copyerr != 1 && $permerr != 1 ]]; then echo -e "\n$tag ${scriptfile}$vids_txt$changestxt downloaded to: ${scriptpath}\n" syslog_set info "$script successfully updated to $tag" @@ -585,6 +606,16 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | fi +# Show if running in shell or via task scheduler +if detect_scheduler; then + echo "Running via task scheduler" + sch_task="yes" +else + echo "Running in interactive shell" + sch_task="" +fi + + # Warn if script located on M.2 drive get_script_vol() { local script_root vol_num vg_name @@ -644,13 +675,20 @@ fi vidfile="/usr/syno/etc.defaults/pci_vendor_ids.conf" vidfile2="/usr/syno/etc/pci_vendor_ids.conf" +reboot_file="${scriptpath}/syno_hdd_reboot.txt" +if [[ ! -f "$reboot_file" ]]; then + echo "Do NOT delete this file!" > "$reboot_file" + echo "It is used to track if DSM has updated." >> "$reboot_file" + synosetkeyvalue "$reboot_file" dsm_build "$buildnumber" +fi + set_writemostly(){ # $1 is writemostly or -writemostly # $2 is sata1 or sas1 or sda etc local model # Show drive model - model="$(cat /sys/block/"${2}"/device/model | xargs)" + model="$(xargs < /sys/block/"${2}"/device/model)" echo -e "${Yellow}$model${Off}" if [[ ${1::2} == "sd" ]]; then @@ -694,8 +732,8 @@ if [[ $restore == "yes" ]]; then unset IFS echo "" - if [[ ${#dbbakfiles[@]} -gt "0" ]] || [[ -f ${synoinfo}.bak ]] ||\ - [[ -f ${dtb_file}.bak ]] || [[ -f ${adapter_cards}.bak ]] ; then + if [[ ${#dbbakfiles[@]} -gt "0" || -f ${synoinfo}.bak ||\ + -f ${dtb_file}.bak || -f ${adapter_cards}.bak ]] ; then # Restore synoinfo.conf from backup if [[ -f ${synoinfo}.bak ]]; then @@ -1012,7 +1050,7 @@ getdriveinfo(){ # Get drive GB size size_gb=$(get_size_gb "$1") if [[ -n "$size_gb" ]]; then # PR #187 - if [[ $hdmodel ]] && [[ $fwrev ]]; then + if [[ $hdmodel && $fwrev ]]; then if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then # Is SATA M.2 SSD nvmelist+=("${hdmodel},${fwrev},${size_gb}") @@ -1039,7 +1077,7 @@ getm2info(){ # Get drive GB size size_gb=$(get_size_gb "$1") - if [[ $nvmemodel ]] && [[ $nvmefw ]]; then + if [[ $nvmemodel && $nvmefw ]]; then nvmelist+=("${nvmemodel},${nvmefw},${size_gb}") drivelist+=("${nvmemodel}") fi @@ -1086,7 +1124,7 @@ m2_drive(){ # Check if is NVMe or SATA M.2 SSD if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then - if [[ $2 == "nvme" ]] || [[ $2 == "nvc" ]]; then + if [[ $2 == "nvme" || $2 == "nvc" ]]; then # Fix unknown vendor id if needed. GitHub issue #161 # "Failed to get disk vendor" from synonvme --vendor-get # causes "Unsupported firmware version" warning. @@ -1118,7 +1156,7 @@ is_ssd(){ brand="$(cat /sys/block/"$1"/device/vendor)" if grep -q "$1" /proc/mdstat | grep -E 'raid5|raid6'; then - if [[ $show_trim_warning != "yes" ]] && [[ $brand != "Synology" ]]; then + if [[ $show_trim_warning != "yes" && $brand != "Synology" ]]; then show_trim_warning="yes" fi fi @@ -1212,7 +1250,7 @@ fi # Exit if no drives found -if [[ ${#hdds[@]} -eq "0" ]] && [[ ${#nvmes[@]} -eq "0" ]]; then +if [[ ${#hdds[@]} -eq "0" && ${#nvmes[@]} -eq "0" ]]; then ding echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2 fi @@ -1747,7 +1785,7 @@ enable_card(){ # $1 is the file # $2 is the section # $3 is the card model and mode - if [[ -f $1 ]] && [[ -n $2 ]] && [[ -n $3 ]]; then + if [[ -f $1 && -n $2 && -n $3 ]]; then backupdb "$adapter_cards" long backupdb "$adapter_cards2" long @@ -1788,7 +1826,7 @@ dts_m2_card(){ sed -i '/^};/d' "$2" # Append PCIe M.2 card node to dts file -if [[ $1 == E10M20-T1 ]] || [[ $1 == M2D20 ]]; then +if [[ $1 == E10M20-T1 || $1 == M2D20 ]]; then cat >> "$2" <