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
fd5e36f8
Commit
fd5e36f8
authored
Mar 26, 2023
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eget: rewrite mirror checking to minimize requests
parent
096c3ce5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
65 deletions
+32
-65
tools_eget
bin/tools_eget
+32
-65
No files found.
bin/tools_eget
View file @
fd5e36f8
...
...
@@ -141,6 +141,29 @@ if [ "$1" = "-U" ] || [ "$1" = "-A" ] || [ "$1" = "--user-agent" ] ; then
shift
fi
# args: cmd <URL> <options>
# will run cmd <options> <URL>
download_with_mirroring
()
{
local
CMD
=
"
$1
"
shift
local
URL
=
"
$1
"
shift
local
res
$CMD
"
$@
"
"
$URL
"
&&
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
MIRROR
=
"https://mirror.eterfund.ru"
SECONDURL
=
"
$(
echo
"
$URL
"
|
sed
-e
"s|^.*://|
$MIRROR
/|"
)
"
$CMD
"
$@
"
"
$SECONDURL
"
&&
URL
=
"
$SECONDURL
"
&&
return
MIRROR
=
"https://mirror.eterfund.org"
SECONDURL
=
"
$(
echo
"
$URL
"
|
sed
-e
"s|^.*://|
$MIRROR
/|"
)
"
$CMD
"
$@
"
"
$SECONDURL
"
&&
URL
=
"
$SECONDURL
"
&&
return
}
WGET
=
"
$(
which wget 2>/dev/null
)
"
...
...
@@ -158,42 +181,24 @@ __wget()
scat
()
{
local
URL
=
"
$1
"
local
res
__wget
-O-
"
$URL
"
&&
return
res
=
$?
# TODO: move check mirrors to __wget (__curl) command (check via try download and print progress)
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__wget
-O-
"
$URL
"
download_with_mirroring __wget
"
$URL
"
-O-
}
# download to default name of to $2
sget
()
{
local
URL
=
"
$1
"
local
res
if
[
"
$2
"
=
"/dev/stdout"
]
||
[
"
$2
"
=
"-"
]
;
then
scat
"
$URL
"
return
elif
[
-n
"
$2
"
]
;
then
__wget
-O
"
$2
"
"
$URL
"
&&
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__wget
-O
"
$2
"
"
$URL
"
download_with_mirroring __wget
"
$URL
"
-O
"
$2
"
return
fi
# TODO: поддержка rsync для известных хостов?
# Не качать, если одинаковый размер и дата
# -nc
# TODO: overwrite always
__wget
$WGETNAMEOPTIONS
"
$URL
"
&&
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__wget
$WGETNAMEOPTIONS
"
$URL
"
download_with_mirroring __wget
"
$URL
"
$WGETNAMEOPTIONS
}
check_url_is_accessible
()
...
...
@@ -208,22 +213,16 @@ CURL="$(which curl 2>/dev/null)"
__curl
()
{
if
[
-n
"
$CURLUSERAGENT
"
]
;
then
docmd
$CURL
-L
$CURLQ
"
$CURLUSERAGENT
"
$CURLNOSSLCHECK
"
$@
"
docmd
$CURL
-
-fail
-
L
$CURLQ
"
$CURLUSERAGENT
"
$CURLNOSSLCHECK
"
$@
"
else
docmd
$CURL
-L
$CURLQ
$CURLNOSSLCHECK
"
$@
"
docmd
$CURL
-
-fail
-
L
$CURLQ
$CURLNOSSLCHECK
"
$@
"
fi
}
# put remote content to stdout
scat
()
{
local
URL
=
"
$1
"
local
res
__curl
"
$URL
"
&&
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__curl
"
$URL
"
download_with_mirroring __curl
"
$URL
"
--output
-
}
# download to default name of to $2
sget
()
...
...
@@ -234,54 +233,22 @@ sget()
scat
"
$1
"
return
elif
[
-n
"
$2
"
]
;
then
__curl
--output
"
$2
"
"
$URL
"
||
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__curl
--output
"
$2
"
"
$URL
"
download_with_mirroring __curl
"
$URL
"
--output
"
$2
"
return
fi
__curl
$CURLNAMEOPTIONS
"
$URL
"
||
return
res
=
$?
[
-n
"
$CHECKMIRRORS
"
]
||
return
$res
update_url_if_need_mirrored
||
return
__curl
$CURLNAMEOPTIONS
"
$URL
"
download_with_mirroring __curl
"
$URL
"
$CURLNAMEOPTIONS
}
check_url_is_accessible
()
{
local
URL
=
"
$1
"
__curl
-LI
"
$URL
"
2>&1 |
grep
"HTTP/"
|
tail
-n1
|
grep
-q
-w
"200"
__curl
-LI
"
$URL
"
2>&1 |
grep
"HTTP/"
|
tail
-n1
|
grep
-q
-w
"200
\|
404
"
}
fi
# update URL variable
update_url_if_need_mirrored
()
{
local
MIRROR
=
"
$1
"
local
SECONDURL
check_url_is_accessible
"
$URL
"
&&
return
if
[
-n
"
$MIRROR
"
]
;
then
check_url_is_accessible
"
$MIRROR
"
&&
URL
=
"
$MIRROR
"
return
fi
MIRROR
=
"https://mirror.eterfund.ru"
SECONDURL
=
"
$(
echo
"
$URL
"
|
sed
-e
"s|^.*://|
$MIRROR
/|"
)
"
check_url_is_accessible
"
$SECONDURL
"
&&
URL
=
"
$SECONDURL
"
&&
return
MIRROR
=
"https://mirror.eterfund.org"
SECONDURL
=
"
$(
echo
"
$URL
"
|
sed
-e
"s|^.*://|
$MIRROR
/|"
)
"
check_url_is_accessible
"
$SECONDURL
"
&&
URL
=
"
$SECONDURL
"
&&
return
}
LISTONLY
=
''
if
[
"
$1
"
=
"--list"
]
;
then
LISTONLY
=
"
$1
"
...
...
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