61d8460149
12 funciones Bash del dominio shell: utilidades de scripting (bash_log, bash_colors, bash_check_deps, bash_confirm, bash_handle_error, bash_safe_run), manipulacion de texto (convert_text_case), estructura de proyectos (create_project_structure), y operaciones git (git_clean_branches, git_log_visual, git_push_all_remotes, git_repo_status). Cada una con su .sh y .md de frontmatter.
76 lines
1.6 KiB
Bash
76 lines
1.6 KiB
Bash
# bash_check_deps
|
|
# ---------------
|
|
# Verifica existencia de comandos, directorios y archivos.
|
|
# Output formateado con colores via bash_log.
|
|
#
|
|
# USO (sourced):
|
|
# source bash_check_deps.sh
|
|
# check_command "docker" "DOCKER_NOT_FOUND" "Docker no esta instalado"
|
|
# check_commands "git" "curl" "jq"
|
|
# check_directory "/path/to/dir"
|
|
# check_file "/path/to/file"
|
|
|
|
SCRIPT_DIR_BASH_CHECK="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR_BASH_CHECK/bash_log.sh"
|
|
bash_log_init
|
|
|
|
check_command() {
|
|
local cmd="$1"
|
|
local error_code="${2:-COMMAND_NOT_FOUND}"
|
|
local description="${3:-El comando '$cmd' no esta disponible}"
|
|
|
|
debug "Verificando comando: $cmd"
|
|
|
|
if ! command -v "$cmd" &> /dev/null; then
|
|
error "$description ($error_code)"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
check_commands() {
|
|
local failed=0
|
|
for cmd in "$@"; do
|
|
if ! command -v "$cmd" &> /dev/null; then
|
|
error "Comando no encontrado: $cmd"
|
|
failed=1
|
|
fi
|
|
done
|
|
|
|
if [ $failed -eq 1 ]; then
|
|
error "Faltan multiples dependencias requeridas"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
check_directory() {
|
|
local dir="$1"
|
|
local error_msg="${2:-El directorio '$dir' no existe}"
|
|
|
|
debug "Verificando directorio: $dir"
|
|
|
|
if [ ! -d "$dir" ]; then
|
|
error "$error_msg"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
check_file() {
|
|
local file="$1"
|
|
local error_msg="${2:-El archivo '$file' no existe}"
|
|
|
|
debug "Verificando archivo: $file"
|
|
|
|
if [ ! -f "$file" ]; then
|
|
error "$error_msg"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|