Browse Source

Update syno_hdd_db.sh

Fix bug #77
pull/78/head v2.2.46
Dave Russell 3 years ago
committed by GitHub
parent
commit
67ed9f4330
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      syno_hdd_db.sh

52
syno_hdd_db.sh

@ -3,7 +3,6 @@
#--------------------------------------------------------------------------------------------------
# Github: https://github.com/007revad/Synology_HDD_db
# Script verified at https://www.shellcheck.net/
# Tested on DSM 7.2 beta, 7.1.1 and DSM 6.2.4
#
# Easiest solution:
# 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
#
# 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
# sudo /volume1/scripts/syno_hdd_db.sh -showedits
# sudo -i /volume1/scripts/syno_hdd_db.sh -showedits
# or
# sudo /volume1/scripts/syno_hdd_db.sh -force -showedits
# sudo -i /volume1/scripts/syno_hdd_db.sh -force -showedits
#--------------------------------------------------------------------------------------------------
# TODO
@ -149,12 +148,13 @@
# Optionally disable "support_disk_compatibility".
scriptver="v2.2.45"
scriptver="v2.2.46"
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 || {
printf \\a
printf >&2 "This is a bash script, don't run it with sh\n"
exit 1
}
@ -173,6 +173,9 @@ Cyan='\e[0;36m'
Error='\e[41m'
Off='\e[0m'
ding(){
printf \\a
}
usage(){
cat <<EOF
@ -268,6 +271,7 @@ fi
# Check script is running as root
if [[ $( whoami ) != "root" ]]; then
ding
echo -e "${Error}ERROR${Off} This script must be run as root or sudo!"
exit 1
fi
@ -478,8 +482,16 @@ if [[ $restore == "yes" ]]; then
done
# 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}"*db.newr; do rm "$f">/dev/null; done
for f in "${dbpath}"*dbr; do
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
syno_disk_db_update --update
@ -639,6 +651,7 @@ fi
# Check hdds array isn't empty
if [[ ${#hdds[@]} -eq "0" ]]; then
ding
echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2
else
echo -e "\nHDD/SSD models found: ${#hdds[@]}"
@ -757,6 +770,7 @@ done
if [[ ${#db1list[@]} -eq "0" ]]; then
ding
echo -e "${Error}ERROR 4${Off} Host db file not found!" && exit 4
fi
# Don't check .db.new as new installs don't have a .db.new file
@ -797,12 +811,14 @@ backupdb() {
# Backup host database file if needed
for i in "${!db1list[@]}"; do
backupdb "${db1list[i]}" ||{
ding
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]}")!"
exit 5 # maybe don't exit for .db.new file
}
@ -821,10 +837,10 @@ editcount(){
fi
}
editdb7(){
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}"
editcount "$2"
else
@ -833,7 +849,8 @@ editdb7(){
fi
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}"
#editcount "$2"
else
@ -842,7 +859,8 @@ editdb7(){
fi
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}"
editcount "$2"
else
@ -907,9 +925,11 @@ updatedb() {
startstring="{\"success\":1,\"list\":\["
# example:
# {"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}"
else
ding
echo -e "\n${Error}ERROR 8${Off} Failed to update $(basename -- "$2")${Off}" >&2
exit 8
fi
@ -973,7 +993,7 @@ done
# Edit /etc.defaults/synoinfo.conf
# Backup synoinfo.conf if needed
backupdb "$synoinfo" || exit 9
backupdb "$synoinfo" || ding && exit 9
# Optionally disable "support_disk_compatibility"
sdc=support_disk_compatibility
@ -1074,7 +1094,8 @@ if [[ $m2 != "no" ]]; then
enabled=""
if [[ ! $setting ]]; then
# Add support_m2_pool="yes"
echo 'support_m2_pool="yes"' >> "$synoinfo"
#echo 'support_m2_pool="yes"' >> "$synoinfo"
synosetkeyvalue "$synoinfo" "$smp" "yes"
enabled="yes"
elif [[ $setting == "no" ]]; then
# Change support_m2_pool="no" to "yes"
@ -1104,7 +1125,8 @@ disabled=""
if [[ $nodbupdate == "yes" ]]; then
if [[ ! $url ]]; then
# 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"
elif [[ $url != "127.0.0.1" ]]; then
# Edit drive_db_test_url=

Loading…
Cancel
Save