hyperterm/hyperterm/core/autodep.sh
Jesus c98c789f32
All checks were successful
CI Pipeline / shasums (push) Successful in 31s
git-sync-with-mirror / git-sync (push) Successful in 43s
CI Pipeline / build (push) Successful in 4m24s
Add autodep.sh
2025-05-18 20:09:31 -05:00

64 lines
1.6 KiB
Bash

#!/bin/bash
function install_package() {
local pkg="$1"
if command -v "$pkg" &>/dev/null; then
return 0
fi
msg "El paquete $pkg no se encontró. Procediendo a instalar..." \
"$pkg not found. Attempting to install..."
local INSTALLER=""
local SUDO=""
local USER_CMD=$(command -v sudo || command -v doas)
[[ "$(id -u)" -ne 0 ]] && SUDO="$USER_CMD"
local OS_ID=""
if [ -f /etc/os-release ]; then
OS_ID=$(grep "^ID=" /etc/os-release | head -n1 | cut -d= -f2 | tr -d '"')
OS_ID=${OS_ID,,}
fi
case "$OS_ID" in
arch|manjaro|artix|hyperbola)
INSTALLER="pacman -Sy --noconfirm $pkg"
;;
debian|ubuntu|linuxmint|elementary|pop)
INSTALLER="apt-get update && apt-get install -y $pkg"
;;
fedora)
INSTALLER="dnf install -y $pkg"
;;
void)
INSTALLER="xbps-install -Sy $pkg"
;;
gentoo)
INSTALLER="emerge app-arch/$pkg"
;;
alpine)
INSTALLER="apk add $pkg"
;;
*)
msg_err "Distro no compatible con la instalación automática de $pkg." \
"Unsupported distro for automatic $pkg installation."
return 1
;;
esac
msg "Ejecutando instalación con: $SUDO $INSTALLER" \
"Running install command: $SUDO $INSTALLER"
$SUDO bash -c "$INSTALLER"
if command -v "$pkg" &>/dev/null; then
return 0
else
msg_err "Falló al instalar: $pkg" \
"Failed to install $pkg."
return 1
fi
}