diff options
author | Thomas Riccardi <riccardi.thomas@gmail.com> | 2013-06-09 01:16:04 +0200 |
---|---|---|
committer | Thomas Riccardi <riccardi.thomas@gmail.com> | 2013-06-09 01:23:37 +0200 |
commit | 2a15d09ba0a63553aa05b127dceeceddec4020b1 (patch) | |
tree | f35fe2bfceac056a688da6a165f620965efd6b9a | |
parent | 4eb10093fb95e9e75f2e89aec2a912c7c8990952 (diff) | |
download | hib-dlagent-2a15d09ba0a63553aa05b127dceeceddec4020b1.tar.gz hib-dlagent-2a15d09ba0a63553aa05b127dceeceddec4020b1.zip |
Add -d STORAGE directory: if set, the script will first search in this directory if the file is present. If not, it will be downloaded there.
-rwxr-xr-x | hib-dlagent | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/hib-dlagent b/hib-dlagent index e575123..70e22f4 100755 --- a/hib-dlagent +++ b/hib-dlagent @@ -13,6 +13,7 @@ LISTING_PAGES=() USERNAME= PASSWORD= KEYS=() +STORAGE= login() { /usr/bin/curl -s --cookie-jar "$COOKIE_JAR" \ @@ -31,6 +32,7 @@ usage() { echo echo "Usage: $0 [OPTIONS] FILE" echo "Options:" + echo " -d Storage directory to look first" echo " -h This help" echo " -k <key> Search key's files. Use multiple times for multiple keys" echo " -o <file> Name to use when saving file" @@ -52,7 +54,7 @@ main() { exit 1 fi - while getopts "hk:o:p:su:" opt; do + while getopts "hd:k:o:p:su:" opt; do case $opt in \?) exit 1 @@ -61,6 +63,9 @@ main() { usage exit 1 ;; + d) + STORAGE="$OPTARG" + ;; k) KEYS+=("$OPTARG") ;; @@ -112,6 +117,15 @@ main() { exit 1 fi + if [ -n "$STORAGE" ]; then + STORAGE_FILE=$(/usr/bin/find "$STORAGE" -name "$FILE") + if [ -n "$STORAGE_FILE" ]; then + echo "Found file: $STORAGE_FILE" + ln -s "$STORAGE_FILE" "$DESTINATION" + return; + fi + fi + for LISTING_PAGE in "${LISTING_PAGES[@]}"; do URL=$(discover_url "$LISTING_PAGE") if [ -n "$URL" ]; then break; fi @@ -128,6 +142,10 @@ main() { if [ $DOWNLOAD -eq 0 ]; then echo "$URL" else + if [ -n "$STORAGE" ]; then + ln -s "$STORAGE/$FILE" "$DESTINATION" + DESTINATION="$STORAGE/$FILE" + fi /usr/bin/curl -C - --retry 3 --retry-delay 3 -o "$DESTINATION" "$URL" fi } |