source: client/engine/Inventory.lib @ a70996f

918-git-images-111dconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since a70996f was d230bb7, checked in by Ramón M. Gómez <ramongomez@…>, 5 years ago

#966: Function ogListSoftware also lists Flatpak and Snappy applications.

  • Property mode set to 100755
File size: 19.9 KB
Line 
1#!/bin/bash
2#/**
3#@file    Inventory.lib
4#@brief   Librería o clase Inventory
5#@class   Inventory
6#@brief   Funciones para recogida de datos de inventario de hardware y software de los clientes.
7#@version 1.1.0
8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogGetArch
14#@brief   Devuelve el tipo de arquitectura del cliente.
15#@return  str_arch - Arquitectura (i386 para 32 bits, x86_64 para 64 bits).
16#@version 0.9.2 - Primera versión para OpenGnSys.
17#@author  Ramon Gomez, ETSII Universidad de Sevilla
18#@date    2010-07-17
19#*/
20function ogGetArch ()
21{
22if [ "$*" == "help" ]; then
23    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  x86_64"
24    return
25fi
26
27[ -d /lib64 ] && echo "x86_64" || echo "i386"
28}
29
30
31#/**
32#         ogGetOsType int_ndisk int_npartition
33#@brief   Devuelve el tipo del sistema operativo instalado.
34#@param   int_ndisk      nº de orden del disco
35#@param   int_npartition nº de orden de la partición
36#@return  OSType - Tipo de sistema operativo.
37#@see     ogGetOsVersion
38#*/ ##
39function ogGetOsType ()
40{
41# Si se solicita, mostrar ayuda.
42if [ "$*" == "help" ]; then
43    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
44           "$FUNCNAME 1 2  =>  Linux"
45    return
46fi
47ogGetOsVersion "$@" | cut -sf1 -d:
48}
49
50
51#/**
52#         ogGetOsUuid int_ndisk int_nfilesys
53#@brief   Devuelve el UUID del sistema operativo instalado en un sistema de archivos.
54#@param   int_ndisk      nº de orden del disco
55#@param   int_nfilesys   nº de orden de la partición
56#@return  str_uuid -     UUID del sistema operativo.
57#@exception OG_ERR_FORMAT    Formato incorrecto.
58#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositiv
59#@version 1.1.0 - Primera versión para OpenGnsys
60#@author  Ramon Gomez, ETSII Universidad de Sevilla
61#@date    2015-09-09
62#*/ ##
63function ogGetOsUuid ()
64{
65# Variables locales.
66local MNTDIR
67# Si se solicita, mostrar ayuda.
68if [ "$*" == "help" ]; then
69    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
70           "$FUNCNAME 1 2  =>  540e47c6-8e78-4178-aa46-042e4803fb16"
71    return
72fi
73# Error si no se reciben 2 parametros.
74[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
75
76# Montar la particion, si no lo estaba previamente.
77MNTDIR=$(ogMount $1 $2) || return $?
78
79# Obtener UUID según el tipo de sistema operativo.
80case "$(ogGetOsType $1 $2)" in
81    Linux)
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
84        ;;
85    Windows)
86        # Leer identificador en clave de registro.
87        ogGetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Cryptography\MachineGuid' 2>/dev/null
88        ;;
89esac
90}
91
92
93#/**
94#         ogGetSerialNumber
95#@brief   Obtiene el nº de serie del cliente.
96#@version 1.1.0 - Primeras versión con OpenGnsys
97#@author  Ramon Gomez, ETSII Universidad de Sevilla
98#@date    2015-06-08
99#*/ ##
100function ogGetSerialNumber ()
101{
102# Variables locales.
103local SERIALNO
104# Si se solicita, mostrar ayuda.
105if [ "$*" == "help" ]; then
106    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  123456"
107    return
108fi
109
110# Obtener nº de serie (ignorar los no especificados).
111SERIALNO=$(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.
113SERIALNO="${SERIALNO// /}"
114[ ${#SERIALNO} -gt 25 ] && SERIALNO="${SERIALNO:0:22}..."
115[ -n "$SERIALNO" ] && echo "$SERIALNO"
116return 0
117}
118
119
120#/**
121#         ogIsEfiActive
122#@brief   Comprueba si el sistema tiene activo el arranque EFI.
123#*/ ##
124function ogIsEfiActive ()
125{
126test -d /sys/firmware/efi
127}
128
129
130#/**
131#         ogListHardwareInfo
132#@brief   Lista el inventario de hardware de la máquina cliente.
133#@return  TipoDispositivo:Modelo    (por determinar)
134#@warning Se ignoran los parámetros de entrada.
135#@note    TipoDispositivo = { bio, boa, bus, cha, cdr, cpu, dis, fir, mem, mod, mul, net, sto, usb, vga }
136#@note    Requisitos: dmidecode, lshw, awk
137#@version 0.1 - Primeras pruebas con OpenGnSys
138#@author  Ramon Gomez, ETSII Universidad de Sevilla
139#@date    2009-07-28
140#@version 1.1.0 - Incluir nuevos componentes al inventario.
141#@author  Ramon Gomez, ETSII Universidad de Sevilla
142#@date    2014-04-23
143#*/ ##
144function ogListHardwareInfo ()
145{
146# Si se solicita, mostrar ayuda.
147if [ "$*" == "help" ]; then
148    ogHelp "$FUNCNAME" "$FUNCNAME"
149    return
150fi
151
152# Recopilación de dispositivos procesando la salida de \c lshw
153ogEcho info "$MSG_HARDWAREINVENTORY}"
154echo "cha=$(dmidecode -s chassis-type)" | grep -v "Other"
155[ -e /sys/firmware/efi ] && echo "boo=UEFI" || echo "boo=BIOS"
156lshw | awk 'BEGIN {type="mod";}
157       /product:/ {sub(/ *product: */,"");  prod=$0;}
158       /vendor:/  {sub(/ *vendor: */,"");   vend=$0;}
159       /version:/ {sub(/ *version: */,"v.");vers=$0;}
160       /size:/    {size=$2;}
161       /clock:/   {clock=$2;}
162       /slot:/    {sub(/ *slot: */,"");     slot=$0;}
163       /\*-/      {if (type=="mem"){
164                     if (size!=""){
165                       numbank++;
166                       print type"="vend,prod,size,clock" ("slot")";}
167                   }else{
168                     if (type=="totalmem"){
169                       if (size!=""){
170                          totalmemory="mem="size;}
171                     }else{
172                       if (type!="" && prod!=""){
173                         if (prod=="v."vers)
174                           vers="";
175                         print type"="vend,prod,size,vers;} }
176                   }
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)
196                        print totalmemory; }
197      '
198# */ (comentario para Doxygen)
199}
200
201
202#/**
203#         ogListSoftware int_ndisk int_npartition
204#@brief   Lista el inventario de software instalado en un sistema operativo.
205#@param   int_ndisk      nº de orden del disco
206#@param   int_npartition nº de orden de la partición
207#@return  programa versión ...
208#@warning Se ignoran los parámetros de entrada.
209#@note    Requisitos: ...
210#@todo    Detectar software en Linux
211#@version 0.1 - Primeras pruebas con OpenGnSys
212#@author  Ramon Gomez, ETSII Universidad de Sevilla
213#@date    2009-09-23
214#@version 1.0.5 - Aproximación para inventario de software de Mac OS.
215#@author  Ramon Gomez, ETSII Universidad de Sevilla
216#@date    2013-10-08
217#@version 1.0.6 - Proceso depende del tipo de SO y soporte para FreeBSD.
218#@author  Ramon Gomez, ETSII Universidad de Sevilla
219#@date    2014-11-13
220#@version 1.1.0 - Se muestra el sistema operativo en la primera línea de la salida
221#@author  Irina Gomez, ETSII Universidad de Sevilla
222#@date    2016-04-26
223#*/ ##
224function ogListSoftware ()
225{
226# Variables locales.
227local APPS HIVE k KEYS KEYS32 MNTDIR PKGDIR PROG VERS TMPFILE TYPE
228
229# Si se solicita, mostrar ayuda.
230if [ "$*" == "help" ]; then
231    ogHelp "$FUNCNAME" "$FUNCNAME 1 1"
232    return
233fi
234# Error si no se reciben 2 parametros.
235[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
236
237# Obtener tipo de sistema de archivos y montarlo.
238MNTDIR=$(ogMount $1 $2) || return $?
239TYPE=$(ogGetOsType $1 $2) || return $?
240
241# Ficheros temporales.
242APPS=$(mktemp /tmp/apps.XXXXX)
243TMPFILE=$(mktemp /tmp/tmp.XXXXX)
244trap "rm -f $APPS $TMPFILE" 1 2 3 9 15
245
246case "$TYPE" in
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;
253                             sub(/-dev$/,"",$2);
254                             pack=$2}
255                 /Version:/ {sub(/^.*:/,"",$2); sub(/-.*$/,"",$2);
256                             vers=$2}
257                 /Status:/  {if ($2!="install") pack=vers=""}
258                 END        {if (pack!="") print pack,vers}
259                ' $PKGDIR/status > $APPS
260        fi
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.*
270            else
271                # Obtener el nombre de cada paquete en la BD de RPM.
272                python <<<"
273import re;
274import bsddb;
275db=bsddb.hashopen('$PKGDIR/Name','r');
276for k in db.keys():
277    print re.sub('-devel$','',k);" > $APPS
278            fi
279        fi
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
284        fi
285        # Procesar aplicaciones Snappy.
286        PKGDIR="${MNTDIR}/snap"
287        find $PKGDIR/*/current/meta -name snap.yaml -exec \
288                awk '/name:/ {pack=$2}
289                     /version:/ {vers=$2}
290                     END {if (pack!="") print pack,"(snap)",vers}' {} 2>/dev/null \; >> $APPS
291        # Procesar aplicaciones Flatpak.
292        PKGDIR="${MNTDIR}/var/lib/flatpak"
293        ls -1 $PKGDIR/app/*/current/active/deploy 2> /dev/null | python -c "
294import sys
295for f in sys.stdin:
296    p = open(f.strip()).read().split('\0')
297    try:
298        if(p[0] != 'flathub'):
299            raise ValueError
300        print('{} (flatpak) {}'.format(p[p.index('appdata-name') + 4], p[p.index('appdata-version') + 1]))
301    except ValueError:
302        pass
303" >> $APPS
304        ;;
305    Windows)        # Software de Windows.
306        # Comprobar tipo de proceso del registro de Windows.
307        if which hivexregedit &>/dev/null; then
308            # Nuevo proceso más rápido basado en "hivexregedit".
309            HIVE=$(ogGetHivePath $MNTDIR software 2>/dev/null)
310            if [ -n "$HIVE" ]; then
311                # Claves de registro para programas instalados.
312                hivexregedit --unsafe-printable-strings --export "$HIVE" '\Microsoft\Windows\CurrentVersion\Uninstall' > $TMPFILE 2>/dev/null
313                hivexregedit --unsafe-printable-strings --export "$HIVE" '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' >> $TMPFILE 2>/dev/null
314                # Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
315                awk -F\" '$1~/^\[/ {n=""}
316                          $2~/DisplayName/ {n=$4}
317                          $2~/DisplayVersion/ {print n,$4}
318                         ' $TMPFILE > $APPS
319            fi
320        else
321            # Compatibilidad con clientes ogLive antiguos.
322            # Claves de registro para programas instalados: formato "{clave}".
323            KEYS=$(ogListRegistryKeys $MNTDIR software '\Microsoft\Windows\CurrentVersion\Uninstall')
324            KEYS32=$(ogListRegistryKeys $MNTDIR software '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
325            # Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
326            for k in $KEYS; do
327                PROG=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
328                if [ -n "$PROG" ]; then
329                    VERS=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
330                    echo "$PROG $VERS"
331                fi
332            done > $APPS
333            for k in $KEYS32; do
334                PROG=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
335                if [ -n "$PROG" ]; then
336                    VERS=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
337                    echo "$PROG $VERS"
338                fi
339            done >> $APPS
340        fi
341        ;;
342    MacOS)          # Software de Mac OS.
343        # Listar directorios de aplicaciones e intentar obtener la versión del fichero .plist (tanto original como descomprimido).
344        find "${MNTDIR}/Applications" -type d -name "*.app" -prune -print | \
345                while read k; do
346                    FILE="$k/Contents/version.plist"
347                    [ -s "$FILE" ] || FILE="$k/Contents/version.plist.uncompress"
348                    [ -s "$FILE" ] && VERSION=$(awk -F"[<>]" '/ShortVersionString/ {getline;v=$3}
349                                                              END {print v}' "$FILE")
350                    echo "$(basename "$k" .app) $VERSION"
351                done > $APPS
352        ;;
353    BSD)            # Software de FreeBSD.
354        sqlite3 $MNTDIR/var/db/pkg/local.sqlite <<<"SELECT name FROM pkg_search;" 2>/dev/null | \
355                sed 's/\(.*\)-\(.*\)/\1 \2/g' > $APPS
356        ;;
357    *)  ogRaiseError $OG_ERR_NOTOS "$1, $2 ${TYPE+($TYPE)}"
358        return $? ;;
359esac
360
361# Mostrar sistema Operativo y aplicaciones.
362ogGetOsVersion $1 $2 | awk -F: '{print $2}'
363sort $APPS | uniq
364rm -f $APPS $TMPFILE
365}
366
367#/**
368#         ogGetOsVersion int_ndisk int_nfilesys
369#@brief   Devuelve la versión del sistema operativo instalado en un sistema de archivos.
370#@param   int_ndisk      nº de orden del disco
371#@param   int_nfilesys   nº de orden de la partición
372#@return  OSType:OSVersion - tipo y versión del sistema operativo.
373#@note    OSType = { Android, BSD, GrubLoader, Hurd, Linux, MacOS, Solaris, Windows, WinLoader }
374#@note    Requisitos: awk, head, chroot
375#@exception OG_ERR_FORMAT    Formato incorrecto.
376#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositiv
377#@exception OG_ERR_PARTITION Fallo al montar el sistema de archivos.
378#@version 0.9 - Primera versión para OpenGnSys
379#@author  Ramon Gomez, ETSII Universidad de Sevilla
380#@date    2009-09-15
381#@version 1.0.4 - Incluir tipos BSD, MacOS y Solaris.
382#@author  Ramon Gomez, ETSII Universidad de Sevilla
383#@date    2012-06-29
384#@version 1.0.5 - Incluir tipos GrubLoader, Hurd y WinLoader, leer por defecto fichero /etc/os-release.
385#@author  Ramon Gomez, ETSII Universidad de Sevilla
386#@date    2013-10-07
387#@version 1.0.6 - Detectar GrubLoader al final y sistemas basados en EFI.
388#@author  Ramon Gomez, ETSII Universidad de Sevilla
389#@date    2014-08-27
390#*/ ##
391function ogGetOsVersion ()
392{
393# Variables locales.
394local MNTDIR TYPE DISTRIB VERSION IS64BIT FILE
395# Si se solicita, mostrar ayuda.
396if [ "$*" == "help" ]; then
397    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
398           "$FUNCNAME 1 2  =>  Linux:Ubuntu precise (12.04 LTS) 64 bits"
399    return
400fi
401# Error si no se reciben 2 parametros.
402[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
403
404# Montar la particion, si no lo estaba previamente.
405MNTDIR=$(ogMount $1 $2) || return $?
406
407# Buscar tipo de sistema operativo.
408# Para GNU/Linux: leer descripción.
409TYPE="Linux"
410FILE="$MNTDIR/etc/os-release"
411[ -r $FILE ] && VERSION="$(awk -F= '$1~/PRETTY_NAME/ {gsub(/\"/,"",$2); print $2}' $FILE)"
412# Si no se puede obtener, buscar en ficheros del sistema.
413if [ -z "$VERSION" ]; then
414    FILE="$MNTDIR/etc/lsb-release"
415    [ -r $FILE ] && VERSION="$(awk -F= '$1~/DESCRIPTION/ {gsub(/\"/,"",$2); print $2}' $FILE)"
416    for DISTRIB in redhat SuSE mandrake gentoo; do
417        FILE="$MNTDIR/etc/${DISTRIB}-release"
418        [ -r $FILE ] && VERSION="$(head -1 $FILE)"
419    done
420    FILE="$MNTDIR/etc/arch-release"
421    [ -r $FILE ] && VERSION="Arch Linux"
422    FILE="$MNTDIR/etc/slackware-version"
423    [ -r $FILE ] && VERSION="Slackware $(cat $FILE)"
424fi
425# Si no se encuentra, intentar ejecutar "lsb_release".
426[ -z "$VERSION" ] && VERSION=$(chroot $MNTDIR lsb_release -d 2>/dev/null | awk -F":\t" '{print $2}')
427# Comprobar Linux de 64 bits.
428[ -n "$VERSION" ] && [ -e $MNTDIR/lib64 ] && IS64BIT="$MSG_64BIT"
429# Para Android, leer fichero de propiedades.
430if [ -z "$VERSION" ]; then
431    TYPE="Android"
432    FILE="$MNTDIR/android*/system/build.prop"
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"
435fi
436# Para GNU/Hurd, comprobar fichero de inicio (basado en os-prober).
437if [ -z "$VERSION" ]; then
438    TYPE="Hurd"
439    FILE="$MNTDIR/hurd/init"
440    [ -r $FILE ] && VERSION="GNU/Hurd"
441fi
442# Para Windows: leer la version del registro.
443if [ -z "$VERSION" ]; then
444    TYPE="Windows"
445    FILE="$(ogGetHivePath $MNTDIR SOFTWARE)"
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
449load $FILE
450cd \Microsoft\Windows NT\CurrentVersion
451lsval ProductName
452lsval ReleaseId
453EOT
454        ))
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"
460        fi
461    fi
462fi
463# Para cargador Windows: buscar versión en fichero BCD (basado en os-prober).
464if [ -z "$VERSION" ]; then
465    TYPE="WinLoader"
466    FILE="$(ogGetPath $MNTDIR/boot/bcd)"
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"
472            fi
473        done
474    fi
475fi
476# Para macOS: detectar kernel y completar con fichero plist de información del sistema.
477if [ -z "$VERSION" ]; then
478    TYPE="MacOS"
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"
494    fi
495fi
496# Para FreeBSD: obtener datos del Kernel.
497### TODO Revisar solución.
498if [ -z "$VERSION" ]; then
499    TYPE="BSD"
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"
504    fi
505fi
506# Para Solaris: leer el fichero de versión.
507### TODO Revisar solución.
508if [ -z "$VERSION" ]; then
509    TYPE="Solaris"
510    FILE="$MNTDIR/etc/release"
511    [ -r $FILE ] && VERSION="$(head -1 $FILE)"
512fi
513# Para cargador GRUB, comprobar fichero de configuración.
514if [ -z "$VERSION" ]; then
515    TYPE="GrubLoader"
516    for FILE in $MNTDIR/{,boot/}grub/menu.lst; do
517        [ -r $FILE ] && VERSION="GRUB Loader"
518    done
519#/* (comentario Doxygen)   
520    for FILE in $MNTDIR/{,boot/}{grub{,2},EFI/*}/grub.cfg; do
521        [ -r $FILE ] && VERSION="GRUB2 Loader"
522    done   
523fi
524#*/ (Comentario Doxygen)
525# Mostrar resultado y salir sin errores.
526[ -n "$VERSION" ] && echo "$TYPE:$VERSION $IS64BIT"
527return 0
528}
Note: See TracBrowser for help on using the repository browser.