hotfix install packages to gnu/linux distros - install.sh
This commit is contained in:
parent
14ae23997e
commit
096ffbaed4
97
install.sh
97
install.sh
@ -27,32 +27,54 @@ function msg_err() {
|
||||
esac
|
||||
}
|
||||
|
||||
# ----------
|
||||
# Get OS ID
|
||||
# ----------
|
||||
function get_os_id() {
|
||||
cat /etc/*release 2>/dev/null |
|
||||
tr '[:upper:]' '[:lower:]' |
|
||||
grep "^id=" | head -n1 | cut -d= -f2 | tr -d '"'
|
||||
}
|
||||
|
||||
# -------------------------
|
||||
# Map programs to packages
|
||||
# -------------------------
|
||||
function map_program_to_package() {
|
||||
local program="$1"
|
||||
local os="$2"
|
||||
|
||||
case "$program" in
|
||||
ls) echo "coreutils" ;;
|
||||
iproute2)
|
||||
case "$os" in
|
||||
fedora|rhel|centos|amzn|rocky|almalinux) echo "iproute" ;;
|
||||
*) echo "iproute2" ;;
|
||||
esac
|
||||
;;
|
||||
*) echo "$program" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ---------------------
|
||||
# Check Requirements
|
||||
# -------------------
|
||||
function install_package() {
|
||||
local pkg="$1"
|
||||
local os="$2"
|
||||
local sudo_cmd=""
|
||||
local OS_ID=""
|
||||
|
||||
# Determine if root or use sudo/doas
|
||||
case "$(id -u)" in
|
||||
0) sudo_cmd="" ;;
|
||||
*)
|
||||
case "$(command -v doas 2>/dev/null)" in
|
||||
"") sudo_cmd="sudo" ;;
|
||||
*) sudo_cmd="doas" ;;
|
||||
esac
|
||||
if command -v doas &>/dev/null; then
|
||||
sudo_cmd="doas"
|
||||
else
|
||||
sudo_cmd="sudo"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get OS ID (e.g., arch, debian, ubuntu, fedora, alpine, etc.)
|
||||
OS_ID=$(
|
||||
cat /etc/*release 2>/dev/null |
|
||||
tr '[:upper:]' '[:lower:]' |
|
||||
grep "^id=" | head -n1 | cut -d= -f2 | tr -d '"'
|
||||
)
|
||||
|
||||
case "$OS_ID" in
|
||||
case "$os" in
|
||||
arch|manjaro|endeavouros|hyperbola|artix)
|
||||
$sudo_cmd pacman -Sy --noconfirm "$pkg"
|
||||
;;
|
||||
@ -76,32 +98,37 @@ function install_package() {
|
||||
$sudo_cmd apk add --no-cache "$pkg"
|
||||
;;
|
||||
*)
|
||||
msg_err "Sistema operativo no soportado: $OS_ID" "Unsupported OS: $OS_ID"
|
||||
msg_err "Sistema operativo no soportado: $os" "Unsupported OS: $os"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
programs=("curl" "less" "ls" "iproute2" "unzip")
|
||||
for program in "${programs[@]}"; do
|
||||
if ! command -v "$program" &>/dev/null; then
|
||||
case "$program" in
|
||||
ls) pkg="coreutils" ;;
|
||||
iproute2)
|
||||
case "$OS_ID" in
|
||||
fedora|rhel|centos) pkg="iproute" ;;
|
||||
*) pkg="iproute2" ;;
|
||||
esac
|
||||
;;
|
||||
*) pkg="$program" ;;
|
||||
esac
|
||||
# ---------------------------
|
||||
# Check and install programs
|
||||
# ---------------------------
|
||||
function check_and_install_programs() {
|
||||
local os_id
|
||||
os_id=$(get_os_id)
|
||||
local programs=("curl" "less" "ls" "iproute2" "unzip")
|
||||
|
||||
for prog in "${programs[@]}"; do
|
||||
if ! command -v "$prog" &>/dev/null; then
|
||||
local pkg
|
||||
pkg=$(map_program_to_package "$prog" "$os_id")
|
||||
msg "Instalando dependencia: $pkg" "Installing dependency: $pkg"
|
||||
install_package "$pkg"
|
||||
install_package "$pkg" "$os_id"
|
||||
fi
|
||||
done
|
||||
}
|
||||
# ---------------------
|
||||
# Install dependencies
|
||||
# ---------------------
|
||||
check_and_install_programs "$@"
|
||||
|
||||
# ------------------------
|
||||
# Check URLs availability
|
||||
# -----------------------
|
||||
# ------------------------
|
||||
function _url_exists() {
|
||||
curl --output /dev/null --silent --head --write-out "%{http_code}" "$1"
|
||||
}
|
||||
@ -124,6 +151,7 @@ function _urls() {
|
||||
esac
|
||||
}
|
||||
|
||||
# -----------
|
||||
# Show usage
|
||||
# -----------
|
||||
function show_usage() {
|
||||
@ -142,6 +170,7 @@ function show_usage() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# --------------------------
|
||||
# Download and unzip archive
|
||||
# --------------------------
|
||||
function download_and_unzip() {
|
||||
@ -182,8 +211,9 @@ function download_and_unzip() {
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
|
||||
# -------------------
|
||||
# Backup and install
|
||||
# ------------------
|
||||
# -------------------
|
||||
function backup_and_install() {
|
||||
download_and_unzip
|
||||
|
||||
@ -197,8 +227,9 @@ function backup_and_install() {
|
||||
"\033[0;36mTemplate copied to ~/$CONFIG_FILE \033[0m"
|
||||
}
|
||||
|
||||
# -----------
|
||||
# Parse args
|
||||
# ----------
|
||||
# -----------
|
||||
for param in "$@"; do
|
||||
shift
|
||||
case "$param" in
|
||||
@ -220,7 +251,9 @@ while getopts "hsn" opt; do
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
# ------------------------------
|
||||
# Setup config file based on OS
|
||||
# ------------------------------
|
||||
case "$OSTYPE" in
|
||||
darwin*) CONFIG_FILE=".bash_profile" ;;
|
||||
*) CONFIG_FILE=".bashrc" ;;
|
||||
|
Loading…
x
Reference in New Issue
Block a user