Commit 1ee5b413 authored by Vitaly Lipatov's avatar Vitaly Lipatov

update eget from eepm project

parent 4b7f3a2b
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
# Example use: # Example use:
# eget ftp://ftp.altlinux.ru/pub/security/ssl/* # eget ftp://ftp.altlinux.ru/pub/security/ssl/*
# #
# Copyright (C) 2014-2014 Etersoft # Copyright (C) 2014-2014, 2016 Etersoft
# Copyright (C) 2014-2014 Daniil Mikhailov <danil@etersoft.ru> # Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -20,37 +21,71 @@ ...@@ -20,37 +21,71 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
WGET="wget"
WGET="wget -q" if [ "$1" = "-q" ] ; then
WGET="wget -q"
shift
fi
if echo "$1" | grep -q "\(^ftp://\|[^*]$\)" ; then # TODO:
$WGET $1 && exit 0 # download to this file
WGET_OPTION_TARGET=
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
WGET_OPTION_TARGET="-O $2"
shift 2
fi fi
URL=$(echo $1 | grep /$ || dirname $1)
MASK=$(basename $1)
MYTMPDIR="$(mktemp -d)"
DIRALLFILES="$MYTMPDIR/files/"
get_index(){ # TODO:
# -P support
# If ftp protocol or have no asterisk, just download
# TODO: use has()
if echo "$1" | grep -q "^ftp://" || echo "$1" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1"
exit
fi
echo "Fall to http workaround"
URL=$(echo "$1" | grep "/$" || dirname "$1")
# mask allowed only in last part of path
MASK=$(basename "$1")
get_index()
{
MYTMPDIR="$(mktemp -d)"
INDEX=$MYTMPDIR/index INDEX=$MYTMPDIR/index
$WGET $URL -O $INDEX $WGET $URL -O $INDEX
} }
save_temp_files(){ print_files()
mkdir -p $DIRALLFILES {
ALLFILES="$MYTMPDIR/allfiles" cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 > $ALLFILES }
while read line ; do
touch $DIRALLFILES/$line create_fake_files()
done <$ALLFILES {
DIRALLFILES="$MYTMPDIR/files/"
mkdir -p "$DIRALLFILES"
print_files | while read -r line ; do
touch $DIRALLFILES/$(basename "$line")
done
rm -f $INDEX
} }
sort_files(){ download_files()
{
ERROR=0
for line in $DIRALLFILES/$MASK ; do for line in $DIRALLFILES/$MASK ; do
$WGET $URL/`basename "$line"` -P $CURRENTDIR/ $WGET $URL/$(basename "$line") || ERROR=1
done done
return $ERROR
} }
get_index get_index || { rm -rf "$MYTMPDIR" ; exit ; }
save_temp_files create_fake_files
sort_files download_files || echo "There was some download errors" >&2
rm -rf "$MYTMPDIR"
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