mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-27 23:36:35 +00:00
Add missing _download_from()
function.
This commit is contained in:
parent
0715b9ec66
commit
2346f6f814
48
hosts
48
hosts
@ -218,6 +218,54 @@ _contains() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# _download_from()
|
||||
#
|
||||
# Usage:
|
||||
# _download_from <url> [<outfile>]
|
||||
#
|
||||
# Description:
|
||||
# Download the file at <url> and print to standard output or <outfile>, if
|
||||
# present. Uses `curl` if available, falling back to `wget`.
|
||||
_download_from() {
|
||||
local _downloaded=0
|
||||
local _target_path="${2:-}"
|
||||
local _url="${1:-}"
|
||||
|
||||
if [[ -z "${_url}" ]] ||
|
||||
[[ ! "${_url}" =~ ^ftp|^http|^file|^mailto|^news|^telnet|^gopher ]]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -n "${_target_path}" ]]
|
||||
then
|
||||
if hash "curl" 2>/dev/null
|
||||
then
|
||||
curl -s -L "${_url}" -o "${_target_path}" &&
|
||||
_downloaded=1
|
||||
elif hash "wget" 2>/dev/null
|
||||
then
|
||||
wget --quiet -O "${_target_path}" "${_url}" 2>/dev/null &&
|
||||
_downloaded=1
|
||||
fi
|
||||
else
|
||||
if hash "curl" 2>/dev/null
|
||||
then
|
||||
curl -s -L "${_url}" &&
|
||||
_downloaded=1
|
||||
elif hash "wget" 2>/dev/null
|
||||
then
|
||||
wget --quiet -O - "${_url}" 2>/dev/null &&
|
||||
_downloaded=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! ((_downloaded))
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# _join()
|
||||
#
|
||||
# Usage:
|
||||
|
Loading…
Reference in New Issue
Block a user