Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nurlan
eepm
Commits
a855c33d
Commit
a855c33d
authored
Oct 26, 2020
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools_eget: update to eget 4.0 (wget/curl support)
parent
f6a96334
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
21 deletions
+72
-21
tools_eget
bin/tools_eget
+72
-21
No files found.
bin/tools_eget
View file @
a855c33d
...
...
@@ -21,17 +21,69 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
WGET
=
"wget"
fatal
()
{
echo
"FATAL:
$*
"
>
&2
exit
1
}
WGETQ
=
''
#-q
CURLQ
=
''
#-s
set_quiet
()
{
WGETQ
=
'-q'
CURLQ
=
'-s'
}
# TODO: passthrou all wget options
if
[
"
$1
"
=
"-q"
]
;
then
WGET
=
"wget -q"
set_quiet
shift
fi
WGET
=
"
$(
which wget 2>/dev/null
)
"
if
[
-n
"
$WGET
"
]
;
then
# put remote content to stdout
scat
()
{
$WGET
$WGETQ
-O-
"
$1
"
}
# download to default name of to $2
sget
()
{
if
[
-n
"
$2
"
]
;
then
$WGET
$WGETQ
-O
"
$2
"
"
$1
"
else
$WGET
$WGETQ
"
$1
"
fi
}
else
CURL
=
"
$(
which curl 2>/dev/null
)
"
[
-n
"
$CURL
"
]
||
fatal
"There are no wget nor curl in the system. Install it with
$
epm install curl"
# put remote content to stdout
scat
()
{
$CURL
-L
$CURLQ
"
$1
"
}
# download to default name of to $2
sget
()
{
if
[
-n
"
$2
"
]
;
then
$CURL
-L
$CURLQ
--output
"
$2
"
"
$1
"
else
$CURL
-L
$CURLQ
-O
"
$1
"
fi
}
fi
LISTONLY
=
''
if
[
"
$1
"
=
"--list"
]
;
then
LISTONLY
=
"
$1
"
set_quiet
shift
fi
...
...
@@ -62,10 +114,9 @@ filter_order()
}
# download to this file
WGET_OPTION_TARGET
=
TARGETFILE
=
''
if
[
"
$1
"
=
"-O"
]
;
then
TARGETFILE
=
"
$2
"
WGET_OPTION_TARGET
=
"-O
$2
"
shift
2
fi
...
...
@@ -73,21 +124,23 @@ fi
# -P support
if
[
-z
"
$1
"
]
;
then
echo
"eget - wget
wrapp
er"
>
&2
fatal
"Run
with URL, like http://somesite.ru/dir/*.log
"
echo
"eget - wget
like download
er"
>
&2
fatal
"Run
$0
--help to get help
"
fi
if
[
"
$1
"
=
"-h"
]
||
[
"
$1
"
=
"--help"
]
;
then
echo
"eget - wget
wrapper, with support
"
echo
"Usage: eget [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo
"eget - wget
like downloader with wildcard support in filename part of URL
"
echo
"Usage: eget [-
q] [-
O target file] [--list] http://somesite.ru/dir/na*.log"
echo
echo
"Options:"
echo
" --list - print files frm url with mask"
echo
" -q - quiet mode"
echo
" -O file - download to this file (use filename from server if missed)"
echo
" --list - print files from url with mask"
echo
" --latest - print only latest version of file"
echo
echo
"eget supports --list and download for https://github.com/owner/project urls"
echo
echo
"See
$
wget --help for wget options you can use here"
#
echo "See $ wget --help for wget options you can use here"
exit
fi
...
...
@@ -99,9 +152,7 @@ get_github_urls()
[
-n
"
$owner
"
]
||
fatal
"Can't get owner from
$1
"
[
-n
"
$project
"
]
||
fatal
"Can't get project from
$1
"
local
URL
=
"https://api.github.com/repos/
$owner
/
$project
/releases/latest"
local
q
=
''
[
-n
"
$LISTONLY
"
]
&&
q
=
"-q"
$WGET
$q
-O-
$URL
|
\
scat
$URL
|
\
grep
-i
-o
-E
'"browser_download_url": "https://.*"'
|
cut
-d
'"'
-f4
}
...
...
@@ -114,7 +165,7 @@ if echo "$1" | grep -q "^https://github.com/" ; then
fi
for
fn
in
$(
get_github_urls
"
$1
"
| filter_glob
"
$MASK
"
| filter_order
)
;
do
$WGET
"
$fn
"
||
ERROR
=
1
sget
"
$fn
"
||
ERROR
=
1
done
exit
fi
...
...
@@ -127,8 +178,8 @@ fi
# If ftp protocol, just download
if
echo
"
$1
"
|
grep
-q
"^ftp://"
;
then
[
-n
"
$LISTONLY
"
]
&&
fatal
"
Error
: list files for ftp:// do not supported yet"
$WGET
$WGET_OPTION_TARGET
"
$1
"
[
-n
"
$LISTONLY
"
]
&&
fatal
"
TODO
: list files for ftp:// do not supported yet"
sget
"
$1
"
"
$TARGETFILE
"
exit
fi
...
...
@@ -139,24 +190,24 @@ if echo "$URL" | grep -q "[*?]" ; then
fatal
"Error: there are globbing symbols (*?) in
$URL
"
fi
# mask allowed only in last part of path
# mask allowed only in
the
last part of path
MASK
=
$(
basename
"
$1
"
)
# If have no wildcard symbol like asterisk, just download
if
echo
"
$MASK
"
|
grep
-qv
"[*?]"
;
then
$WGET
$WGET_OPTION_TARGET
"
$1
"
sget
"
$1
"
"
$TARGETFILE
"
exit
fi
get_urls
()
{
$WGET
-O-
$URL
|
\
scat
$URL
|
\
grep
-i
-o
-E
'href="([^\*/"#]+)"'
|
cut
-d
'"'
-f2
}
if
[
-n
"
$LISTONLY
"
]
;
then
WGET
=
"
$WGET
-q"
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
| filter_order
)
;
do
# TODO: return full url? someone use old behaviour?
echo
"
$(
basename
"
$fn
"
)
"
done
exit
...
...
@@ -164,7 +215,7 @@ fi
ERROR
=
0
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
| filter_order
)
;
do
$WGET
"
$URL
/
$(
basename
"
$fn
"
)
"
||
ERROR
=
1
sget
"
$URL
/
$(
basename
"
$fn
"
)
"
||
ERROR
=
1
done
exit
$ERROR
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment