Commit 128275aa authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: regroup functions

parent 5a8d5633
......@@ -27,6 +27,7 @@ fatal()
exit 1
}
# TODO:
arch="$(uname -m)"
......@@ -141,6 +142,24 @@ if [ "$1" = "-U" ] || [ "$1" = "-A" ] || [ "$1" = "--user-agent" ] ; then
shift
fi
# check man glob
filter_glob()
{
[ -z "$1" ] && cat && return
# translate glob to regexp
grep "$(echo "$1" | sed -e "s|\*|.*|g" -e "s|?|.|g")$"
}
filter_order()
{
if [ -n "$SECONDLATEST" ] ; then
sort -V | tail -n2 | head -n1
return
fi
[ -z "$LATEST" ] && cat && return
sort -V | tail -n1
}
# args: cmd <URL> <options>
# will run cmd <options> <URL>
download_with_mirroring()
......@@ -165,6 +184,52 @@ download_with_mirroring()
}
LISTONLY=''
if [ "$1" = "--list" ] ; then
LISTONLY="$1"
set_quiet
shift
fi
if [ "$1" = "--check" ] ; then
set_quiet
shift
check_url_is_accessible "$1"
exit
fi
LATEST=''
if [ "$1" = "--latest" ] ; then
LATEST="$1"
shift
fi
SECONDLATEST=''
if [ "$1" = "--second-latest" ] ; then
SECONDLATEST="$1"
shift
fi
CHECKMIRRORS=''
if [ "$1" = "--check-mirrors" ] ; then
CHECKMIRRORS="$1"
shift
fi
# download to this file
TARGETFILE=''
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
shift 2
elif [ "$1" = "-O-" ] ; then
TARGETFILE="-"
shift 1
fi
WGET="$(which wget 2>/dev/null)"
if [ -n "$WGET" ] ; then
......@@ -249,72 +314,6 @@ check_url_is_accessible()
fi
LISTONLY=''
if [ "$1" = "--list" ] ; then
LISTONLY="$1"
set_quiet
shift
fi
if [ "$1" = "--check" ] ; then
set_quiet
shift
check_url_is_accessible "$1"
exit
fi
LATEST=''
if [ "$1" = "--latest" ] ; then
LATEST="$1"
shift
fi
SECONDLATEST=''
if [ "$1" = "--second-latest" ] ; then
SECONDLATEST="$1"
shift
fi
CHECKMIRRORS=''
if [ "$1" = "--check-mirrors" ] ; then
CHECKMIRRORS="$1"
shift
fi
fatal()
{
echo "$*" >&2
exit 1
}
# check man glob
filter_glob()
{
[ -z "$1" ] && cat && return
# translate glob to regexp
grep "$(echo "$1" | sed -e "s|\*|.*|g" -e "s|?|.|g")$"
}
filter_order()
{
if [ -n "$SECONDLATEST" ] ; then
sort -V | tail -n2 | head -n1
return
fi
[ -z "$LATEST" ] && cat && return
sort -V | tail -n1
}
# download to this file
TARGETFILE=''
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
shift 2
elif [ "$1" = "-O-" ] ; then
TARGETFILE="-"
shift 1
fi
# TODO:
# -P support
......
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