Browse Source

Update syno_hdd_db.sh

- Changed to add drives' firmware version to the db files (to support data deduplication).
    - See https://github.com/007revad/Synology_enable_Deduplication
- Changed to be able to edit existing drive entries in the db files to add the firmware version.
- Now supports editing db files that don't currently have any drives listed.
pull/48/head
007revad 3 years ago
committed by GitHub
parent
commit
81fef1b6bb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 86
      syno_hdd_db.sh

86
syno_hdd_db.sh

@ -29,6 +29,15 @@
# 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
# Changed to add drives' firmware version to the db files (to support data deduplication).
# See https://github.com/007revad/Synology_enable_Deduplication
#
# Changed to be able to edit existing drive entries in the db files to add the firmware version.
#
# Now supports editing db files that don't currently have any drives listed.
#
# Fixed bug where the --noupdate option was coded as --nodbupdate. Now either will work.
#
# Fixed bug in re-enable drive db updates # Fixed bug in re-enable drive db updates
# #
# Fixed "download new version" failing if script was run via symlink or ./<scriptname> # Fixed "download new version" failing if script was run via symlink or ./<scriptname>
@ -94,7 +103,7 @@
# Optionally disable "support_disk_compatibility". # Optionally disable "support_disk_compatibility".
scriptver="v1.2.31" scriptver="v1.3.32"
script=Synology_HDD_db script=Synology_HDD_db
repo="007revad/Synology_HDD_db" repo="007revad/Synology_HDD_db"
@ -212,12 +221,16 @@ model=$(cat /proc/sys/kernel/syno_hw_version)
#echo -e "$script $scriptver\ngithub.com/$repo\n" #echo -e "$script $scriptver\ngithub.com/$repo\n"
echo "$script $scriptver" echo "$script $scriptver"
# Show DSM full version # Get DSM full version
productversion=$(get_key_value /etc.defaults/VERSION productversion) productversion=$(get_key_value /etc.defaults/VERSION productversion)
buildphase=$(get_key_value /etc.defaults/VERSION buildphase) buildphase=$(get_key_value /etc.defaults/VERSION buildphase)
buildnumber=$(get_key_value /etc.defaults/VERSION buildnumber) buildnumber=$(get_key_value /etc.defaults/VERSION buildnumber)
smallfixnumber=$(get_key_value /etc.defaults/VERSION smallfixnumber)
# Show DSM full version and model
if [[ $buildphase == GM ]]; then buildphase=""; fi if [[ $buildphase == GM ]]; then buildphase=""; fi
echo "$model DSM $productversion-$buildnumber $buildphase" if [[ $smallfixnumber -gt "0" ]]; then smallfix="-$smallfixnumber"; fi
echo -e "$model DSM $productversion-$buildnumber$smallfix $buildphase\n"
# Convert model to lower case # Convert model to lower case
@ -640,6 +653,48 @@ backupdb "$db1" || exit 5
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Edit db files # Edit db files
editcount(){
# Count drives added to host db files
if [[ $1 == "$db1" ]]; then
db1Edits=$((db1Edits +1))
elif [[ $1 == "$db2" ]]; then
db2Edits=$((db2Edits +1))
fi
}
editdb7(){
if [[ $1 == "append" ]]; then # model not in db file
if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # append
echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}"
editcount "$2"
else
echo -e "\n${Error}ERROR 6a${Off} Failed to update $(basename -- "$2")${Off}"
#exit 6
fi
elif [[ $1 == "insert" ]]; then # model and default exists
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
echo -e "\n${Error}ERROR 6b${Off} Failed to update $(basename -- "$2")${Off}"
#exit 6
fi
elif [[ $1 == "empty" ]]; then # db file only contains {}
if sed -i "s/{}/{\"$hdmodel\":{$fwstrng${default}}/" "$2"; then # empty
echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}"
editcount "$2"
else
echo -e "\n${Error}ERROR 6c${Off} Failed to update $(basename -- "$2")${Off}"
#exit 6
fi
fi
}
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)
@ -649,7 +704,7 @@ updatedb() {
#echo hdmodel "$hdmodel" >&2 # debug #echo hdmodel "$hdmodel" >&2 # debug
#echo fwrev "$fwrev" >&2 # debug #echo fwrev "$fwrev" >&2 # debug
if grep "$hdmodel" "$2" >/dev/null; then if grep "$hdmodel"'":{"'"$fwrev" "$2" >/dev/null; then
echo -e "${Yellow}$hdmodel${Off} already exists in ${Cyan}$(basename -- "$2")${Off}" >&2 echo -e "${Yellow}$hdmodel${Off} already exists in ${Cyan}$(basename -- "$2")${Off}" >&2
else else
# Check if db file is new or old style # Check if db file is new or old style
@ -665,21 +720,22 @@ updatedb() {
default="$default":{\"compatibility_interval\":[{\"compatibility\":\"support\",\"not_yet_rolling_status\" default="$default":{\"compatibility_interval\":[{\"compatibility\":\"support\",\"not_yet_rolling_status\"
default="$default":\"support\",\"fw_dsm_update_status_notify\":false,\"barebone_installable\":true}]}}} default="$default":\"support\",\"fw_dsm_update_status_notify\":false,\"barebone_installable\":true}]}}}
#if sed -i "s/}}}/}},\"$hdmodel\":{$fwstrng$default/" "$2"; then # Don't need to add firmware version? if grep '"disk_compatbility_info":{}' "$2" >/dev/null; then
if sed -i "s/}}}/}},\"$hdmodel\":{$default/" "$2"; then # Replace "disk_compatbility_info":{} with "disk_compatbility_info":{"WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}}
echo -e "Added ${Yellow}$hdmodel${Off} to ${Cyan}$(basename -- "$2")${Off}" echo "Edit empty db file"
editdb7 "empty" "$2"
# Count drives added to host db files elif grep '"WD40PURX-64GVNY0"' "$2" >/dev/null; then
if [[ $2 == "$db1" ]]; then # Replace "WD40PURX-64GVNY0":{ with "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},
db1Edits=$((db1Edits +1)) echo "Insert firmware version"
elif [[ $2 == "$db2" ]]; then editdb7 "insert" "$2"
db2Edits=$((db2Edits +1))
fi
else else
echo -e "\n${Error}ERROR 6${Off} Failed to update v7 $(basename -- "$2")${Off}" # Add "WD40PURX-64GVNY0":{"80.00A80":{ ... }}},"default":{ ... }}}
exit 6 echo "Append drive and firmware"
editdb7 "append" "$2"
fi fi
elif [[ $dbtype -eq "6" ]];then elif [[ $dbtype -eq "6" ]];then
# example: # example:
# {"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]}, # {"model":"WD60EFRX-68MYMN1","firmware":"82.00A82","rec_intvl":[1]},

Loading…
Cancel
Save