#!/bin/sh . scripts/common download() { local file="$1" local url="$2" local ret if [[ -f $file ]]; then return 0 fi begin "from $url"; { if type aria2c >/dev/null 2>/dev/null; then ( builtin cd "$(dirname "$file")" aria2c -j 10 -s 10 -o "$(basename "$file.tmp")" "$url" && mv "$file.tmp" "$file" ) ret=$? elif type wget >/dev/null 2>/dev/null; then wget -c -O "$file.tmp" "$url" && mv "$file.tmp" "$file" ret=$? else curl -C - -o "$file.tmp" "$url" && mv "$file.tmp" "$file" ret=$? fi rm -f "$file.tmp" }; [[ $ret -eq 0 ]] && end || end "not found" return $ret } cleanup() { local file for file in "$sourceDir/"*.bz2 "$sourceDir/"*.zip; do if [[ -f $file && ! -s $file ]]; then rm -f "$file" fi done exit } download_x() { local filename=$1 shift local url local ret=1 begin "Downloading $filename"; { while [ $# -gt 0 ]; do url=$1 shift if download "$sourceDir/$filename" $url; then ret=0 break fi done }; [[ $ret -eq 0 ]] && end "downloaded" || end "not found" return $ret } trap cleanup exit phpFiles_foreach download_x