Commit d5d6a57d authored by Vitaly Lipatov's avatar Vitaly Lipatov

tools_eget: add support for https://github.com/owner/project urls

parent 489efac7
......@@ -50,6 +50,7 @@ fatal()
# check man glob
filter_glob()
{
[ -z "$1" ] && cat && return
# translate glob to regexp
grep "^$(echo "$1" | sed -e "s|\*|.*|g" -e "s|?|.|g")$"
}
......@@ -79,14 +80,46 @@ 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
echo "Options:"
echo " --list - print files frm url with mask"
echo " --list - print files frm url with mask"
echo " --latest - print only latest version of file"
echo
wget --help
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"
exit
fi
get_github_urls()
{
# https://github.com/OWNER/PROJECT
local owner="$(echo "$1" | sed -e "s|^https://github.com/||" -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 "$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 | \
grep -i -o -E '"browser_download_url": "https://.*"' | cut -d'"' -f4
}
if echo "$1" | grep -q "^https://github.com/" ; then
MASK="$2"
if [ -n "$LISTONLY" ] ; then
get_github_urls "$1" | filter_glob "$MASK" | filter_order
exit
fi
for fn in $(get_github_urls "$1" | filter_glob "$MASK" | filter_order) ; do
$WGET "$fn" || ERROR=1
done
exit
fi
# do not support /
if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir"
......
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