Repository navigation
Expand file tree
/
Copy pathdistro
More file actions
executable file
·56 lines (46 loc) · 1.81 KB
/
Copy pathdistro
File metadata and controls
executable file
·56 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Función principal de detección
detectar_distro() {
# 1. Método principal: Usar /etc/os-release (ESTÁNDAR MODERNO)
if [ -f "/etc/os-release" ]; then
# Carga las variables del archivo (NAME, ID, VERSION_ID, etc.)
. /etc/os-release
# Convierte el ID a minúsculas para comparaciones consistentes
local ID_MINUSCULAS=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
# Comprobación de distribuciones específicas
case "$ID_MINUSCULAS" in
# Familias Debian
debian)
echo "Distribución: Debian"
;;
ubuntu)
echo "Distribución: Ubuntu"
;;
# Familias Red Hat (RHEL, CentOS, Fedora)
rhel)
echo "Distribución: Red Hat Enterprise Linux (RHEL)"
;;
centos)
echo "Distribución: CentOS"
;;
# Familia Arch
arch | archarm)
echo "Distribución: Arch Linux"
;;
# Si no coincide exactamente, muestra el nombre (ej. Mint, Pop!_OS)
*)
echo "Distribución (Base OS-RELEASE): $NAME $VERSION_ID"
;;
esac
# 2. Método de respaldo: Usar lsb_release (LEGADO)
elif command -v lsb_release &> /dev/null; then
echo "Distribución (Base LSB): $(lsb_release -ds)"
# 3. Método de último recurso: Archivos específicos
elif [ -f "/etc/redhat-release" ]; then
# Atrapa versiones muy antiguas de RHEL/CentOS
echo "Distribución (Base RedHat-release): $(cat /etc/redhat-release)"
else
echo "Error: No se pudo detectar la distribución de Linux."
fi
}
detectar_distro