From b156771461db7f06bcb441f5a658f2f3a8a975d9 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 11 Mar 2020 11:46:36 +0000 Subject: [PATCH] Adds script to download an open directory --- bin/.bin/download-odir | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 bin/.bin/download-odir diff --git a/bin/.bin/download-odir b/bin/.bin/download-odir new file mode 100755 index 00000000..e282ece2 --- /dev/null +++ b/bin/.bin/download-odir @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +directory="" +dryrun="false" + + +function multigrep(){ + # will grep for each argument passed + + if [ -n "$1" ]; then + local i="$1" + shift + cat - | grep "$i" | multigrep "$@" + else + cat - + fi +} + +function main(){ + if [ "$dryrun" == "true" ]; then + curl "$directory" | hq a attr href | multigrep "$@" + else + curl "$directory" | hq a attr href | multigrep "$@" | awk "{print \"$directory\" \$1}" | aria2c -i - + fi +} + +if [ -n "$1" ]; then + while [ -n "$1" ]; do + case "$1" in + "-d"|"--dry-run") + dryrun="true" + shift + ;; + *) + directory="$1" + shift + main "$@" + exit 0 + ;; + esac + done + +else + echo "No url passed" +fi + +shift +curl "$directory" | hq a attr href | multigrep "$@"