Browse Source

Merge pull request #78 from 007revad/develop

Develop
pull/91/head
Dave Russell 3 years ago
committed by GitHub
parent
commit
4777230d4b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      README.md
  2. 75
      syno_hdd_db.sh

7
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. * 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). * 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?)**. * 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). * Makes DSM recheck disk compatibility so rebooting is not needed if you don't have M.2 drives (DSM 7 only).
* Reminds you that you may need to reboot the Synology after running the script (DSM 6 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. * 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. * 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. 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 ### Options when running the script

75
syno_hdd_db.sh

@ -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
@ -324,7 +328,7 @@ echo "Using options: $args"
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Check latest release with GitHub API # Check latest release with GitHub API
get_latest_release() { get_latest_release(){
# Curl timeout options: # Curl timeout options:
# https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout # https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout
curl --silent -m 10 --connect-timeout 5 \ curl --silent -m 10 --connect-timeout 5 \
@ -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
@ -520,7 +532,7 @@ fixdrivemodel(){
fi fi
} }
getdriveinfo() { getdriveinfo(){
# $1 is /sys/block/sata1 etc # $1 is /sys/block/sata1 etc
# Skip USB drives # Skip USB drives
@ -543,7 +555,7 @@ getdriveinfo() {
fi fi
} }
getm2info() { getm2info(){
# $1 is /sys/block/nvme0n1 etc # $1 is /sys/block/nvme0n1 etc
nvmemodel=$(cat "$1/device/model") nvmemodel=$(cat "$1/device/model")
nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space nvmemodel=$(printf "%s" "$nvmemodel" | xargs) # trim leading and trailing white space
@ -559,7 +571,7 @@ getm2info() {
fi fi
} }
getcardmodel() { getcardmodel(){
# Get M.2 card model (if M.2 drives found) # Get M.2 card model (if M.2 drives found)
# $1 is /dev/nvme0n1 etc # $1 is /dev/nvme0n1 etc
if [[ ${#nvmelist[@]} -gt "0" ]]; then if [[ ${#nvmelist[@]} -gt "0" ]]; then
@ -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
@ -778,7 +792,7 @@ getdbtype(){
} }
backupdb() { backupdb(){
# Backup database file if needed # Backup database file if needed
if [[ ! -f "$1.bak" ]]; then if [[ ! -f "$1.bak" ]]; then
if [[ $(basename "$1") == "synoinfo.conf" ]]; then if [[ $(basename "$1") == "synoinfo.conf" ]]; then
@ -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
@ -854,7 +873,7 @@ editdb7(){
} }
updatedb() { updatedb(){
hdmodel=$(printf "%s" "$1" | cut -d"," -f 1) hdmodel=$(printf "%s" "$1" | cut -d"," -f 1)
fwrev=$(printf "%s" "$1" | cut -d"," -f 2) fwrev=$(printf "%s" "$1" | cut -d"," -f 2)
@ -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

Loading…
Cancel
Save