Commit 56379277 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: improve options parsing

parent 25e445f9
...@@ -207,23 +207,22 @@ CURLQ='' #-s ...@@ -207,23 +207,22 @@ CURLQ='' #-s
WGETNAMEOPTIONS='--content-disposition' WGETNAMEOPTIONS='--content-disposition'
CURLNAMEOPTIONS='--remote-name --remote-header-name' CURLNAMEOPTIONS='--remote-name --remote-header-name'
LISTONLY=''
CHECKURL=''
LATEST=''
SECONDLATEST=''
CHECKMIRRORS=''
TARGETFILE=''
set_quiet() set_quiet()
{ {
WGETQ='-q' WGETQ='-q'
CURLQ='-s' CURLQ='-s'
} }
# TODO: parse options in a good way
# TODO:
# -P support
if [ -z "$1" ] ; then eget_help()
echo "eget - wget like downloader wrapper with wildcard support, uses wget or curl as backend" >&2 {
fatal "Run $0 --help to get help"
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "eget - wget like downloader wrapper with wildcard support in filename part of URL" echo "eget - wget like downloader wrapper with wildcard support in filename part of URL"
echo "Usage: eget [-q] [-k] [-U] [-O target file] [--list] http://somesite.ru/dir/na*.log" echo "Usage: eget [-q] [-k] [-U] [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo echo
...@@ -246,71 +245,66 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then ...@@ -246,71 +245,66 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo " $ eget --check http://ftp.somesite.ru/test" echo " $ eget --check http://ftp.somesite.ru/test"
echo " $ eget --list http://download.somesite.ru 'package-*.tar.xz'" echo " $ eget --list http://download.somesite.ru 'package-*.tar.xz'"
echo " $ eget --list --latest https://github.com/telegramdesktop/tdesktop/releases 'tsetup.*.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" }
exit
fi
# TODO: passthrou all wget options if [ -z "$1" ] ; then
if [ "$1" = "-q" ] ; then echo "eget - wget like downloader wrapper with wildcard support, uses wget or curl as backend" >&2
set_quiet echo "Run $0 --help to get help" >&2
shift exit 1
fi fi
if [ "$1" = "-k" ] || [ "$1" = "--no-check-certificate" ] ; then
while [ -n "$1" ] ; do
case "$1" in
-h|--help)
eget_help
exit
;;
-q)
set_quiet
;;
-k|--no-check-certificate)
WGETNOSSLCHECK='--no-check-certificate' WGETNOSSLCHECK='--no-check-certificate'
CURLNOSSLCHECK='-k' CURLNOSSLCHECK='-k'
shift ;;
fi -U|-A|--user-agent)
if [ "$1" = "-U" ] || [ "$1" = "-A" ] || [ "$1" = "--user-agent" ] ; then
user_agent="Mozilla/5.0 (X11; Linux $arch) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" user_agent="Mozilla/5.0 (X11; Linux $arch) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
WGETUSERAGENT="-U '$user_agent'" WGETUSERAGENT="-U '$user_agent'"
CURLUSERAGENT="-A '$user_agent'" CURLUSERAGENT="-A '$user_agent'"
shift ;;
fi --list)
LISTONLY=''
if [ "$1" = "--list" ] ; then
LISTONLY="$1" LISTONLY="$1"
set_quiet set_quiet
shift ;;
fi --check)
if [ "$1" = "--check" ] ; then
CHECKURL="$1" CHECKURL="$1"
shift set_quiet
fi ;;
--latest)
LATEST=''
if [ "$1" = "--latest" ] ; then
LATEST="$1" LATEST="$1"
shift ;;
fi --second-latest)
SECONDLATEST=''
if [ "$1" = "--second-latest" ] ; then
SECONDLATEST="$1" SECONDLATEST="$1"
shift ;;
fi --check-mirrors)
CHECKMIRRORS=''
if [ "$1" = "--check-mirrors" ] ; then
CHECKMIRRORS="$1" CHECKMIRRORS="$1"
;;
-O)
shift shift
fi TARGETFILE="$1"
;;
-O-)
# download to this file
TARGETFILE=''
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
shift 2
elif [ "$1" = "-O-" ] ; then
TARGETFILE="-" TARGETFILE="-"
shift 1 ;;
fi *)
break
;;
esac
shift
done
......
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