Skip to content

Commit

Permalink
Merge pull request #144 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Sep 19, 2023
2 parents d615e99 + e3704a7 commit d30252f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 57 deletions.
14 changes: 11 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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.)

v3.1.63
- Added support to disable unsupported memory warnings on DVA models. #136

Expand All @@ -9,8 +17,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.

Expand All @@ -19,7 +27,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).
Expand Down
163 changes: 109 additions & 54 deletions syno_hdd_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -673,7 +728,7 @@ fixdrivemodel(){

# Brands that return "BRAND <model>" 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
Expand Down

0 comments on commit d30252f

Please sign in to comment.