22 if [
"$*" ==
"help" ]; then
23 ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME => x86_64" 27 [ -d /lib64 ] && echo
"x86_64" || echo
"i386" 41 # Si se solicita, mostrar ayuda. 42 if [
"$*" ==
"help" ]; then
43 ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
44 "$FUNCNAME 1 2 => Linux" 47 ogGetOsVersion
"$@" | cut -sf1 -d:
67 # Si se solicita, mostrar ayuda. 68 if [
"$*" ==
"help" ]; then
69 ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
70 "$FUNCNAME 1 2 => 540e47c6-8e78-4178-aa46-042e4803fb16" 73 # Error si no se reciben 2 parametros. 76 # Montar la particion, si no lo estaba previamente. 77 MNTDIR=$(
ogMount $1 $2) ||
return $?
79 # Obtener UUID según el tipo de sistema operativo.
80 case
"$(ogGetOsType $1 $2)" in
82 # Leer el UUID del sistema de ficheros raíz o el fichero de identificador. 83 findmnt -no UUID $MNTDIR 2>/dev/null || cat $MNTDIR/etc/machine-
id 2>/dev/null
86 # Leer identificador en clave de registro.
104 # Si se solicita, mostrar ayuda. 105 if [
"$*" ==
"help" ]; then
106 ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME => 123456" 110 # Obtener nº de serie (ignorar los no especificados). 111 SERIALNO=$(dmidecode -s system-serial-number | egrep -vi
"(^[ 0]+$|not specified|to be filled|invalid entry|default string)")
112 # Quitar espacios y truncar cadena si >25 caracteres.
113 SERIALNO=
"${SERIALNO// /}" 114 [ ${#SERIALNO} -gt 25 ] && SERIALNO=
"${SERIALNO:0:22}..." 115 [ -n
"$SERIALNO" ] && echo
"$SERIALNO" 126 test -d /
sys/firmware/efi
146 # Si se solicita, mostrar ayuda. 147 if [
"$*" ==
"help" ]; then
148 ogHelp "$FUNCNAME" "$FUNCNAME" 152 # Recopilación de dispositivos procesando la salida de \c lshw 153 ogEcho info
"$MSG_HARDWAREINVENTORY}" 154 echo
"cha=$(dmidecode -s chassis-type)" | grep -v
"Other" 155 [ -e /
sys/firmware/efi ] && echo
"boo=UEFI" || echo
"boo=BIOS" 156 lshw |
awk 'BEGIN {type="mod";} 157 /product:/ {sub(/ *product: */,""); prod=$0;} 158 /vendor:/ {sub(/ *vendor: */,""); vend=$0;} 159 /version:/ {sub(/ *version: */,"v.");vers=$0;} 162 /slot:/ {sub(/ *slot: */,""); slot=$0;} 163 /\*-/ {if (type=="mem"){ 166 print type"="vend,prod,size,clock" ("slot")";} 168 if (type=="totalmem"){ 170 totalmemory="mem="size;} 172 if (type!="" && prod!=""){ 175 print type"="vend,prod,size,vers;} } 177 type=prod=vend=vers=size=clock=slot="";} 178 $1~/-core/ {type="boa";} 179 $1~/-firmware/ {type="bio";} 180 $1~/-cpu/ {type="cpu";} 181 $1~/-bank/ {type="mem";} 182 $1~/-memory/ {type="totalmem";} 183 $1~/-ide/ {type="ide";} 184 $1~/-storage/ {type="sto";} 185 $1~/-disk/ {type="dis";} 186 $1~/-cdrom/ {type="cdr";} 187 $1~/-display/ {type="vga";} 188 $1~/-network/ {type="net";} 189 $1~/-multimedia/ {type="mul";} 190 $1~/-usb/ {type="usb";} 191 $1~/-firewire/ {type="fir";} 192 $1~/-serial/ {type="bus";} 193 END {if (type!="" && prod!="") 194 print type"="vend,prod,size,vers; 195 if (length(numbank)==0 && length(totalmemory)>=4) 198 # */ (comentario para Doxygen) 227 local APPS HIVE k KEYS KEYS32 MNTDIR PKGDIR PROG VERS TMPFILE TYPE
229 # Si se solicita, mostrar ayuda. 230 if [
"$*" ==
"help" ]; then
231 ogHelp "$FUNCNAME" "$FUNCNAME 1 1" 234 # Error si no se reciben 2 parametros. 237 # Obtener tipo de sistema de archivos y montarlo. 238 MNTDIR=$(
ogMount $1 $2) ||
return $?
241 # Ficheros temporales. 242 APPS=$(mktemp /tmp/apps.XXXXX)
243 TMPFILE=$(mktemp /tmp/tmp.XXXXX)
244 trap
"rm -f $APPS $TMPFILE" 1 2 3 9 15
247 Linux) # Software de GNU/Linux.
248 # Procesar paquetes dpkg.
249 PKGDIR=
"${MNTDIR}/var/lib/dpkg" 250 if [ -r $PKGDIR ]; then
251 # Proceso de fichero en sistemas de 64 bits.
252 awk '/Package:/ {if (pack!="") print pack,vers; 255 /Version:/ {sub(/^.*:/,"",$2); sub(/-.*$/,"",$2); 257 /Status:/ {if ($2!="install") pack=vers=""} 258 END {if (pack!="") print pack,vers} 259 ' $PKGDIR/status > $APPS
261 # Procesar paquetes RPM.
262 PKGDIR=
"${MNTDIR}/var/lib/rpm" 263 if [ -r $PKGDIR ]; then
264 # Listar si está instalado el paquete
"rpm" en el cliente.
265 if which rpm &>/dev/null; then
266 rm -f ${PKGDIR}/__db.*
267 rpm --dbpath $PKGDIR -qa --qf
"%{NAME} %{VERSION}\n" 2>/dev/null |
\ 268 awk '$1!~/-devel$/ {sub(/-.*$/,"",$2); print $0}' > $APPS
269 rm -f ${PKGDIR}/__db.*
271 # Obtener el nombre de cada paquete en la BD de RPM. 275 db=bsddb.hashopen('$PKGDIR/Name','r'); 277 print re.sub('-devel$','',k);" > $APPS
280 # Procesar paquetes pacman. 281 PKGDIR=
"${MNTDIR}/var/lib/pacman/local" 282 if [ -r $PKGDIR ]; then
283 ls $PKGDIR |
awk -F-
'/-/ {print gensub(/-/, " ", NF-2);}' > $APPS
285 # Procesar aplicaciones Snappy. 286 PKGDIR=
"${MNTDIR}/snap" 433 [ -r $FILE ] && VERSION="Android $(
awk -F=
'$1~/(product.brand|build.version.release)/ {print $2}' $FILE | tr
'\n' ' ')
" 434 [ -e $MNTDIR/lib64 ] && IS64BIT="$MSG_64BIT
" 436 # Para GNU/Hurd, comprobar fichero de inicio (basado en os-prober). 437 if [ -z "$VERSION
" ]; then 439 FILE="$MNTDIR/hurd/init
" 440 [ -r $FILE ] && VERSION="GNU/Hurd
" 442 # Para Windows: leer la version del registro. 443 if [ -z "$VERSION
" ]; then 446 if [ -n "$FILE
" ]; then 447 # Nuevo método más rápido para acceder al registro de Windows.. 448 VERSION=$(echo $(hivexsh << EOT 2>/dev/null 450 cd \Microsoft\Windows NT\CurrentVersion 455 [ -n "$(reglookup -H -p
"Microsoft/Windows/CurrentVersion/ProgramW6432Dir" "$FILE" 2>/dev/null)
" ] && IS64BIT="$MSG_64BIT
" 456 if [ -z "$VERSION
" ]; then 457 # Compatibilidad con métrodo antiguo y más lento de acceder al registro. 458 VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName' 2>/dev/null) 459 [ -n "$(
ogGetRegistryValue $MNTDIR software
'\Microsoft\Windows\CurrentVersion\ProgramW6432Dir' 2>/dev/null)
" ] && IS64BIT="$MSG_64BIT
" 463 # Para cargador Windows: buscar versión en fichero BCD (basado en os-prober). 464 if [ -z "$VERSION
" ]; then 467 [ -z "$FILE
" ] && FILE="$(
ogGetPath $MNTDIR/EFI/Microsoft/boot/bcd)
" 468 if [ -n "$FILE
" ]; then 469 for DISTRIB in "Windows Recovery
" "Windows
Boot"; do 470 if grep -aqs "$(echo
"$DISTRIB" | sed
's/./&./g')
" $FILE; then 471 VERSION="$DISTRIB loader
" 476 # Para macOS: detectar kernel y completar con fichero plist de información del sistema. 477 if [ -z "$VERSION
" ]; then 479 # Kernel de Mac OS (no debe ser fichero de texto). 480 FILE="$MNTDIR/mach_kernel
" 481 if [ -z "$(file -b $FILE | grep
'text')
" ]; then 482 # Obtener tipo de kernel. 483 [ -n "$(file -b $FILE | grep
'Mach-O')
" ] && VERSION="macOS
" 484 [ -n "$(file -b $FILE | grep
'Mach-O 64-bit')
" ] && IS64BIT="$MSG_64BIT
" 485 # Datos de configuración de versión de Mac OS. 486 FILE="$MNTDIR/
System/Library/CoreServices/SystemVersion.plist
" 487 [ -r $FILE ] && VERSION=$(awk -F"[<>]
" ' 488 /ProductName/ {getline;s=$3} 489 /ProductVersion/ {getline;v=$3} 490 END {print s,v}' $FILE) 491 # Datos de recuperación de macOS. 492 FILE="$MNTDIR/com.apple.recovery.boot
" 493 [ -r $FILE -a -n "$VERSION
" ] && VERSION="$VERSION recovery
" 496 # Para FreeBSD: obtener datos del Kernel. 497 ### TODO Revisar solución. 498 if [ -z "$VERSION
" ]; then 500 FILE="$MNTDIR/boot/kernel/kernel
" 501 if [ -r $FILE ]; then 502 VERSION="$(strings $FILE|
awk '/@.*RELEASE/ {sub(/@\(#\)/,""); print $1,$2}')
" 503 [ -n "$(file -b $FILE | grep
'x86-64')
" ] && IS64BIT="$MSG_64BIT
" 506 # Para Solaris: leer el fichero de versión. 507 ### TODO Revisar solución. 508 if [ -z "$VERSION
" ]; then 510 FILE="$MNTDIR/etc/release
" 511 [ -r $FILE ] && VERSION="$(head -1 $FILE)
" 513 # Para cargador GRUB, comprobar fichero de configuración. 514 if [ -z "$VERSION
" ]; then 516 for FILE in $MNTDIR/{,boot/}grub/menu.lst; do 517 [ -r $FILE ] && VERSION="GRUB Loader
" 519 #/* (comentario Doxygen) 520 for FILE in $MNTDIR/{,boot/}{grub{,2},EFI/*}/grub.cfg; do 521 [ -r $FILE ] && VERSION="GRUB2 Loader
" 524 #*/ (Comentario Doxygen) 525 # Mostrar resultado y salir sin errores. 526 [ -n "$VERSION
" ] && echo "$TYPE:$VERSION $IS64BIT
" function ogGetHivePath()
Función básica que devuelve el camino del fichero con una sección del registro. #.
function ogIsEfiActive()
Comprueba si el sistema tiene activo el arranque EFI.
Funciones para arranque y post-configuración de sistemas de archivos. #.
function ogRaiseError()
Devuelve el mensaje y el código de error correspondiente. #.
function ogHelp()
Muestra mensaje de ayuda para una función determinda. #.
Funciones básicas del sistema. #.
function ogGetPath()
Inicia el proceso de arranque de un sistema de archivos. #.
function ogGetRegistryValue()
Devuelve el dato de un valor del registro de Windows. #.
function ogListSoftware()
Lista el inventario de software instalado en un sistema operativo. #.
function ogGetOsType()
Devuelve el tipo del sistema operativo instalado. #.
function ogListHardwareInfo()
Lista el inventario de hardware de la máquina cliente. #.
function ogGetOsUuid()
Devuelve el UUID del sistema operativo instalado en un sistema de archivos. #.
function ogGetSerialNumber()
Obtiene el nº de serie del cliente. #.
function ogEcho()
Muestra mensajes en consola y lo registra en fichero de incidencias. #.