Browse Source

Update syno_hdd_db.sh

Changed 'latest version check' to download to /tmp and extract files to the script's location.
pull/30/head
007revad 3 years ago
committed by GitHub
parent
commit
300ec1b463
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      syno_hdd_db.sh

69
syno_hdd_db.sh

@ -29,6 +29,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
# Changed latest version check to download to /tmp and extract files to the script's location.
#
# Added a timeouts when checking for newer script version in case github is down or slow. # Added a timeouts when checking for newer script version in case github is down or slow.
# #
# Added option to disable incompatible memory notifications. # Added option to disable incompatible memory notifications.
@ -86,7 +88,7 @@
# Optionally disable "support_disk_compatibility". # Optionally disable "support_disk_compatibility".
scriptver="v1.2.21" scriptver="v1.2.22"
script=Synology_HDD_db script=Synology_HDD_db
repo="007revad/Synology_HDD_db" repo="007revad/Synology_HDD_db"
@ -229,57 +231,66 @@ echo "" # To keep output readable
get_latest_release() { get_latest_release() {
# Curl timeout options: # Curl timeout options:
# https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout # https://unix.stackexchange.com/questions/94604/does-curl-have-a-timeout
curl --silent -m 10 --connect-timeout 5 "https://api.github.com/repos/$1/releases/latest" | curl --silent -m 10 --connect-timeout 5 \
"https://api.github.com/repos/$1/releases/latest" |
grep '"tag_name":' | # Get tag line grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
} }
tag=$(get_latest_release "$repo") tag=$(get_latest_release "$repo")
shorttag="${tag:1}" shorttag="${tag:1}"
scriptpath=$(dirname -- "$0")
if [[ $HOME =~ /var/services/* ]]; then
shorthome=${HOME:14}
else
shorthome="$HOME"
fi
if ! printf "%s\n%s\n" "$tag" "$scriptver" | if ! printf "%s\n%s\n" "$tag" "$scriptver" |
sort --check --version-sort &> /dev/null ; then sort --check --version-sort &> /dev/null ; then
echo -e "${Cyan}There is a newer version of this script available.${Off}" echo -e "${Cyan}There is a newer version of this script available.${Off}"
echo -e "Current version: ${scriptver}\nLatest version: $tag" echo -e "Current version: ${scriptver}\nLatest version: $tag"
if [[ ! -d $HOME ]]; then if [[ -f $scriptpath/$script-$shorttag.tar.gz ]]; then
# Can't download to home # They have the latest version tar.gz downloaded but are using older version
echo "https://github.com/$repo/releases/latest" echo "https://github.com/$repo/releases/latest"
sleep 10 sleep 10
elif [[ -f $HOME/$script-$shorttag.tar.gz ]]; then elif [[ -d $scriptpath/$script-$shorttag ]]; then
# Latest version tar.gz in home but they're using older version # They have the latest version extracted but are using older version
echo "https://github.com/$repo/releases/latest" echo "https://github.com/$repo/releases/latest"
sleep 10 sleep 10
else else
echo -e "${Cyan}Do you want to download $tag now?${Off} {y/n]" echo -e "${Cyan}Do you want to download $tag now?${Off} {y/n]"
read -r -t 30 reply read -r -t 30 reply
if [[ ${reply,,} == "y" ]]; then if [[ ${reply,,} == "y" ]]; then
if ! curl -LJO -m 30 --connect-timeout 5 "https://github.com/$repo/archive/refs/tags/$tag.tar.gz"; if cd /tmp; then
then url="https://github.com/$repo/archive/refs/tags/$tag.tar.gz"
echo -e "${Error}ERROR ${Off} Failed to download $script-$shorttag.tar.gz!" if ! curl -LJO -m 30 --connect-timeout 5 "$url";
else then
if [[ -f $HOME/$script-$shorttag.tar.gz ]]; then echo -e "${Error}ERROR ${Off} Failed to download"\
if ! tar -xf "$HOME/$script-$shorttag.tar.gz"; then "$script-$shorttag.tar.gz!"
echo -e "${Error}ERROR ${Off} Failed to extract $script-$shorttag.tar.gz!" else
else if [[ -f /tmp/$script-$shorttag.tar.gz ]]; then
if ! rm "$HOME/$script-$shorttag.tar.gz"; then # Extract tar file to script location
echo -e "${Error}ERROR ${Off} Failed to delete downloaded $script-$shorttag.tar.gz!" if ! tar -xf "/tmp/$script-$shorttag.tar.gz" -C "$scriptpath";
then
echo -e "${Error}ERROR ${Off} Failed to"\
"extract $script-$shorttag.tar.gz!"
else else
echo -e "\n$tag and changes.txt are in ${Cyan}$shorthome/$script-$shorttag${Off}" if ! rm "/tmp/$script-$shorttag.tar.gz"; then
echo -e "${Cyan}Do you want to stop this script so you can run the new one?${Off} {y/n]" echo -e "${Error}ERROR ${Off} Failed to delete"\
read -r -t 30 reply "downloaded $script-$shorttag.tar.gz!"
if [[ ${reply,,} == "y" ]]; then exit; fi else
echo -e "\n$tag and changes.txt are in "\
"${Cyan}$scriptpath/$script-$shorttag${Off}"
echo -e "${Cyan}Do you want to stop this script"\
"so you can run the new one?${Off} {y/n]"
read -r -t 30 reply
if [[ ${reply,,} == "y" ]]; then exit; fi
fi
fi fi
else
echo -e "${Error}ERROR ${Off}"\
"/tmp/$script-$shorttag.tar.gz not found!"
#ls /tmp | grep "$script" # debug
fi fi
else
echo -e "${Error}ERROR ${Off} $shorthome/$script-$shorttag.tar.gz not found!"
#ls $HOME/ | grep "$script" # debug
fi fi
else
echo -e "${Error}ERROR ${Off} Failed to cd to /tmp!"
fi fi
fi fi
fi fi

Loading…
Cancel
Save