diff options
author | Jesus <heckyel@hyperbola.info> | 2025-05-18 20:09:31 -0500 |
---|---|---|
committer | Jesus <heckyel@hyperbola.info> | 2025-05-18 20:09:31 -0500 |
commit | c98c789f32ac45ca231350b8bacca07692afe749 (patch) | |
tree | acda5ecbb4bbc297478ae3027fe57a98f5ad56f7 /hyperterm/core/autodep.sh | |
parent | d5e477f13dd41081bba461eb9ae34423d91f5790 (diff) | |
download | hyperterm-c98c789f32ac45ca231350b8bacca07692afe749.tar.lz hyperterm-c98c789f32ac45ca231350b8bacca07692afe749.tar.xz hyperterm-c98c789f32ac45ca231350b8bacca07692afe749.zip |
Add autodep.sh
Diffstat (limited to 'hyperterm/core/autodep.sh')
-rw-r--r-- | hyperterm/core/autodep.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/hyperterm/core/autodep.sh b/hyperterm/core/autodep.sh new file mode 100644 index 0000000..a106c82 --- /dev/null +++ b/hyperterm/core/autodep.sh @@ -0,0 +1,63 @@ +#!/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 +} |