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
etersoft
eepm
Commits
89894e9c
Commit
89894e9c
authored
Nov 19, 2017
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update internal eget up to 3.0
parent
3d1ff000
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
37 deletions
+49
-37
tools_eget
bin/tools_eget
+49
-37
No files found.
bin/tools_eget
View file @
89894e9c
...
...
@@ -23,12 +23,31 @@
WGET
=
"wget"
# TODO: passthrou all wget options
if
[
"
$1
"
=
"-q"
]
;
then
WGET
=
"wget -q"
shift
fi
# TODO:
if
[
"
$1
"
=
"--list"
]
;
then
LISTONLY
=
"
$1
"
shift
fi
fatal
()
{
echo
"
$*
"
>
&2
exit
1
}
# check man glob
filter_glob
()
{
# translate glob to regexp
grep
"^
$(
echo
"
$1
"
|
sed
-e
"s|
\*
|.*|g"
-e
"s|
\?
|.|g"
)
$"
}
# download to this file
WGET_OPTION_TARGET
=
if
[
"
$1
"
=
"-O"
]
;
then
...
...
@@ -42,61 +61,54 @@ fi
if
[
-z
"
$1
"
]
;
then
echo
"eget - wget wrapper"
>
&2
echo
"Run with URL, like http://somesite.ru/dir/*.log"
>
&2
exit
1
fatal
"Run with URL, like http://somesite.ru/dir/*.log"
fi
# do not support /
if
echo
"
$1
"
|
grep
-q
"/$"
;
then
fatal
"Use http://example.com/e/* to download all files in dir"
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
"
exit
fi
# drop mask part
(if has /$, not changed)
URL
=
$(
echo
"
$1
"
|
grep
"/$"
||
dirname
"
$1
"
)
# drop mask part
URL
=
"
$(
dirname
"
$1
"
)
/"
# If have no wildcard symbol like asterisk and no / at the end, just download
if
[
"
$URL
"
!=
"
$1
"
]
&&
echo
"
$1
"
|
grep
-qv
"[*?]"
;
then
$WGET
$WGET_OPTION_TARGET
"
$1
"
exit
if
echo
"
$URL
"
|
grep
-q
"[*?]"
;
then
fatal
"Error: there are globbing symbols (*?) in
$URL
"
fi
echo
"Fall to http workaround"
# mask allowed only in last part of path
MASK
=
$(
basename
"
$1
"
)
# TODO: skip create_fake_files for full dir
# add * if full dir
#[ "$URL" != "$1" ] && MASK="*"
print_files
()
# If have no wildcard symbol like asterisk, just download
if
echo
"
$MASK
"
|
grep
-qv
"[*?]"
;
then
$WGET
$WGET_OPTION_TARGET
"
$1
"
exit
fi
get_urls
()
{
$WGET
-O-
$URL
|
\
grep
-o
-E
'href="([^\*/"#]+)"'
|
cut
-d
'"'
-f2
}
create_fake_files
()
{
DIRALLFILES
=
"
$MYTMPDIR
/files/"
mkdir
-p
"
$DIRALLFILES
"
print_files |
while
read
-r
line
;
do
touch
$DIRALLFILES
/
$(
basename
"
$line
"
)
if
[
-n
"
$LISTONLY
"
]
;
then
WGET
=
"
$WGET
-q"
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
)
;
do
echo
"
$(
basename
"
$fn
"
)
"
done
}
exit
fi
download_files
()
{
ERROR
=
0
# TODO: test fix / at the end
for
line
in
$DIRALLFILES
/
$MASK
;
do
[
-r
"
$line
"
]
||
{
ERROR
=
1
;
break
;
}
$WGET
$URL
/
$(
basename
"
$line
"
)
||
ERROR
=
1
done
return
$ERROR
}
ERROR
=
0
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
)
;
do
$WGET
"
$URL
/
$(
basename
"
$fn
"
)
"
||
ERROR
=
1
done
exit
$ERROR
MYTMPDIR
=
"
$(
mktemp
-d
)
"
create_fake_files
download_files
||
echo
"There was some download errors"
>
&2
rm
-rf
"
$MYTMPDIR
"
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