diff options
| author | luisgulo <luisgulo@gmail.com> | 2025-10-24 18:01:10 +0200 |
|---|---|---|
| committer | luisgulo <luisgulo@gmail.com> | 2025-10-24 18:01:10 +0200 |
| commit | 533e79ba959143f0459431a486bfb85c56c72ddc (patch) | |
| tree | 91974de1bbbdc4c51c76ed591fc5c6e02a3342b6 /core/modules/download.sh | |
| parent | 45019c81cfd0fc1d18dce18cdfd5f127c6d61073 (diff) | |
Releasing code version 1.8.0
Diffstat (limited to 'core/modules/download.sh')
| -rw-r--r-- | core/modules/download.sh | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/core/modules/download.sh b/core/modules/download.sh new file mode 100644 index 0000000..a71fcc4 --- /dev/null +++ b/core/modules/download.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Module: download +# Description: Descarga ficheros remotos con soporte para reintentos, proxy y reanudación +# Author: Luis GuLo +# Version: 1.1.0 +# Dependencies: wget o curl, sudo (si become=true) + +download_task() { + local host="$1"; shift + declare -A args + for arg in "$@"; do key="${arg%%=*}"; value="${arg#*=}"; args["$key"]="$value"; done + + local url="${args[url]}" + local dest="${args[dest]:-$(basename "$url")}" + local proxy="${args[proxy]:-}" + local continue="${args[continue]:-true}" + local become="${args[become]}" + local prefix="" + [ "$become" = "true" ] && prefix="sudo" + + # 🌐 Cargar traducciones + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/download.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile"; fi + + if [[ -z "$url" ]]; then + echo "${tr[missing_url]:-❌ [download] Falta el parámetro obligatorio 'url'}" + return 1 + fi + + local cmd="" + if command -v wget &>/dev/null; then + echo "${tr[using_wget]:-📦 [download] Usando wget}" + cmd="$prefix wget \"$url\" -O \"$dest\"" + [[ "$continue" == "true" ]] && cmd="$cmd -c" + [[ -n "$proxy" ]] && cmd="$cmd -e use_proxy=yes -e http_proxy=\"$proxy\"" + elif command -v curl &>/dev/null; then + echo "${tr[using_curl]:-📦 [download] Usando curl}" + cmd="$prefix curl -L \"$url\" -o \"$dest\"" + [[ "$continue" == "true" ]] && cmd="$cmd -C -" + [[ -n "$proxy" ]] && cmd="$cmd --proxy \"$proxy\"" + else + echo "${tr[missing_tool]:-❌ [download] Ni wget ni curl están disponibles}" + return 1 + fi + + echo "$(render_msg "${tr[start]}" "url=$url" "dest=$dest")" + eval "$cmd" && echo "$(render_msg "${tr[done]}" "dest=$dest")" +} + +check_dependencies_download() { + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/download.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile"; fi + + if ! command -v wget &>/dev/null && ! command -v curl &>/dev/null; then + echo "${tr[missing_tool]:-❌ [download] Se requiere 'wget' o 'curl'}" + return 1 + fi + echo "${tr[deps_ok]:-✅ [download] Herramienta de descarga disponible}" + return 0 +} |
