Browse Source

Update syno_hdd_db.sh

-  Added a --restore option to undo all changes made by the script.
pull/63/head
Dave Russell 3 years ago
committed by GitHub
parent
commit
0eaec15c12
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      syno_hdd_db.sh

57
syno_hdd_db.sh

@ -30,6 +30,8 @@
# 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
# Added a --restore option to undo all changes.
#
# Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4. # Now looks for and edits both v7 and non-v7 db files to solve issue #11 for RS '21 models running DSM 6.2.4.
# This will also ensure the script still works if: # This will also ensure the script still works if:
# Synology append different numbers to the db file names in DSM 8 etc. # Synology append different numbers to the db file names in DSM 8 etc.
@ -135,7 +137,7 @@
# Optionally disable "support_disk_compatibility". # Optionally disable "support_disk_compatibility".
scriptver="v2.2.39" scriptver="v2.2.40"
script=Synology_HDD_db script=Synology_HDD_db
repo="007revad/Synology_HDD_db" repo="007revad/Synology_HDD_db"
@ -190,10 +192,14 @@ args="$*"
# Check for flags with getopt # Check for flags with getopt
if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
-l showedits,noupdate,nodbupdate,m2,force,ram,help,version,debug -- "$@")"; then -l restore,showedits,noupdate,nodbupdate,m2,force,ram,help,version,debug -- "$@")"; then
eval set -- "$options" eval set -- "$options"
while true; do while true; do
case "${1,,}" in case "${1,,}" in
--restore) # Restore changes from backups
restore=yes
break
;;
-s|--showedits) # Show edits done to host db file -s|--showedits) # Show edits done to host db file
showedits=yes showedits=yes
;; ;;
@ -419,6 +425,49 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
fi fi
#------------------------------------------------------------------------------
# Restore changes from backups
dbpath=/var/lib/disk-compatibility/
synoinfo="/etc.defaults/synoinfo.conf"
if [[ $restore == "yes" ]]; then
dbbakfiles=($(find $dbpath -maxdepth 1 \( -name "*.db.new.bak" -o -name "*.db.bak" \)))
echo
if [[ ${#dbbakfiles[@]} -gt "0" ]] || [[ -f ${synoinfo}.bak ]]; then
# Restore .db files from backups
for f in "${!dbbakfiles[@]}"; do
deleteme="${dbbakfiles[f]%.bak}" # Remove .bak
if mv "${dbbakfiles[f]}" "$deleteme"; then
echo "Restored $(basename -- "$deleteme")"
else
restoreerr=1
echo -e "${Error}ERROR${Off} Failed to restore $(basename -- "$deleteme")!\n"
fi
done
# Restore synoinfo.conf from backup
if [[ -f ${synoinfo}.bak ]]; then
if mv "${synoinfo}.bak" "${synoinfo}"; then
echo "Restored $(basename -- "$synoinfo")"
else
restoreerr=1
echo -e "${Error}ERROR${Off} Failed to restore synoinfo.conf!\n"
fi
fi
if [[ -z $restoreerr ]]; then
echo -e "\nRestore successful."
fi
else
echo "Nothing to restore."
fi
exit
fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Get list of installed SATA, SAS and M.2 NVMe/SATA drives, # Get list of installed SATA, SAS and M.2 NVMe/SATA drives,
# PCIe M.2 cards and connected Expansion Units. # PCIe M.2 cards and connected Expansion Units.
@ -664,8 +713,6 @@ fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Check databases and add our drives if needed # Check databases and add our drives if needed
dbpath="/var/lib/disk-compatibility/"
# Host db files # Host db files
db1list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db")) db1list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db"))
db2list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db.new")) db2list=($(find "$dbpath" -maxdepth 1 -name "*_host*.db.new"))
@ -682,8 +729,6 @@ for i in "${!m2cards[@]}"; do
m2carddb2list=($(find "$dbpath" -maxdepth 1 -name "*_${m2cards[i],,}*.db.new")) m2carddb2list=($(find "$dbpath" -maxdepth 1 -name "*_${m2cards[i],,}*.db.new"))
done done
synoinfo="/etc.defaults/synoinfo.conf"
if [[ ${#db1list[@]} -eq "0" ]]; then if [[ ${#db1list[@]} -eq "0" ]]; then
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

Loading…
Cancel
Save