Commit 11ff9ce7 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add -i|--input-file option

parent 557948de
...@@ -369,6 +369,7 @@ AXELSHOWPROGRESS='' ...@@ -369,6 +369,7 @@ AXELSHOWPROGRESS=''
WGETTIMESTAMPING='' WGETTIMESTAMPING=''
CURLTIMESTAMPING='' CURLTIMESTAMPING=''
TIMESTAMPING='' TIMESTAMPING=''
INPUTFILE=''
set_quiet() set_quiet()
{ {
...@@ -415,6 +416,7 @@ Options: ...@@ -415,6 +416,7 @@ Options:
--no-glob - turn off file name globbing --no-glob - turn off file name globbing
-c|--continue - continue getting a partially-downloaded file -c|--continue - continue getting a partially-downloaded file
-N|--timestamping - only download if remote file is newer than local -N|--timestamping - only download if remote file is newer than local
-i|--input-file FILE - read URLs from FILE, one per line; each line can contain multiple mirror URLs (use - for stdin)
-T|--timeout=N - set the network timeout to N seconds -T|--timeout=N - set the network timeout to N seconds
--read-timeout=N - set the read (and write) timeout to N seconds --read-timeout=N - set the read (and write) timeout to N seconds
--retry-connrefused - consider “connection refused” a transient error and try again --retry-connrefused - consider “connection refused” a transient error and try again
...@@ -585,6 +587,13 @@ while [ -n "$1" ] ; do ...@@ -585,6 +587,13 @@ while [ -n "$1" ] ; do
WGETTIMESTAMPING="-N" WGETTIMESTAMPING="-N"
CURLTIMESTAMPING="1" CURLTIMESTAMPING="1"
;; ;;
-i|--input-file)
if [ -z "$argvalue" ];then
shift
argvalue="$1"
fi
INPUTFILE="$argvalue"
;;
-T|--timeout) -T|--timeout)
if [ -z "$argvalue" ];then if [ -z "$argvalue" ];then
shift shift
...@@ -1851,6 +1860,34 @@ sget() ...@@ -1851,6 +1860,34 @@ sget()
url_sget "$@" url_sget "$@"
} }
# Read URLs from file, skip empty lines and comments
read_urls_from_file()
{
local file="$1"
local line
if [ "$file" = "-" ] ; then
# Read from stdin
while IFS= read -r line ; do
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
[ -z "$line" ] && continue
echo "$line" | grep -q '^[[:space:]]*#' && continue
echo "$line"
done
else
# Read from file
[ ! -f "$file" ] && fatal "Error: input file '$file' not found"
[ ! -r "$file" ] && fatal "Error: input file '$file' is not readable"
while IFS= read -r line ; do
line="$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
[ -z "$line" ] && continue
echo "$line" | grep -q '^[[:space:]]*#' && continue
echo "$line"
done < "$file"
fi
}
pget() pget()
{ {
url_pget "$@" url_pget "$@"
...@@ -2022,6 +2059,24 @@ else ...@@ -2022,6 +2059,24 @@ else
fi fi
# Process input file if specified
if [ -n "$INPUTFILE" ] ; then
# Set output dir to current dir if not specified
[ -z "$USEOUTPUTDIR" ] && USEOUTPUTDIR="."
# Read URLs from file
URLS="$(read_urls_from_file "$INPUTFILE")"
[ -z "$URLS" ] && fatal "Error: no valid URLs found in input file"
# Process each line separately (each line = one file, possibly with mirrors)
echo "$URLS" | while IFS= read -r line ; do
[ -z "$line" ] && continue
# Each line may contain multiple URLs (mirrors) separated by spaces
sget_with_mirrors $line
done
exit
fi
# https://www.freeoffice.com/download.php?filename=freeoffice-2021-1062.x86_64.rpm # https://www.freeoffice.com/download.php?filename=freeoffice-2021-1062.x86_64.rpm
if [ -z "$NOGLOB" ] && echo "$URL" | grep -q -P "[*\[\]]" ; then if [ -z "$NOGLOB" ] && echo "$URL" | grep -q -P "[*\[\]]" ; then
fatal "Error: there are globbing symbol (*[]) in $URL. It is allowed only for mask part" fatal "Error: there are globbing symbol (*[]) in $URL. It is allowed only for mask part"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment