Commit 31994fe4 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add --check support for check url if accessible

parent faa7beda
......@@ -174,6 +174,12 @@ sget()
fi
}
check_url_http()
{
local URL="$1"
__wget --spider -S "$URL" 2>&1 | grep "HTTP" | tail -n1 | grep -q -w "200\|301"
}
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"
......@@ -201,6 +207,13 @@ sget()
__curl $CURLNAMEOPTIONS "$1"
fi
}
check_url_http()
{
local URL="$1"
__curl -I "$URL" 2>&1 | grep "HTTP" | tail -n1 | grep -q -w "200\|301"
}
fi
LISTONLY=''
......@@ -210,6 +223,14 @@ if [ "$1" = "--list" ] ; then
shift
fi
if [ "$1" = "--check" ] ; then
set_quiet
shift
check_url_http "$1"
exit
fi
LATEST=''
if [ "$1" = "--latest" ] ; then
LATEST="$1"
......@@ -264,6 +285,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo " -U|-A|--user-agent - send browser like UserAgent"
echo " -O file - download to this file (use filename from server if missed)"
echo " --list - print files from url with mask"
echo " --check - check if URL is accessible (returns HTTP 200 OK)"
echo " --latest - print only latest version of a file"
echo
echo "eget supports --list and download for https://github.com/owner/project urls"
......@@ -271,6 +293,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "Examples:"
echo " $ eget --list http://ftp.somesite.ru/package-*.tar"
echo " $ eget http://ftp.somesite.ru/package-*.x64.tar"
echo " $ eget --check http://ftp.somesite.ru/test"
echo " $ eget --list http://download.somesite.ru 'package-*.tar.xz'"
echo " $ eget --list --latest https://github.com/telegramdesktop/tdesktop/releases 'tsetup.*.tar.xz'"
# echo "See $ wget --help for wget options you can use here"
......
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