@ -3,7 +3,6 @@
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
# 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/
# Tested on DSM 7.2 beta, 7.1.1 and DSM 6.2.4
#
#
# Easiest solution:
# Easiest solution:
# Edit /etc.defaults/synoinfo.conf and change support_disk_compatibility="yes" to "no" and reboot.
# 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
# /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):
# 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
# or
# sudo /volume1/scripts/syno_hdd_db.sh -showedits
# sudo -i /volume1/scripts/syno_hdd_db.sh -showedits
# or
# or
# sudo /volume1/scripts/syno_hdd_db.sh -force -showedits
# sudo -i /volume1/scripts/syno_hdd_db.sh -force -showedits
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
# TODO
# TODO
@ -149,12 +148,13 @@
# Optionally disable "support_disk_compatibility".
# Optionally disable "support_disk_compatibility".
scriptver = "v2.2.45 "
scriptver = "v2.2.47 "
script = Synology_HDD_db
script = Synology_HDD_db
repo = "007revad/Synology_HDD_db"
repo = "007revad/Synology_HDD_db"
# Check BASH variable is is non-empty and posix mode is off, else abort with error.
# Check BASH variable is is non-empty and posix mode is off, else abort with error.
[ " $BASH " ] && ! shopt -qo posix || {
[ " $BASH " ] && ! shopt -qo posix || {
printf \\ a
printf >& 2 "This is a bash script, don't run it with sh\n"
printf >& 2 "This is a bash script, don't run it with sh\n"
exit 1
exit 1
}
}
@ -173,6 +173,9 @@ Cyan='\e[0;36m'
Error = '\e[41m'
Error = '\e[41m'
Off = '\e[0m'
Off = '\e[0m'
ding( ) {
printf \\ a
}
usage( ) {
usage( ) {
cat <<EOF
cat <<EOF
@ -268,6 +271,7 @@ fi
# Check script is running as root
# Check script is running as root
if [ [ $( whoami ) != "root" ] ] ; then
if [ [ $( whoami ) != "root" ] ] ; then
ding
echo -e " ${ Error } ERROR ${ Off } This script must be run as root or sudo! "
echo -e " ${ Error } ERROR ${ Off } This script must be run as root or sudo! "
exit 1
exit 1
fi
fi
@ -478,8 +482,16 @@ if [[ $restore == "yes" ]]; then
done
done
# Delete any .dbr and .db.newr files left by previous script versions
# Delete any .dbr and .db.newr files left by previous script versions
for f in " ${ dbpath } " *dbr; do rm " $f " >/dev/null; done
for f in " ${ dbpath } " *dbr; do
for f in " ${ dbpath } " *db.newr; do rm " $f " >/dev/null; done
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
# Update .db files from Synology
syno_disk_db_update --update
syno_disk_db_update --update
@ -639,6 +651,7 @@ fi
# Check hdds array isn't empty
# Check hdds array isn't empty
if [ [ ${# hdds [@] } -eq "0" ] ] ; then
if [ [ ${# hdds [@] } -eq "0" ] ] ; then
ding
echo -e " \n ${ Error } ERROR ${ Off } No drives found! " && exit 2
echo -e " \n ${ Error } ERROR ${ Off } No drives found! " && exit 2
else
else
echo -e " \nHDD/SSD models found: ${# hdds [@] } "
echo -e " \nHDD/SSD models found: ${# hdds [@] } "
@ -757,6 +770,7 @@ done
if [ [ ${# db1list [@] } -eq "0" ] ] ; then
if [ [ ${# db1list [@] } -eq "0" ] ] ; then
ding
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
# Don't check .db.new as new installs don't have a .db.new file
# Don't check .db.new as new installs don't have a .db.new file
@ -791,19 +805,22 @@ backupdb() {
return 1
return 1
fi
fi
fi
fi
return 0
}
}
# Backup host database file if needed
# Backup host database file if needed
for i in " ${ !db1list[@] } " ; do
for i in " ${ !db1list[@] } " ; do
backupdb " ${ db1list [i] } " || {
backupdb " ${ db1list [i] } " || {
echo -e " ${ Error } ERROR 5 ${ Off } Failed to backup $( basename -- " ${ db1list [i] } " ) ! "
ding
#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] } " || {
echo -e " ${ Error } ERROR 5 ${ Off } Failed to backup $( basename -- " ${ 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
exit 5 # maybe don't exit for .db.new file
}
}
done
done
@ -821,10 +838,10 @@ editcount(){
fi
fi
}
}
editdb7( ) {
editdb7( ) {
if [ [ $1 = = "append" ] ] ; then # model not in db file
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 } "
echo -e " Added ${ Yellow } $hdmodel ${ Off } to ${ Cyan } $( basename -- " $2 " ) ${ Off } "
editcount " $2 "
editcount " $2 "
else
else
@ -833,7 +850,8 @@ editdb7(){
fi
fi
elif [ [ $1 = = "insert" ] ] ; then # model and default exists
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 } "
echo -e " Updated ${ Yellow } $hdmodel ${ Off } to ${ Cyan } $( basename -- " $2 " ) ${ Off } "
#editcount "$2"
#editcount "$2"
else
else
@ -842,7 +860,8 @@ editdb7(){
fi
fi
elif [ [ $1 = = "empty" ] ] ; then # db file only contains {}
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 } "
echo -e " Added ${ Yellow } $hdmodel ${ Off } to ${ Cyan } $( basename -- " $2 " ) ${ Off } "
editcount " $2 "
editcount " $2 "
else
else
@ -907,9 +926,11 @@ updatedb() {
startstring = "{\"success\":1,\"list\":\["
startstring = "{\"success\":1,\"list\":\["
# 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 -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 } "
echo -e " Added ${ Yellow } $hdmodel ${ Off } to ${ Cyan } $( basename -- " $2 " ) ${ Off } "
else
else
ding
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
fi
fi
@ -973,7 +994,10 @@ done
# Edit /etc.defaults/synoinfo.conf
# Edit /etc.defaults/synoinfo.conf
# Backup synoinfo.conf if needed
# Backup synoinfo.conf if needed
backupdb " $synoinfo " || exit 9
backupdb " $synoinfo " || {
ding
exit 9
}
# Optionally disable "support_disk_compatibility"
# Optionally disable "support_disk_compatibility"
sdc = support_disk_compatibility
sdc = support_disk_compatibility
@ -1074,7 +1098,8 @@ if [[ $m2 != "no" ]]; then
enabled = ""
enabled = ""
if [ [ ! $setting ] ] ; then
if [ [ ! $setting ] ] ; then
# Add support_m2_pool="yes"
# Add support_m2_pool="yes"
echo 'support_m2_pool="yes"' >> " $synoinfo "
#echo 'support_m2_pool="yes"' >> "$synoinfo"
synosetkeyvalue " $synoinfo " " $smp " "yes"
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"
@ -1104,7 +1129,8 @@ disabled=""
if [ [ $nodbupdate = = "yes" ] ] ; then
if [ [ $nodbupdate = = "yes" ] ] ; then
if [ [ ! $url ] ] ; then
if [ [ ! $url ] ] ; then
# Add drive_db_test_url="127.0.0.1"
# 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"
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=
@ -1181,12 +1207,15 @@ if [[ -f /usr/syno/sbin/synostgdisk ]]; then # DSM 6.2.3 does not have synostgd
status = $?
status = $?
if [ [ $status -eq "0" ] ] ; then
if [ [ $status -eq "0" ] ] ; then
echo -e "\nDSM successfully checked disk compatibility."
echo -e "\nDSM successfully checked disk compatibility."
echo -e " \nYou may need to ${ Cyan } reboot the Synology ${ Off } to see the changes. "
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
# 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 "
#if [[ $m2 != "no" ]] && [[ ${#m2cards[@]} -gt "0" ]]; then
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. "
#fi
fi
fi
fi
fi
fi
fi