Commit 0043e226 authored by Vitaly Lipatov's avatar Vitaly Lipatov

tools_eget: update from eget 4.1

parent 80e106e1
...@@ -69,7 +69,6 @@ scat() ...@@ -69,7 +69,6 @@ scat()
{ {
$CURL -L $CURLQ "$1" $CURL -L $CURLQ "$1"
} }
# download to default name of to $2 # download to default name of to $2
sget() sget()
{ {
...@@ -94,6 +93,12 @@ if [ "$1" = "--latest" ] ; then ...@@ -94,6 +93,12 @@ if [ "$1" = "--latest" ] ; then
shift shift
fi fi
fatal()
{
echo "$*" >&2
exit 1
}
# check man glob # check man glob
filter_glob() filter_glob()
{ {
...@@ -146,39 +151,23 @@ get_github_urls() ...@@ -146,39 +151,23 @@ get_github_urls()
local project="$(echo "$1" | sed -e "s|^https://github.com/$owner/||" -e "s|/.*||")" #" local project="$(echo "$1" | sed -e "s|^https://github.com/$owner/||" -e "s|/.*||")" #"
[ -n "$owner" ] || fatal "Can't get owner from $1" [ -n "$owner" ] || fatal "Can't get owner from $1"
[ -n "$project" ] || fatal "Can't get project from $1" [ -n "$project" ] || fatal "Can't get project from $1"
local URL="https://api.github.com/repos/$owner/$project/releases/latest" local URL="https://api.github.com/repos/$owner/$project/releases"
scat $URL | \ scat $URL | \
grep -i -o -E '"browser_download_url": "https://.*"' | cut -d'"' -f4 grep -i -o -E '"browser_download_url": "https://.*"' | cut -d'"' -f4
} }
# mask allowed only in the last part of path if echo "$1" | grep -q "^https://github.com/" ; then
MASK=$(basename "$1")
NOMASK=''
# If have no wildcard symbol like asterisk, just download
if echo "$MASK" | grep -qv "[*?]" || echo "$MASK" | grep -q "[?].*="; then
NOMASK='1'
fi
if echo "$1" | grep -q "^https://github.com/" && ! echo "$1" | grep -q "/releases/download/" ; then
MASK="$2" MASK="$2"
if [ -n "$LISTONLY" ] ; then if [ -n "$LISTONLY" ] ; then
fn='' get_github_urls "$1" | filter_glob "$MASK" | filter_order
for fn in $(get_github_urls "$1" | filter_glob "$MASK" | filter_order) ; do
echo "$fn"
done
test -n "$fn"
exit exit
fi fi
ERROR=0
fn=''
for fn in $(get_github_urls "$1" | filter_glob "$MASK" | filter_order) ; do for fn in $(get_github_urls "$1" | filter_glob "$MASK" | filter_order) ; do
sget "$fn" || ERROR=1 sget "$fn" || ERROR=1
done done
test -n "$fn" || ERROR=1 exit
exit $ERROR
fi fi
...@@ -195,40 +184,38 @@ if echo "$1" | grep -q "^ftp://" ; then ...@@ -195,40 +184,38 @@ if echo "$1" | grep -q "^ftp://" ; then
fi fi
# drop mask part # drop mask part
URL="$(dirname "$1")" URL="$(dirname "$1")/"
if echo "$URL" | grep -q "[*?]" ; then if echo "$URL" | grep -q "[*?]" ; then
fatal "Error: there are globbing symbols (*?) in $URL" fatal "Error: there are globbing symbols (*?) in $URL"
fi fi
# mask allowed only in the last part of path
MASK=$(basename "$1")
# If have no wildcard symbol like asterisk, just download # If have no wildcard symbol like asterisk, just download
if [ -n "$NOMASK" ] ; then if echo "$MASK" | grep -qv "[*?]" || echo "$MASK" | grep -q "[?].*="; then
sget "$1" "$TARGETFILE" sget "$1" "$TARGETFILE"
exit exit
fi fi
get_urls() get_urls()
{ {
scat $URL/ | \ scat $URL | \
grep -i -o -P 'href="(.*?)"' | cut -d'"' -f2 | sed -e "s|^./||" grep -i -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
} }
if [ -n "$LISTONLY" ] ; then if [ -n "$LISTONLY" ] ; then
fn=''
for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do
# TODO: return full url? someone use old behaviour? # TODO: return full url? someone use old behaviour?
echo "$fn" | sed -e "s|$URL/||" echo "$(basename "$fn")"
done done
test -n "$fn"
exit exit
fi fi
ERROR=0 ERROR=0
fn=''
for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do for fn in $(get_urls | filter_glob "$MASK" | filter_order) ; do
echo "$fn" | grep -q "://" && furl=$fn || furl="$URL/$fn" sget "$URL/$(basename "$fn")" || ERROR=1
sget "$furl" || ERROR=1
done done
test -n "$fn" || ERROR=1
exit $ERROR exit $ERROR
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