Commit 99f4e7cb authored by Vitaly Lipatov's avatar Vitaly Lipatov

rewrite eget

parent 28397e64
......@@ -20,37 +20,61 @@
# 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
# TODO:
# -P support
# If ftp protocol or have no asterisk, jus download
# TODO: use has()
if echo "$1" | grep -q "\(^ftp://\|[^*]$\)" ; then
$WGET $1 && exit 0
$WGET "$1"
exit
fi
URL=$(echo $1 | grep /$ || dirname $1)
MASK=$(basename $1)
MYTMPDIR="$(mktemp -d)"
DIRALLFILES="$MYTMPDIR/files/"
get_index(){
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
$WGET $URL -O $INDEX
}
save_temp_files(){
mkdir -p $DIRALLFILES
ALLFILES="$MYTMPDIR/allfiles"
cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 > $ALLFILES
while read line ; do
touch $DIRALLFILES/$line
done <$ALLFILES
print_files()
{
cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
}
create_fake_files()
{
DIRALLFILES="$MYTMPDIR/files/"
mkdir -p "$DIRALLFILES"
print_files | while read line ; do
touch $DIRALLFILES/$(basename "$line")
done
}
sort_files(){
download_files()
{
ERROR=0
for line in $DIRALLFILES/$MASK ; do
$WGET $URL/`basename "$line"` -P $CURRENTDIR/
$WGET $URL/$(basename "$line") || ERROR=1
done
return $ERROR
}
get_index
save_temp_files
sort_files
get_index || exit
create_fake_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