#!/usr/bin/env sh # lib/os-detect.sh — shared OS/package-manager detection for module installers. # Source this, then call pkg_install [pkg...]. detect_pkg_family() { if [ -f /etc/os-release ]; then # shellcheck disable=SC1091 id_line="$(. /etc/os-release && printf '%s %s' "${ID:-}" "${ID_LIKE:-}")" case "$id_line" in *debian*|*ubuntu*) printf 'debian\n'; return 0 ;; *rhel*|*fedora*|*centos*) printf 'rhel\n'; return 0 ;; esac fi if command -v apt-get >/dev/null 2>&1; then printf 'debian\n'; return 0 fi if command -v dnf >/dev/null 2>&1 || command -v yum >/dev/null 2>&1; then printf 'rhel\n'; return 0 fi printf 'unknown\n' return 1 } pkg_install() { family="$(detect_pkg_family)" case "$family" in debian) sudo apt-get update -qq sudo apt-get install -y "$@" ;; rhel) if command -v dnf >/dev/null 2>&1; then sudo dnf install -y "$@" else sudo yum install -y "$@" fi ;; *) printf 'error: unsupported/undetected OS family; install manually: %s\n' "$*" >&2 return 1 ;; esac }