return empty string if download fails and return/exit if this happens

This commit is contained in:
TotallyLeGIT 2020-08-27 22:59:43 +02:00
parent 66b7aa7b89
commit 8d0f6443e6

View file

@ -107,7 +107,7 @@ Optional Arguments:
download_file () { # expects URL as argument ($1)
declare -r tf=$(mktemp)
$DOWNLOAD_METHOD "${tf}" "$1" && echo "$tf" || return 1 # return the temp-filename or return error code 1
$DOWNLOAD_METHOD "${tf}" "$1" && echo "$tf" || echo '' # return the temp-filename or empty string on error
}
open_file () { #expects one argument: file_path
@ -196,6 +196,7 @@ update_updater () {
fi
declare -r tmpfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.sh')
[ -z "${tmpfile}" ] && echo -e "${RED}Error! Could not download updater.sh${NC}" && return 1 # check if download failed
if [[ $(get_updater_version "${SCRIPT_DIR}/updater.sh") < $(get_updater_version "${tmpfile}") ]]; then
if [ $UPDATE = 'check' ]; then
@ -249,8 +250,8 @@ remove_comments () { # expects 2 arguments: from-file and to-file
# Applies latest version of user.js and any custom overrides
update_userjs () {
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')" ret="$?"
[ "$ret" -ne 0 ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1
declare -r newfile="$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')"
[ -z "${newfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && return 1 # check if download failed
echo -e "Please observe the following information:
Firefox profile: ${ORANGE}$(pwd)${NC}
@ -370,6 +371,7 @@ if [ $# != 0 ]; then
;;
r)
tfile=$(download_file 'https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js')
[ -z "${tfile}" ] && echo -e "${RED}Error! Could not download user.js${NC}" && exit 1 # check if download failed
mv $tfile "${tfile}.js"
echo -e "${ORANGE}Warning: user.js was saved to temporary file ${tfile}.js${NC}"
open_file "${tfile}.js"