@ -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.
# It's also parsed and checked and probably in some cases it could be more critical to patch that one instead.
# DONE
# 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
# Added --restore info to --help
#
#
# Updated restore option to download the latest db files from Synology
# 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"
# 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 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.
# 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".
# Optionally disable "support_disk_compatibility".
scriptver = "v2.2.47 "
scriptver = "v2.3.48 "
script = Synology_HDD_db
script = Synology_HDD_db
repo = "007revad/Synology_HDD_db"
repo = "007revad/Synology_HDD_db"
@ -184,14 +190,18 @@ $script $scriptver - by 007revad
Usage: $( basename " $0 " ) [ options]
Usage: $( basename " $0 " ) [ options]
Options:
Options:
-s, --showedits Show edits made to <model>_host db and db.new file( s)
-s, --showedits Show edits made to <model>_host db and db.new file( s)
-n, --noupdate Prevent DSM updating the compatible drive databases
-n, --noupdate Prevent DSM updating the compatible drive databases
-m, --m2 Don' t process M.2 drives
-m, --m2 Don' t process M.2 drives
-f, --force Force DSM to not check drive compatibility
-f, --force Force DSM to not check drive compatibility
-r, --ram Disable memory compatibility checking
-r, --ram Disable memory compatibility checking
--restore Undo all changes made by the script
-w, --wdda Disable WD WDDA
-h, --help Show this help message
--restore Undo all changes made by the script
-v, --version Show the script version
--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
EOF
exit 0
exit 0
@ -209,12 +219,13 @@ EOF
# Save options used
# Save options used
args = " $* "
args = ( " $@ " )
# Check for flags with getopt
# Check for flags with getopt
if options = " $( getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
if options = " $( getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \
-l restore,showedits,noupdate,nodbupdate,m2,force,ram,help,version,debug -- " $@ " ) " ; then
restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,autoupdate:,help,version,debug \
-- " $@ " ) " ; then
eval set -- " $options "
eval set -- " $options "
while true; do
while true; do
case " ${ 1 ,, } " in
case " ${ 1 ,, } " in
@ -237,6 +248,18 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
-r| --ram) # Disable "support_memory_compatibility"
-r| --ram) # Disable "support_memory_compatibility"
ram = yes
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
-h| --help) # Show usage options
usage
usage
; ;
; ;
@ -320,7 +343,7 @@ elif [[ $model =~ '-j'$ ]]; then # GitHub issue #2
fi
fi
# Show options used
# Show options used
echo " Using options: $ args"
echo " Using options: ${ args [*] } "
#echo "" # To keep output readable
#echo "" # To keep output readable
@ -328,18 +351,37 @@ echo "Using options: $args"
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Check latest release with GitHub API
# Check latest release with GitHub API
get_latest_release ( ) {
syslog_set ( ) {
# Curl timeout options:
if [ [ ${ 1 ,, } = = "info" ] ] || [ [ ${ 1 ,, } = = "warn" ] ] || [ [ ${ 1 ,, } = = "err" ] ] ; then
# https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout
if [ [ $autoupdate = = "yes" ] ] ; then
curl --silent -m 10 --connect-timeout 5 \
# Add entry to Synology system log
" https://api.github.com/repos/ $1 /releases/latest " |
synologset1 sys " $1 " 0x11100000 " $2 "
grep '"tag_name":' | # Get tag line
fi
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
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 } "
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
# Get script location
# https://stackoverflow.com/questions/59895/
# https://stackoverflow.com/questions/59895/
@ -368,8 +410,17 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
echo " https://github.com/ $repo /releases/latest "
echo " https://github.com/ $repo /releases/latest "
sleep 10
sleep 10
else
else
echo -e " ${ Cyan } Do you want to download $tag now? ${ Off } [y/n] "
if [ [ $autoupdate = = "yes" ] ] ; then
read -r -t 30 reply
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 [ [ ${ reply ,, } = = "y" ] ] ; then
if cd /tmp; then
if cd /tmp; then
url = " https://github.com/ $repo /archive/refs/tags/ $tag .tar.gz "
url = " https://github.com/ $repo /archive/refs/tags/ $tag .tar.gz "
@ -377,36 +428,40 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
then
then
echo -e " ${ Error } ERROR ${ Off } Failed to download " \
echo -e " ${ Error } ERROR ${ Off } Failed to download " \
" $script - $shorttag .tar.gz! "
" $script - $shorttag .tar.gz! "
syslog_set warn " $script $tag failed to download "
else
else
if [ [ -f /tmp/$script -$shorttag .tar.gz ] ] ; then
if [ [ -f /tmp/$script -$shorttag .tar.gz ] ] ; then
# Extract tar file to /tmp/<script-name>
# Extract tar file to /tmp/<script-name>
if ! tar -xf " /tmp/ $script - $shorttag .tar.gz " -C "/tmp" ; then
if ! tar -xf " /tmp/ $script - $shorttag .tar.gz " -C "/tmp" ; then
echo -e " ${ Error } ERROR ${ Off } Failed to " \
echo -e " ${ Error } ERROR ${ Off } Failed to " \
" extract $script - $shorttag .tar.gz! "
" extract $script - $shorttag .tar.gz! "
syslog_set warn " $script failed to extract $script - $shorttag .tar.gz! "
else
else
# Copy new script sh files to script location
# Copy new script sh files to script location
if ! cp -p " /tmp/ $script - $shorttag / " *.sh " $scriptpath " ; then
if ! cp -p " /tmp/ $script - $shorttag / " *.sh " $scriptpath " ; then
copyerr = 1
copyerr = 1
echo -e " ${ Error } ERROR ${ Off } Failed to copy " \
echo -e " ${ Error } ERROR ${ Off } Failed to copy " \
" $script - $shorttag .sh file(s) to:\n $scriptpath "
" $script - $shorttag .sh file(s) to:\n $scriptpath "
syslog_set warn " $script failed to copy $tag to script location "
else
else
# Set permsissions on CHANGES.txt
# Set permsissions on script sh files
if ! chmod 744 " $scriptpath / " *.sh ; then
if ! chmod 744 " $scriptpath / " *.sh ; then
permerr = 1
permerr = 1
echo -e " ${ Error } ERROR ${ Off } Failed to set permissions on: "
echo -e " ${ Error } ERROR ${ Off } Failed to set permissions on: "
echo " $scriptpath *.sh file(s) "
echo " $scriptpath *.sh file(s) "
syslog_set warn " $script failed to set permissions on $tag "
fi
fi
fi
fi
# Copy new CHANGES.txt file to script location
# Copy new CHANGES.txt file to script location
if ! cp -p " /tmp/ $script - $shorttag /CHANGES.txt " " $scriptpath " ; then
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 " \
echo -e " ${ Error } ERROR ${ Off } Failed to copy " \
" $script - $shorttag /CHANGES.txt to:\n $scriptpath "
" $script - $shorttag /CHANGES.txt to:\n $scriptpath "
else
else
# Set permsissions on CHANGES.txt
# Set permsissions on CHANGES.txt
if ! chmod 744 " $scriptpath /CHANGES.txt " ; then
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 -e " ${ Error } ERROR ${ Off } Failed to set permissions on: "
echo " $scriptpath /CHANGES.txt "
echo " $scriptpath /CHANGES.txt "
fi
fi
@ -416,32 +471,38 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
if ! rm " /tmp/ $script - $shorttag .tar.gz " ; then
if ! rm " /tmp/ $script - $shorttag .tar.gz " ; then
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! "
syslog_set warn " $script update failed to delete tmp files "
fi
fi
# Delete extracted tmp files
# Delete extracted tmp files
if ! rm -r " /tmp/ $script - $shorttag " ; then
if ! rm -r " /tmp/ $script - $shorttag " ; then
echo -e " ${ Error } ERROR ${ Off } Failed to delete " \
echo -e " ${ Error } ERROR ${ Off } Failed to delete " \
" downloaded /tmp/ $script - $shorttag ! "
" downloaded /tmp/ $script - $shorttag ! "
syslog_set warn " $script update failed to delete tmp files "
fi
fi
# Notify of success (if there were no errors)
# Notify of success (if there were no errors)
if [ [ $copyerr != 1 ] ] && [ [ $permerr != 1 ] ] ; then
if [ [ $copyerr != 1 ] ] && [ [ $permerr != 1 ] ] ; then
echo -e " \n $tag and changes.txt downloaded to: " \
echo -e " \n $tag and changes.txt downloaded to: ${ scriptpath } \n "
" $scriptpath "
syslog_set info " $script successfully updated to $tag "
echo -e " ${ Cyan } Do you want to stop this script " \
" so you can run the new one? ${ Off } [y/n] "
# Reload script
read -r reply
printf -- '-%.0s' { 1..79} ; echo # print 79 -
if [ [ ${ reply ,, } = = "y" ] ] ; then exit; fi
exec " $0 " " ${ args [@] } "
else
syslog_set warn " $script update to $tag had errors "
fi
fi
fi
fi
else
else
echo -e " ${ Error } ERROR ${ Off } " \
echo -e " ${ Error } ERROR ${ Off } " \
" /tmp/ $script - $shorttag .tar.gz not found! "
" /tmp/ $script - $shorttag .tar.gz not found! "
#ls /tmp | grep "$script" # debug
#ls /tmp | grep "$script" # debug
syslog_set warn " /tmp/ $script - $shorttag .tar.gz not found "
fi
fi
fi
fi
else
else
echo -e " ${ Error } ERROR ${ Off } Failed to cd to /tmp! "
echo -e " ${ Error } ERROR ${ Off } Failed to cd to /tmp! "
syslog_set warn " $script update failed to cd to /tmp "
fi
fi
fi
fi
fi
fi
@ -813,14 +874,14 @@ backupdb(){
for i in " ${ !db1list[@] } " ; do
for i in " ${ !db1list[@] } " ; do
backupdb " ${ db1list [i] } " || {
backupdb " ${ db1list [i] } " || {
ding
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
exit 5
}
}
done
done
for i in " ${ !db2list[@] } " ; do
for i in " ${ !db2list[@] } " ; do
backupdb " ${ db2list [i] } " || {
backupdb " ${ db2list [i] } " || {
ding
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
exit 5 # maybe don't exit for .db.new file
}
}
done
done
@ -1169,6 +1230,23 @@ else
fi
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
# Finished