From 6eeea132cb4029bf73b05417806c14f683178e93 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:16:00 +1000 Subject: [PATCH 1/3] Update CHANGES.txt --- CHANGES.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f653629..77c898c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +v3.1.64 +- Bug fix for script not updating itself if .sh file had been renamed. +- Bug fix for missing executable permissions if .sh file had been renamed. +- Bug fix to prevent update loop if script's .tar.gz file already exists in /tmp. +- Bug fix to prevent update failing if script's temp folder already exists in /tmp. +- Now only copies CHANGES.txt to script location if script is located on a volume, to prevent putting CHANGES.txt on system partition (/usr/bin, /usr/sbin, /root etc.) + v3.1.63 - Added support to disable unsupported memory warnings on DVA models. #136 @@ -9,8 +16,8 @@ v3.1.61 - Added enabling M2D18 for RS822RP+, RS822+, RS1221RP+ and RS1221+ for older DSM versions. - Fixed enabling E10M20-T1, M2D20 and M2D18 cards in models that don't officially support them. - Fixed bugs where the calculated amount of installed memory could be incorrect: - - If last memory socket was empty an invalid unit of bytes could be used. Issue #106 - - When dmidecode returned MB for one ram module and GB for another ram module. Issue #107 + - If last memory socket was empty an invalid unit of bytes could be used. Issue #106 + - When dmidecode returned MB for one ram module and GB for another ram module. Issue #107 - Fixed bug displaying the max memory setting if total installed memory was less than the max memory. Issue #107 - Fixed bug where sata1 drive firmware version was wrong if there was a sata10 drive. @@ -19,7 +26,7 @@ v3.0.56 v3.0.55 - Now enables any installed Synology M.2 PCIe cards for models that don't officially support them. - - You can use a M2D20, M2D18, M2D17 or E10M20-T1 on any model with a PCIe slot (not Mini PCIe). + - You can use a M2D20, M2D18, M2D17 or E10M20-T1 on any model with a PCIe slot (not Mini PCIe). - Now the script reloads itself after updating. - Added -i, --immutable option to enable immutable snapshots on models older than '20 series running DSM 7.2. - Added -w, --wdda option to disable WDDA (to prevent warnings when WD drives have been running more than 3 years). From 5050b62d5565a41ca3744f3a6c393944cdfbc0d8 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:17:20 +1000 Subject: [PATCH 2/3] Update CHANGES.txt --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 77c898c..450c048 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ v3.1.64 +- Added -e --email option to disable coloured output to make task scheduler emails easier to read. - Bug fix for script not updating itself if .sh file had been renamed. - Bug fix for missing executable permissions if .sh file had been renamed. - Bug fix to prevent update loop if script's .tar.gz file already exists in /tmp. From e3704a7f0334e5ccb67bed239061efc94c5bc227 Mon Sep 17 00:00:00 2001 From: Dave Russell <39733752+007revad@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:22:08 +1000 Subject: [PATCH 3/3] Update syno_hdd_db.sh v3.1.64 - Added -e --email option to disable coloured output to make task scheduler emails easier to read. - Bug fix for script not updating itself if .sh file had been renamed. - Bug fix for missing executable permissions if .sh file had been renamed. - Bug fix to prevent update loop if script's .tar.gz file already exists in /tmp. - Bug fix to prevent update failing if script's temp folder already exists in /tmp. - Now only copies CHANGES.txt to script location if script is located on a volume, to prevent putting CHANGES.txt on system partition (/usr/bin, /usr/sbin, /root etc.) --- syno_hdd_db.sh | 163 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 109 insertions(+), 54 deletions(-) diff --git a/syno_hdd_db.sh b/syno_hdd_db.sh index ee7eb1c..563d016 100644 --- a/syno_hdd_db.sh +++ b/syno_hdd_db.sh @@ -29,6 +29,20 @@ # Change how synoinfo.conf is backed up and restored to prevent issue #73 # DONE +# Bug fix for script not updating itself if .sh file had been renamed. +# +# Bug fix for missing executable permissions if .sh file had been renamed. +# +# Bug fix to prevent update loop if script's .tar.gz file already exists in /tmp. +# +# Bug fix to prevent update failing if script's temp folder already exists in /tmp. +# +# Now only copies CHANGES.txt to script location if script is located on a volume, +# to prevent putting CHANGES.txt on system partition (/usr/bin, /usr/sbin, /root etc.) +# +# Added -e --email option to disable coloured output to make task scheduler emails easier to read. +# +# # Added support to disable unsupported memory warnings on DVA models. # # Fixed bug where newly connected expansion units weren't found until up to 24 hours later. #124 @@ -204,7 +218,7 @@ # Optionally disable "support_disk_compatibility". -scriptver="v3.1.63" +scriptver="v3.1.64" script=Synology_HDD_db repo="007revad/Synology_HDD_db" @@ -217,18 +231,6 @@ fi #echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug -# Shell Colors -#Black='\e[0;30m' -Red='\e[0;31m' -#Green='\e[0;32m' -Yellow='\e[0;33m' -#Blue='\e[0;34m' -#Purple='\e[0;35m' -Cyan='\e[0;36m' -#White='\e[0;37m' -Error='\e[41m' -Off='\e[0m' - ding(){ printf \\a } @@ -249,6 +251,7 @@ Options: -w, --wdda Disable WD WDDA -i, --immutable Enable immutable snapshots on models older than 20-series (DSM 7.2 and newer only). + -e, --email Disable colored text in output scheduler emails. --restore Undo all changes made by the script --autoupdate=AGE Auto update script (useful when script is scheduled) AGE is how many days old a release must be before @@ -277,7 +280,7 @@ args=("$@") # Check for flags with getopt if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ - restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,immutable,autoupdate:,help,version,debug \ + restore,showedits,noupdate,nodbupdate,m2,force,ram,wdda,immutable,email,autoupdate:,help,version,debug \ -- "$@")"; then eval set -- "$options" while true; do @@ -307,6 +310,9 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ -w|--wdda) # Disable "support_memory_compatibility" wdda=no ;; + -e|--email) # Disable colour text in task scheduler emails + color=no + ;; --autoupdate) # Auto update script autoupdate=yes if [[ $2 =~ ^[0-9]+$ ]]; then @@ -348,6 +354,23 @@ if [[ $debug == "yes" ]]; then fi +# Shell Colors +if [[ $color != "no" ]]; then + #Black='\e[0;30m' # ${Black} + Red='\e[0;31m' # ${Red} + #Green='\e[0;32m' # ${Green} + Yellow='\e[0;33m' # ${Yellow} + #Blue='\e[0;34m' # ${Blue} + #Purple='\e[0;35m' # ${Purple} + Cyan='\e[0;36m' # ${Cyan} + #White='\e[0;37m' # ${White} + Error='\e[41m' # ${Error} + Off='\e[0m' # ${Off} +else + echo "" # For task scheduler email readability +fi + + # Check script is running as root if [[ $( whoami ) != "root" ]]; then ding @@ -448,16 +471,52 @@ source=${BASH_SOURCE[0]} while [ -L "$source" ]; do # Resolve $source until the file is no longer a symlink scriptpath=$( cd -P "$( dirname "$source" )" >/dev/null 2>&1 && pwd ) source=$(readlink "$source") - # If $source was a relative symlink, we need to resolve it + # If $source was a relative symlink, we need to resolve it # relative to the path where the symlink file was located [[ $source != /* ]] && source=$scriptpath/$source done scriptpath=$( cd -P "$( dirname "$source" )" >/dev/null 2>&1 && pwd ) +scriptfile=$( basename -- "$source" ) +echo "Running from: ${scriptpath}/$scriptfile" + #echo "Script location: $scriptpath" # debug +#echo "Source: $source" # debug +#echo "Script filename: $scriptfile" # debug + +#echo "tag: $tag" # debug +#echo "scriptver: $scriptver" # debug + + +cleanup_tmp(){ + cleanup_err= + + # Delete downloaded .tar.gz file + if [[ -f "/tmp/$script-$shorttag.tar.gz" ]]; then + if ! rm "/tmp/$script-$shorttag.tar.gz"; then + echo -e "${Error}ERROR${Off} Failed to delete"\ + "downloaded /tmp/$script-$shorttag.tar.gz!" >&2 + cleanup_err=1 + fi + fi + + # Delete extracted tmp files + if [[ -d "/tmp/$script-$shorttag" ]]; then + if ! rm -r "/tmp/$script-$shorttag"; then + echo -e "${Error}ERROR${Off} Failed to delete"\ + "downloaded /tmp/$script-$shorttag!" >&2 + cleanup_err=1 + fi + fi + + # Add warning to DSM log + if [[ -z $cleanup_err ]]; then + syslog_set warn "$script update failed to delete tmp files" + fi +} if ! printf "%s\n%s\n" "$tag" "$scriptver" | - sort --check --version-sort >/dev/null ; then + sort --check=quiet --version-sort >/dev/null ; then echo -e "\n${Cyan}There is a newer version of this script available.${Off}" echo -e "Current version: ${scriptver}\nLatest version: $tag" if [[ -f $scriptpath/$script-$shorttag.tar.gz ]]; then @@ -480,11 +539,14 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | echo -e "${Cyan}Do you want to download $tag now?${Off} [y/n]" read -r -t 30 reply fi + if [[ ${reply,,} == "y" ]]; then + # Delete previously downloaded .tar.gz file and extracted tmp files + cleanup_tmp + if cd /tmp; then url="https://github.com/$repo/archive/refs/tags/$tag.tar.gz" - if ! curl -LJO -m 30 --connect-timeout 5 "$url"; - then + if ! curl -JLO -m 30 --connect-timeout 5 "$url"; then echo -e "${Error}ERROR${Off} Failed to download"\ "$script-$shorttag.tar.gz!" syslog_set warn "$script $tag failed to download" @@ -496,53 +558,46 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" | "extract $script-$shorttag.tar.gz!" syslog_set warn "$script failed to extract $script-$shorttag.tar.gz!" else - # Copy new script sh files to script location - if ! cp -p "/tmp/$script-$shorttag/"*.sh "$scriptpath"; then + # Set permissions on script sh files + if ! chmod a+x "/tmp/$script-$shorttag/"*.sh ; then + permerr=1 + echo -e "${Error}ERROR${Off} Failed to set executable permissions" + syslog_set warn "$script failed to set permissions on $tag" + fi + + # Copy new script sh file to script location + if ! cp -p "/tmp/$script-$shorttag/syno_hdd_db.sh" "${scriptpath}/${scriptfile}"; + then copyerr=1 echo -e "${Error}ERROR${Off} Failed to copy"\ "$script-$shorttag .sh file(s) to:\n $scriptpath" syslog_set warn "$script failed to copy $tag to script location" - else - # Set permissions on script sh files - if ! chmod 744 "$scriptpath/"*.sh ; then - permerr=1 - echo -e "${Error}ERROR${Off} Failed to set permissions on:" - echo "$scriptpath *.sh file(s)" - syslog_set warn "$script failed to set permissions on $tag" - fi fi - # Copy new CHANGES.txt file to script location - if ! cp -p "/tmp/$script-$shorttag/CHANGES.txt" "$scriptpath"; then - if [[ $autoupdate != "yes" ]]; then copyerr=1; fi - echo -e "${Error}ERROR${Off} Failed to copy"\ - "$script-$shorttag/CHANGES.txt to:\n $scriptpath" - else - # Set permissions on CHANGES.txt - if ! chmod 744 "$scriptpath/CHANGES.txt"; then - if [[ $autoupdate != "yes" ]]; then permerr=1; fi - echo -e "${Error}ERROR${Off} Failed to set permissions on:" - echo "$scriptpath/CHANGES.txt" + # Copy new CHANGES.txt file + if [[ $scriptpath =~ /volume* ]]; then + # Copy new CHANGES.txt file to script location + if ! cp -p "/tmp/$script-$shorttag/CHANGES.txt" "$scriptpath"; then + if [[ $autoupdate != "yes" ]]; then copyerr=1; fi + echo -e "${Error}ERROR${Off} Failed to copy"\ + "$script-$shorttag/CHANGES.txt to:\n $scriptpath" + else + # Set permissions on CHANGES.txt + if ! chmod 664 "$scriptpath/CHANGES.txt"; then + if [[ $autoupdate != "yes" ]]; then permerr=1; fi + echo -e "${Error}ERROR${Off} Failed to set permissions on:" + echo "$scriptpath/CHANGES.txt" + fi + changestxt=" and changes.txt" fi fi - # Delete downloaded .tar.gz file - if ! rm "/tmp/$script-$shorttag.tar.gz"; then - echo -e "${Error}ERROR${Off} Failed to delete"\ - "downloaded /tmp/$script-$shorttag.tar.gz!" - syslog_set warn "$script update failed to delete tmp files" - fi - - # Delete extracted tmp files - if ! rm -r "/tmp/$script-$shorttag"; then - echo -e "${Error}ERROR${Off} Failed to delete"\ - "downloaded /tmp/$script-$shorttag!" - syslog_set warn "$script update failed to delete tmp files" - fi + # Delete downloaded .tar.gz file and extracted tmp files + cleanup_tmp # Notify of success (if there were no errors) if [[ $copyerr != 1 ]] && [[ $permerr != 1 ]]; then - echo -e "\n$tag and changes.txt downloaded to: ${scriptpath}\n" + echo -e "\n$tag$changestxt downloaded to: ${scriptpath}\n" syslog_set info "$script successfully updated to $tag" # Reload script @@ -673,7 +728,7 @@ fixdrivemodel(){ # Brands that return "BRAND " and need "BRAND " removed. if [[ $1 =~ ^[A-Za-z]{1,7}" ".* ]]; then - #see Smartmontools database in /var/lib/smartmontools/drivedb.db + # See Smartmontools database in /var/lib/smartmontools/drivedb.db hdmodel=${hdmodel#"WDC "} # Remove "WDC " from start of model name hdmodel=${hdmodel#"HGST "} # Remove "HGST " from start of model name hdmodel=${hdmodel#"TOSHIBA "} # Remove "TOSHIBA " from start of model name