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/git.sh | |
| parent | 45019c81cfd0fc1d18dce18cdfd5f127c6d61073 (diff) | |
Releasing code version 1.8.0
Diffstat (limited to 'core/modules/git.sh')
| -rw-r--r-- | core/modules/git.sh | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/core/modules/git.sh b/core/modules/git.sh new file mode 100644 index 0000000..0fa22f1 --- /dev/null +++ b/core/modules/git.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# Module: git +# Description: Gestiona repositorios Git en hosts remotos (clone, pull, checkout, fetch-file) +# License: GPLv3 +# Author: Luis GuLo +# Version: 1.2.0 +# Dependencies: ssh, git, curl, tar + +git_task() { + local host="$1"; shift + declare -A args + for arg in "$@"; do key="${arg%%=*}"; value="${arg#*=}"; args["$key"]="$value"; done + + local action="${args[action]}" + local repo="${args[repo]}" + local dest="${args[dest]}" + local branch="${args[branch]}" + local file_path="${args[file_path]}" + local become="${args[become]}" + local prefix="" + [ "$become" = "true" ] && prefix="sudo" + + # 🌐 Cargar traducciones + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/git.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then + while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile" + fi + + case "$action" in + clone) + echo "$(render_msg "${tr[cloning]}" "repo=$repo" "dest=$dest")" + ssh "$host" "[ -d '$dest/.git' ] || $prefix git clone '$repo' '$dest'" + ;; + pull) + echo "$(render_msg "${tr[pulling]}" "dest=$dest")" + ssh "$host" "[ -d '$dest/.git' ] && cd '$dest' && $prefix git pull" + ;; + checkout) + echo "$(render_msg "${tr[checkout]}" "branch=$branch" "dest=$dest")" + ssh "$host" "[ -d '$dest/.git' ] && cd '$dest' && $prefix git checkout '$branch'" + ;; + fetch-file) + echo "$(render_msg "${tr[fetching]}" "file=$file_path" "repo=$repo" "branch=$branch")" + fetch_file_from_repo "$host" "$repo" "$branch" "$file_path" "$dest" "$become" + ;; + *) + echo "$(render_msg "${tr[unsupported]}" "action=$action")" + return 1 + ;; + esac +} + +fetch_file_from_repo() { + local host="$1" + local repo="$2" + local branch="$3" + local file_path="$4" + local dest="$5" + local become="$6" + local prefix="" + [ "$become" = "true" ] && prefix="sudo" + + ssh "$host" "$prefix git archive --remote='$repo' '$branch' '$file_path' | $prefix tar -xO > '$dest'" +} + +check_dependencies_git() { + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/git.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then + while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile" + fi + + local missing=() + for cmd in ssh git curl tar; do + command -v "$cmd" &> /dev/null || missing+=("$cmd") + done + + if [[ ${#missing[@]} -gt 0 ]]; then + echo "$(render_msg "${tr[missing_deps]}" "cmds=${missing[*]}")" + return 1 + fi + + echo "${tr[deps_ok]:-✅ [git] Todas las dependencias están disponibles}" + return 0 +} |
