source: client/engine/Inventory.lib @ 2cce651a

918-git-images-111dconfigfileconfigure-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-instalacionwebconsole3
Last change on this file since 2cce651a was 46b510c, checked in by ramon <ramongomez@…>, 7 years ago

#802: Nueva función ogIsEfiActive y ampliar búsquedas de disco por UUID en función ogDiskToDev.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5714 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 18.8 KB
RevLine 
[b550747]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.
[304533c]7#@version 1.1.0
[b550747]8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
[cb5997b]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#*/
[e4dafd6]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"
[cb5997b]28}
29
30
31#/**
[045fd2d]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#/**
[73c42522]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#/**
[4d2b852]94#         ogGetOsVersion int_ndisk int_nfilesys
[1d531f9]95#@brief   Devuelve la versión del sistema operativo instalado en un sistema de archivos.
[42669ebf]96#@param   int_ndisk      nº de orden del disco
[4d2b852]97#@param   int_nfilesys   nº de orden de la partición
[f35fadc]98#@return  OSType:OSVersion - tipo y versión del sistema operativo.
[4d2b852]99#@note    OSType = { Android, BSD, GrubLoader, Hurd, Linux, MacOS, Solaris, Windows, WinLoader }
[1d531f9]100#@note    Requisitos: awk, head, chroot
101#@exception OG_ERR_FORMAT    Formato incorrecto.
102#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositiv
103#@exception OG_ERR_PARTITION Fallo al montar el sistema de archivos.
[f35fadc]104#@version 0.9 - Primera versión para OpenGnSys
[1d531f9]105#@author  Ramon Gomez, ETSII Universidad de Sevilla
106#@date    2009-09-15
[f35fadc]107#@version 1.0.4 - Incluir tipos BSD, MacOS y Solaris.
108#@author  Ramon Gomez, ETSII Universidad de Sevilla
109#@date    2012-06-29
[4d2b852]110#@version 1.0.5 - Incluir tipos GrubLoader, Hurd y WinLoader, leer por defecto fichero /etc/os-release.
[988438f]111#@author  Ramon Gomez, ETSII Universidad de Sevilla
[6f4e407]112#@date    2013-10-07
[1a2fa9d8]113#@version 1.0.6 - Detectar GrubLoader al final y sistemas basados en EFI.
[5acde60]114#@author  Ramon Gomez, ETSII Universidad de Sevilla
115#@date    2014-08-27
[1e7eaab]116#*/ ##
[42669ebf]117function ogGetOsVersion ()
118{
[1d531f9]119# Variables locales.
[988438f]120local MNTDIR TYPE DISTRIB VERSION IS64BIT FILE
[42669ebf]121# Si se solicita, mostrar ayuda.
[be74e2d]122if [ "$*" == "help" ]; then
[4d2b852]123    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
124           "$FUNCNAME 1 2  =>  Linux:Ubuntu precise (12.04 LTS) 64 bits"
[1d531f9]125    return
126fi
[42669ebf]127# Error si no se reciben 2 parametros.
[055adcf]128[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[1d531f9]129
130# Montar la particion, si no lo estaba previamente.
131MNTDIR=$(ogMount $1 $2) || return $?
132
[988438f]133# Buscar tipo de sistema operativo.
134# Para GNU/Linux: leer descripción.
135TYPE="Linux"
[825dd06]136FILE="$MNTDIR/etc/os-release"
137[ -r $FILE ] && VERSION="$(awk -F= '$1~/PRETTY_NAME/ {gsub(/\"/,"",$2); print $2}' $FILE)"
[988438f]138# Si no se puede obtener, buscar en ficheros del sistema.
139if [ -z "$VERSION" ]; then
140    FILE="$MNTDIR/etc/lsb-release"
[825dd06]141    [ -r $FILE ] && VERSION="$(awk -F= '$1~/DESCRIPTION/ {gsub(/\"/,"",$2); print $2}' $FILE)"
[988438f]142    for DISTRIB in redhat SuSE mandrake gentoo; do
143        FILE="$MNTDIR/etc/${DISTRIB}-release"
[f35fadc]144        [ -r $FILE ] && VERSION="$(head -1 $FILE)"
[988438f]145    done
146    FILE="$MNTDIR/etc/arch-release"
147    [ -r $FILE ] && VERSION="Arch Linux"
148    FILE="$MNTDIR/etc/slackware-version"
149    [ -r $FILE ] && VERSION="Slackware $(cat $FILE)"
150fi
[825dd06]151# Si no se encuentra, intentar ejecutar "lsb_release".
152[ -z "$VERSION" ] && VERSION=$(chroot $MNTDIR lsb_release -d 2>/dev/null | awk -F":\t" '{print $2}')
153# Comprobar Linux de 64 bits.
154[ -n "$VERSION" ] && [ -e $MNTDIR/lib64 ] && IS64BIT="$MSG_64BIT"
[988438f]155# Para Android, leer fichero de propiedades.
156if [ -z "$VERSION" ]; then
157    TYPE="Android"
158    FILE="$MNTDIR/android*/system/build.prop"
159    [ -r $FILE ] && VERSION="Android $(awk -F= '$1~/(product.brand|build.version.release)/ {print $2}' $FILE | tr '\n' ' ')"
160    [ -e $MNTDIR/lib64 ] && IS64BIT="$MSG_64BIT"
161fi
162# Para GNU/Hurd, comprobar fichero de inicio (basado en os-prober).
163if [ -z "$VERSION" ]; then
164    TYPE="Hurd"
165    FILE="$MNTDIR/hurd/init"
166    [ -r $FILE ] && VERSION="GNU/Hurd"
167fi
168# Para Windows: leer la version del registro.
169if [ -z "$VERSION" ]; then
170    TYPE="Windows"
[58718f5]171    FILE="$(ogGetHivePath $MNTDIR SOFTWARE)"
172    if [ -n "$FILE" ]; then
173        # Nuevo método más rápido para acceder al registro de Windows..
174        VERSION=$(echo $(hivexsh << EOT 2>/dev/null
175load $FILE
176cd \Microsoft\Windows NT\CurrentVersion
177lsval ProductName
178lsval ReleaseId
179EOT
180        ))
181        [ -n "$(reglookup -H -p "Microsoft/Windows/CurrentVersion/ProgramW6432Dir" "$FILE" 2>/dev/null)" ] && IS64BIT="$MSG_64BIT"
182        if [ -z "$VERSION" ]; then
183            # Compatibilidad con métrodo antiguo y más lento de acceder al registro.
184            VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName' 2>/dev/null)
185            [ -n "$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows\CurrentVersion\ProgramW6432Dir' 2>/dev/null)" ] && IS64BIT="$MSG_64BIT"
186        fi
187    fi
[988438f]188fi
189# Para cargador Windows: buscar versión en fichero BCD (basado en os-prober).
190if [ -z "$VERSION" ]; then
191    TYPE="WinLoader"
192    FILE="$(ogGetPath $MNTDIR/boot/bcd)"
[1a2fa9d8]193    [ -z "$FILE" ] && FILE="$(ogGetPath $MNTDIR/EFI/Microsoft/boot/bcd)"
[988438f]194    if [ -n "$FILE" ]; then
[1a2fa9d8]195        for DISTRIB in "Windows Recovery" "Windows Boot"; do
[1e4000f]196            if grep -aqs "$(echo "$DISTRIB" | sed 's/./&./g')" $FILE; then
[1a2fa9d8]197                VERSION="$DISTRIB loader"
[988438f]198            fi
199        done
200    fi
201fi
[58718f5]202# Para macOS: detectar kernel y completar con fichero plist de información del sistema.
[988438f]203if [ -z "$VERSION" ]; then
204    TYPE="MacOS"
[045fd2d]205    # Kernel de Mac OS (no debe ser fichero de texto).
[6f4e407]206    FILE="$MNTDIR/mach_kernel"
[045fd2d]207    if [ -z "$(file -b $FILE | grep 'text')" ]; then
208        # Obtener tipo de kernel.
[58718f5]209        [ -n "$(file -b $FILE | grep 'Mach-O')" ] && VERSION="macOS"
[045fd2d]210        [ -n "$(file -b $FILE | grep 'Mach-O 64-bit')" ] && IS64BIT="$MSG_64BIT"
211        # Datos de configuración de versión de Mac OS.
212        FILE="$MNTDIR/System/Library/CoreServices/SystemVersion.plist"
213        [ -r $FILE ] && VERSION=$(awk -F"[<>]" '
214                                      /ProductName/ {getline;s=$3}
215                                      /ProductVersion/ {getline;v=$3}
216                                      END {print s,v}' $FILE)
[58718f5]217        # Datos de recuperación de macOS.
[045fd2d]218        FILE="$MNTDIR/com.apple.recovery.boot"
219        [ -r $FILE -a -n "$VERSION" ] && VERSION="$VERSION recovery"
220    fi
[988438f]221fi
222# Para FreeBSD: obtener datos del Kernel.
223### TODO Revisar solución.
224if [ -z "$VERSION" ]; then
225    TYPE="BSD"
226    FILE="$MNTDIR/boot/kernel/kernel"
227    if [ -r $FILE ]; then
[c7dcb94]228        VERSION="$(strings $FILE|awk '/@.*RELEASE/ {sub(/@\(#\)/,""); print $1,$2}')"
[988438f]229        [ -n "$(file -b $FILE | grep 'x86-64')" ] && IS64BIT="$MSG_64BIT"
230    fi
231fi
232# Para Solaris: leer el fichero de versión.
233### TODO Revisar solución.
234if [ -z "$VERSION" ]; then
235    TYPE="Solaris"
236    FILE="$MNTDIR/etc/release"
237    [ -r $FILE ] && VERSION="$(head -1 $FILE)"
238fi
[5acde60]239# Para cargador GRUB, comprobar fichero de configuración.
240if [ -z "$VERSION" ]; then
241    TYPE="GrubLoader"
242    for FILE in $MNTDIR/{,boot/}grub/menu.lst; do
243        [ -r $FILE ] && VERSION="GRUB Loader"
244    done
245    for FILE in $MNTDIR/{,boot/}{grub{,2},EFI/*}/grub.cfg; do
246        [ -r $FILE ] && VERSION="GRUB2 Loader"
247    done
248fi
[1d531f9]249
[42669ebf]250# Mostrar resultado y salir sin errores.
[988438f]251[ -n "$VERSION" ] && echo "$TYPE:$VERSION $IS64BIT"
[d071d9b]252return 0
[1d531f9]253}
254
255
256#/**
[304533c]257#         ogGetSerialNumber
258#@brief   Obtiene el nº de serie del cliente.
259#@version 1.1.0 - Primeras versión con OpenGnsys
260#@author  Ramon Gomez, ETSII Universidad de Sevilla
261#@date    2015-06-08
262function ogGetSerialNumber ()
263{
264# Si se solicita, mostrar ayuda.
265if [ "$*" == "help" ]; then
266    ogHelp "$FUNCNAME" "$FUNCNAME"
267    return
268fi
269
270# Obtener nº de serie (ignorar los no especificados)
[7a59012]271dmidecode -s system-serial-number | egrep -vi "(^[ 0]+$|not specified|filled by o.e.m.)"
[304533c]272}
273
274
275#/**
[46b510c]276#         ogIsEfiActive
277#@brief   Comprueba si el sistema tiene activo el arranque EFI.
278#*/ ##
279function ogIsEfiActive ()
280{
281test -d /sys/firmware/efi
282}
283
284
285#/**
[b550747]286#         ogListHardwareInfo
287#@brief   Lista el inventario de hardware de la máquina cliente.
288#@return  TipoDispositivo:Modelo    (por determinar)
289#@warning Se ignoran los parámetros de entrada.
[304533c]290#@note    TipoDispositivo = { bio, boa, bus, cha, cdr, cpu, dis, fir, mem, mod, mul, net, sto, usb, vga }
291#@note    Requisitos: dmidecode, lshw, awk
[f35fadc]292#@version 0.1 - Primeras pruebas con OpenGnSys
[b550747]293#@author  Ramon Gomez, ETSII Universidad de Sevilla
294#@date    2009-07-28
[304533c]295#@version 1.1.0 - Incluir nuevos componentes al inventario.
296#@author  Ramon Gomez, ETSII Universidad de Sevilla
297#@date    2014-04-23
[1e7eaab]298#*/ ##
[42669ebf]299function ogListHardwareInfo ()
300{
301# Si se solicita, mostrar ayuda.
[be74e2d]302if [ "$*" == "help" ]; then
[b550747]303    ogHelp "$FUNCNAME" "$FUNCNAME"
304    return
305fi
306
[aaf5f9f]307# Recopilación de dispositivos procesando la salida de \c lshw
[b550747]308ogEcho info "$MSG_HARDWAREINVENTORY}"
[6dedc02]309echo "cha=$(dmidecode -s chassis-type)" | grep -v "Other"
310[ -e /sys/firmware/efi ] && echo "boo=UEFI" || echo "boo=BIOS"
[b550747]311lshw | awk 'BEGIN {type="mod";}
[304533c]312       /product:/ {sub(/ *product: */,"");  prod=$0;}
313       /vendor:/  {sub(/ *vendor: */,"");   vend=$0;}
314       /version:/ {sub(/ *version: */,"v.");vers=$0;}
315       /size:/    {size=$2;}
316       /clock:/   {clock=$2;}
317       /slot:/    {sub(/ *slot: */,"");     slot=$0;}
318       /\*-/      {if (type=="mem"){
[42d268a4]319                     if (size!=""){
320                       numbank++;
321                       print type"="vend,prod,size,clock" ("slot")";}
[304533c]322                   }else{
[42d268a4]323                     if (type=="totalmem"){
324                       if (size!=""){
325                          totalmemory="mem="size;}
326                     }else{
327                       if (type!="" && prod!=""){
328                         if (prod=="v."vers)
329                           vers="";
330                         print type"="vend,prod,size,vers;} }
[aaf5f9f]331                   }
[304533c]332                   type=prod=vend=vers=size=clock=slot="";}
333       $1~/-core/    {type="boa";}
334       $1~/-firmware/ {type="bio";}
335       $1~/-cpu/     {type="cpu";}
336       $1~/-bank/    {type="mem";}
[aaf5f9f]337       $1~/-memory/  {type="totalmem";}
[304533c]338       $1~/-ide/     {type="ide";}
339       $1~/-storage/ {type="sto";}
340       $1~/-disk/    {type="dis";}
341       $1~/-cdrom/   {type="cdr";}
342       $1~/-display/ {type="vga";}
343       $1~/-network/ {type="net";}
344       $1~/-multimedia/ {type="mul";}
345       $1~/-usb/     {type="usb";}
346       $1~/-firewire/ {type="fir";}
347       $1~/-serial/  {type="bus";}
348       END           {if (type!="" && prod!="")
[aaf5f9f]349                        print type"="vend,prod,size,vers;
[42d268a4]350                      if (length(numbank)==0 && length(totalmemory)>=4)
[aaf5f9f]351                        print totalmemory; }
[b550747]352      '
[42669ebf]353# */ (comentario para Doxygen)
[b550747]354}
355
356
[50a094c]357#/**
[42669ebf]358#         ogListSoftware int_ndisk int_npartition
[50a094c]359#@brief   Lista el inventario de software instalado en un sistema operativo.
[42669ebf]360#@param   int_ndisk      nº de orden del disco
361#@param   int_npartition nº de orden de la partición
362#@return  programa versión ...
[50a094c]363#@warning Se ignoran los parámetros de entrada.
364#@note    Requisitos: ...
365#@todo    Detectar software en Linux
[f35fadc]366#@version 0.1 - Primeras pruebas con OpenGnSys
[50a094c]367#@author  Ramon Gomez, ETSII Universidad de Sevilla
368#@date    2009-09-23
[89a5166]369#@version 1.0.5 - Aproximación para inventario de software de Mac OS.
370#@author  Ramon Gomez, ETSII Universidad de Sevilla
371#@date    2013-10-08
[38e2328]372#@version 1.0.6 - Proceso depende del tipo de SO y soporte para FreeBSD.
[bc2279a]373#@author  Ramon Gomez, ETSII Universidad de Sevilla
374#@date    2014-11-13
[38e2328]375#@version 1.1.0 - Se muestra el sistema operativo en la primera línea de la salida
376#@author  Irina Gomez, ETSII Universidad de Sevilla
377#@date    2016-04-26
[1e7eaab]378#*/ ##
[42669ebf]379function ogListSoftware ()
380{
[50a094c]381# Variables locales.
[2f3d0532]382local MNTDIR TYPE DPKGDIR RPMDIR PACMANDIR k
[50a094c]383
[42669ebf]384# Si se solicita, mostrar ayuda.
[be74e2d]385if [ "$*" == "help" ]; then
[50a094c]386    ogHelp "$FUNCNAME" "$FUNCNAME 1 1"
387    return
388fi
[42669ebf]389# Error si no se reciben 2 parametros.
[50a094c]390[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
391
[42669ebf]392# Obtener tipo de sistema de archivos y montarlo.
[50a094c]393MNTDIR=$(ogMount $1 $2) || return $?
[bc2279a]394TYPE=$(ogGetOsType $1 $2) || return $?
[50a094c]395
[38e2328]396# Sistema Operativo en la primera línea de la salida
397ogGetOsVersion $1 $2 | awk -F ':'  '{print $2}'
398
[50a094c]399case "$TYPE" in
[bc2279a]400    Linux)          # Software de GNU/Linux.
[c2b03eb]401        # Procesar paquetes dpkg.
402        DPKGDIR="${MNTDIR}/var/lib/dpkg"
403        if [ -r $DPKGDIR ]; then
404            # Proceso de fichero en sistemas de 64 bits.
[304533c]405            awk '/Package:/ {if (pack!="") print pack,vers;
406                             sub(/-dev$/,"",$2);
407                             pack=$2}
408                 /Version:/ {sub(/^.*:/,"",$2); sub(/-.*$/,"",$2);
409                             vers=$2}
410                 /Status:/  {if ($2!="install") pack=vers=""}
411                 END        {if (pack!="") print pack,vers}
412                ' $DPKGDIR/status | sort | uniq
[c2b03eb]413        fi
414        # Procesar paquetes RPM.
415        RPMDIR="${MNTDIR}/var/lib/rpm"
416        if [ -r $RPMDIR ]; then
[bc2279a]417            # Listar si está instalado el paquete "rpm" en el cliente.
418            if which rpm &>/dev/null; then
419                rm -f ${RPMDIR}/__db.*
420                rpm --dbpath $RPMDIR -qa --qf "%{NAME} %{VERSION}\n" 2>/dev/null | \
421                    awk '$1!~/-devel$/ {sub(/-.*$/,"",$2); print $0}' | sort | uniq
422                rm -f ${RPMDIR}/__db.*
423            else
[246bf13b]424                # Obtener el nombre de cada paquete en la BD de RPM.
425                python <<<"
426import re;
427import bsddb;
428db=bsddb.hashopen('$RPMDIR/Name','r');
429for k in db.keys():
[5cc5560f]430    print re.sub('-devel$','',k);" | sort | uniq
[bc2279a]431            fi
[c2b03eb]432        fi
[2e472ef3]433        # Procesar paquetes pacman.
434        PACMANDIR="${MNTDIR}/var/lib/pacman/local"
435        if [ -r $PACMANDIR ]; then
[526bbf8]436            ls $PACMANDIR | awk -F- '/-/ {print gensub(/-/, " ", NF-2);}'
[2e472ef3]437        fi
[c2b03eb]438        ;;
[bc2279a]439    Windows)        # Software de Windows.
[2f3d0532]440        # Comprobar tipo de proceso del registro de Windows.
441        if which hivexregedit &>/dev/null; then
442            # Nuevo proceso más rápido basado en "hivexregedit".
443            local HIVE TMPFILE
444            HIVE=$(ogGetHivePath $MNTDIR software 2>/dev/null)
445            if [ -n "$HIVE" ]; then
446                # Claves de registro para programas instalados.
447                TMPFILE=/tmp/tmp$$
448                trap "rm -f $TMPFILE" 1 2 3 9 15
449                hivexregedit --unsafe-printable-strings --export "$HIVE" '\Microsoft\Windows\CurrentVersion\Uninstall' > $TMPFILE 2>/dev/null
450                hivexregedit --unsafe-printable-strings --export "$HIVE" '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' >> $TMPFILE 2>/dev/null
451                # Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
452                awk -F\" '$1~/^\[/ {n=""}
453                          $2~/DisplayName/ {n=$4}
454                          $2~/DisplayVersion/ {print n,$4}
455                         ' $TMPFILE | sort | uniq
456                rm -f $TMPFILE
[c2b03eb]457            fi
[2f3d0532]458        else
459            # Compatibilidad con clientes ogLive antiguos.
460            local KEYS KEYS32 PROG VERS
461            # Claves de registro para programas instalados: formato "{clave}".
462            KEYS=$(ogListRegistryKeys $MNTDIR software '\Microsoft\Windows\CurrentVersion\Uninstall')
463            KEYS32=$(ogListRegistryKeys $MNTDIR software '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
464            # Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
465            (for k in $KEYS; do
466                PROG=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
467                if [ -n "$PROG" ]; then
468                    VERS=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
469                    echo "$PROG $VERS"
470                fi
471             done
472             for k in $KEYS32; do
473                PROG=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
474                if [ -n "$PROG" ]; then
475                    VERS=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
476                    echo "$PROG $VERS"
477                fi
478             done) | sort | uniq
479        fi
[c2b03eb]480        ;;
[bc2279a]481    MacOS)          # Software de Mac OS.
[4ff56c5]482        # Listar directorios de aplicaciones e intentar obtener la versión del fichero .plist (tanto original como descomprimido).
[89a5166]483        find "${MNTDIR}/Applications" -type d -name "*.app" -prune -print | \
484                while read k; do
[4ff56c5]485                    FILE="$k/Contents/version.plist"
486                    [ -s "$FILE" ] || FILE="$k/Contents/version.plist.uncompress"
487                    [ -s "$FILE" ] && VERSION=$(awk -F"[<>]" '/ShortVersionString/ {getline;v=$3}
488                                                              END {print v}' "$FILE")
489                    echo "$(basename "$k" .app) $VERSION"
[89a5166]490                done | sort
491        ;;
[bc2279a]492    BSD)            # Software de FreeBSD.
493        sqlite3 $MNTDIR/var/db/pkg/local.sqlite <<<"SELECT name FROM pkg_search;" 2>/dev/null | \
494                sed 's/\(.*\)-\(.*\)/\1 \2/g' | sort
495        ;;
[c2b03eb]496    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
[50a094c]497        return $? ;;
498esac
499}
Note: See TracBrowser for help on using the repository browser.