source: client/engine/Inventory.lib @ 20a91aa

Last change on this file since 20a91aa was 71643c0, checked in by ramon <ramongomez@…>, 13 years ago

Integrar versión 1.0.2 en rama trunk (modificar #464).

git-svn-id: https://opengnsys.es/svn/trunk@2404 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 10.4 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.
[cb5997b]7#@version 0.9.2
[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#*/
[71643c0]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#/**
[1d531f9]32#         ogGetOsVersion int_ndisk int_npartition
33#@brief   Devuelve la versión del sistema operativo instalado en un sistema de archivos.
[42669ebf]34#@param   int_ndisk      nº de orden del disco
35#@param   int_npartition nº de orden de la partición
[1c04494]36#@return  OSType:OSVersion
[1d531f9]37#@note    TipoSistema = { Linux, Windows }
38#@note    Requisitos: awk, head, chroot
39#@exception OG_ERR_FORMAT    Formato incorrecto.
40#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositiv
41#@exception OG_ERR_PARTITION Fallo al montar el sistema de archivos.
[1c04494]42#@version 0.9 - Primera versión para OpenGNSys
[1d531f9]43#@author  Ramon Gomez, ETSII Universidad de Sevilla
44#@date    2009-09-15
[1e7eaab]45#*/ ##
[42669ebf]46function ogGetOsVersion ()
47{
[1d531f9]48# Variables locales.
[2e472ef3]49local MNTDIR TYPE DISTRIB VERSION FILE
[42669ebf]50# Si se solicita, mostrar ayuda.
[be74e2d]51if [ "$*" == "help" ]; then
[71643c0]52    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
53           "$FUNCNAME 1 2  =>  Linux:Ubuntu 11.04 64 bits"
[1d531f9]54    return
55fi
[42669ebf]56# Error si no se reciben 2 parametros.
[055adcf]57[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[1d531f9]58
59# Montar la particion, si no lo estaba previamente.
60MNTDIR=$(ogMount $1 $2) || return $?
61
[42669ebf]62# Elección del tipo de sistema operativo.
[1d531f9]63case "$(ogGetFsType $1 $2)" in
64    EXT[234] | REISERFS | REISER4)
[1c04494]65        TYPE="Linux"
[42669ebf]66        # Para Linux: leer descripción.
[1c04494]67        VERSION=$(chroot $MNTDIR lsb_release -d 2>/dev/null| awk -F: '{gsub (/\t/,""); print $2}')
[42669ebf]68        # Si no se puede obtener, buscar en ficheros del sistema.
[1c04494]69        if [ -z "$VERSION" ]; then
70            FILE="$MNTDIR/etc/lsb-release"
71            [ -r $FILE ] && VERSION="$(awk 'BEGIN {FS="="}; $1~/DESCRIPTION/ {gsub(/\"/,"",$2); print $2}' $FILE)"
[2e472ef3]72            for DISTRIB in redhat SuSE mandrake; do
73                FILE="$MNTDIR/etc/${DISTRIB}-release"
74                [ -r $FILE ] && VERSION="$(head -1 $FILE)"
75            done
76            FILE="$MNTDIR/etc/arch-release"
77            [ -r $FILE ] && VERSION="Arch Linux"
[1c04494]78        fi
79        [ -e $MNTDIR/lib64 ] && VERSION="$VERSION 64 bits"
80        ;;
[71643c0]81    NTFS | HNTFS | FAT32 | HFAT32)
[1c04494]82        TYPE="Windows"
[42669ebf]83        # Para Windows: leer la version del registro.
[1c04494]84        VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName')
85        ;;
[1d531f9]86esac
87
[42669ebf]88# Mostrar resultado y salir sin errores.
[1d531f9]89[ -n "$VERSION" ] && echo "$TYPE:$VERSION"
[d071d9b]90return 0
[1d531f9]91}
92
93
94#/**
[1c04494]95#         ogGetOsType int_ndisk int_npartition
96#@brief   Devuelve el tipo del sistema operativo instalado.
[42669ebf]97#@param   int_ndisk      nº de orden del disco
98#@param   int_npartition nº de orden de la partición
[1c04494]99#@return  OSType
100#@note    OSType = { Linux, Windows }
101#@see     ogGetOsVersion
[1e7eaab]102#*/ ##
[42669ebf]103function ogGetOsType ()
104{
[71643c0]105# Si se solicita, mostrar ayuda.
106if [ "$*" == "help" ]; then
107    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
108           "$FUNCNAME 1 2  =>  Linux"
109    return
110fi
[1c04494]111ogGetOsVersion "$@" | cut -sf1 -d:
112}
113
114
115#/**
[b550747]116#         ogListHardwareInfo
117#@brief   Lista el inventario de hardware de la máquina cliente.
118#@return  TipoDispositivo:Modelo    (por determinar)
119#@warning Se ignoran los parámetros de entrada.
120#@note    TipoDispositivo = { ata, bio, boa, cdr, cpu, dis, fir, mem, mod, mul, net, ser, vga }
121#@note    Requisitos: lshw, awk
122#@version 0.1 - Primeras pruebas con OpenGNSys
123#@author  Ramon Gomez, ETSII Universidad de Sevilla
124#@date    2009-07-28
[1e7eaab]125#*/ ##
[42669ebf]126function ogListHardwareInfo ()
127{
128# Si se solicita, mostrar ayuda.
[be74e2d]129if [ "$*" == "help" ]; then
[b550747]130    ogHelp "$FUNCNAME" "$FUNCNAME"
131    return
132fi
133
[42669ebf]134# Recopilación de disposibivos procesando la salida de \c lshw
[b550747]135ogEcho info "$MSG_HARDWAREINVENTORY}"
136lshw | awk 'BEGIN {type="mod";}
137        /product:/ {sub(/ *product: */,"");  prod=$0;}
138        /vendor:/  {sub(/ *vendor: */,"");   vend=$0;}
139        /version:/ {sub(/ *version: */,"v.");vers=$0;}
140        /size:/    {sub(/ *size: */,"");     size=$0;}
141        /\*-/      {if (type=="mem")
[c2b03eb]142                    print type"="size;
143                else
144                    if (type!="" && prod!="")
145                        print type"="vend,prod,size,vers;
146                type=prod=vend=vers=size="";}
[b550747]147        /-core/    {type="boa";}
148        /-firmware/ {type="bio";}
149        /-cpu/     {type="cpu";}
150        /-memory/  {type="mem";}
151        /-ide/     {type="ide";}
152        /-disk/    {type="dis";}
153        /-cdrom/   {type="cdr";}
154        /-display/ {type="vga";}
155        /-network/ {type="net";}
156        /-multimedia/ {type="mul";}
157        /-usb/     {type="usb";}
158        /-firewire/ {type="fir";}
159        /-serial/  {type="bus";}
160        END        {if (type!="" && prod!="")
[c2b03eb]161                    print type"="vend,prod,size,vers;}
[b550747]162      '
[42669ebf]163# */ (comentario para Doxygen)
[b550747]164}
165
166
[50a094c]167#/**
[42669ebf]168#         ogListSoftware int_ndisk int_npartition
[50a094c]169#@brief   Lista el inventario de software instalado en un sistema operativo.
[42669ebf]170#@param   int_ndisk      nº de orden del disco
171#@param   int_npartition nº de orden de la partición
172#@return  programa versión ...
[50a094c]173#@warning Se ignoran los parámetros de entrada.
174#@note    Requisitos: ...
175#@todo    Detectar software en Linux
176#@version 0.1 - Primeras pruebas con OpenGNSys
177#@author  Ramon Gomez, ETSII Universidad de Sevilla
178#@date    2009-09-23
[1e7eaab]179#*/ ##
[42669ebf]180function ogListSoftware ()
181{
[50a094c]182# Variables locales.
[71643c0]183local MNTDIR TYPE DPKGDIR RPMDIR PACMANDIR KEYS KEYS32 k PROG VERS
[50a094c]184
[42669ebf]185# Si se solicita, mostrar ayuda.
[be74e2d]186if [ "$*" == "help" ]; then
[50a094c]187    ogHelp "$FUNCNAME" "$FUNCNAME 1 1"
188    return
189fi
[42669ebf]190# Error si no se reciben 2 parametros.
[50a094c]191[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
192
[42669ebf]193# Obtener tipo de sistema de archivos y montarlo.
[50a094c]194TYPE=$(ogGetFsType $1 $2) || return $?
195MNTDIR=$(ogMount $1 $2) || return $?
196
197case "$TYPE" in
[c2b03eb]198    EXT[234]|REISERFS|REISER4)
199        # Procesar paquetes dpkg.
200        DPKGDIR="${MNTDIR}/var/lib/dpkg"
201        if [ -r $DPKGDIR ]; then
202        #    dpkg --admindir=$DPKGDIR -l | \
203            # Proceso de fichero en sistemas de 64 bits.
204            if [ -e $MNTDIR/lib64 ]; then
205                awk '/Package:/ {if (pack!="") print pack,vers;
206                                 sub(/-dev$/,"",$2);
207                                 pack=$2}
208                     /Version:/ {sub(/^.*:/,"",$2); sub(/-.*$/,"",$2);
209                                 vers=$2}
210                     /Status:/  {if ($2!="install") pack=vers=""}
211                     END        {if (pack!="") print pack,vers}
212                    ' $MNTDIR/var/lib/dpkg/status | sort | uniq
213            else
214                # FIXME Sólo 32 bits
215                chroot "$MNTDIR" /usr/bin/dpkg -l | \
216                    awk '$1~/ii/ {sub(/-dev$/,"",$2); sub(/^.*:/,"",$3);
217                                  sub(/-.*$/,"",$3); print $2,$3}
218                        ' | sort | uniq
219            fi
220        fi
221        # Procesar paquetes RPM.
222        RPMDIR="${MNTDIR}/var/lib/rpm"
223        if [ -r $RPMDIR ]; then
224            # Correccion inconsistencia de version de base de datos.
225            #    rm -f ${RPMDIR}/__db.*
226            #    rpm --dbpath $RPMDIR -qa --qf "%{NAME} %{VERSION}\n" | \
227            # FIXME Sólo 32 bits
228            chroot $MNTDIR /bin/rpm -qa --qf "%{NAME} %{VERSION}\n" | \
229                   awk '$1!~/-devel$/ {sub(/-.*$/,"",$2); print $0}' | \
230                   sort | uniq
231                #    rm -f ${RPMDIR}/__db.*
232        fi
[2e472ef3]233        # Procesar paquetes pacman.
234        PACMANDIR="${MNTDIR}/var/lib/pacman/local"
235        if [ -r $PACMANDIR ]; then
236            # FIXME Separar nombre y versión de los paquetes
237            ls -A $PACMANDIR
238        fi
[c2b03eb]239        ;;
240    NTFS|HNTFS|FAT32|HFAT32)
241        # Claves de registro para programas instalados: formato "{clave}".
242        KEYS=$(ogListRegistryKeys $MNTDIR software '\Microsoft\Windows\CurrentVersion\Uninstall')
[71643c0]243        KEYS32=$(ogListRegistryKeys $MNTDIR software '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
[c2b03eb]244        # Mostrar los valores "DisplayName" y "DisplayVersion" para cada clave.
245        (for k in $KEYS; do
246            PROG=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
247            if [ -n "$PROG" ]; then
248                VERS=$(ogGetRegistryValue $MNTDIR software "\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
249                echo "$PROG $VERS"
250            fi
[71643c0]251        done
252        for k in $KEYS32; do
253            PROG=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayName")
254            if [ -n "$PROG" ]; then
255                VERS=$(ogGetRegistryValue $MNTDIR software "\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\$k\\DisplayVersion")
256                echo "$PROG $VERS"
257            fi
[c2b03eb]258        done) | sort | uniq
259        ;;
260    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
[50a094c]261        return $? ;;
262esac
263}
264
[be74e2d]265#/**  @function ogInfoCache: @brief muestra la informacion de la CACHE.
266#@param  sin parametros
267#@return  texto que se almacena en $IP.-InfoCache.  punto_montaje, tama?oTotal, TamanioOcupado, TaminioLibre, imagenes dentro de la cahce
268#@warning  Salidas de errores no determinada
269#@warning   printf no soportado por busybox
270#@attention
271#@version 0.1   Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga
272#*/
[71643c0]273function ogInfoCache ()
274{
275local info infoFilesystem infoSize infoUsed infoUsedPorcet infoMountedOn content
[be74e2d]276if ogMountCache
277then
278        info=`df -h | grep $OGCAC`
279        infoFilesystem=`echo $info | cut -f1 -d" "`
280        infoSize=`echo $info | cut -f2 -d" "`
281        infoUsed=`echo $info | cut -f3 -d" "`
282        infoAvail=`echo $info | cut -f4 -d" "`
283        infoUsedPorcet=`echo $info | cut -f5 -d" "`
284        infoMountedOn=`echo $info | cut -f2 -d" "`
285        if `ls  ${OGCAC}$OGIMG > /dev/null 2>&1`
286        then
287               cd ${OGCAC}${OPENGNSYS}
288                #content=`find images/ -type f -printf "%h/  %f  %s \n"`   busybox no soporta printf
289                content=`find images/ -type f`
290                cd /
291                echo $info
292                echo -ne $content
293                echo " "
294                #echo "$info" > ${OGLOG}/${IP}-InfoCache
295                #echo "$content" >> {$OGLOG}/${IP}-InfoCache
296        else
297                echo $info
298                #echo "$info" > {$OGLOG}/${IP}-InfoCache
299        fi
300        ogUnmountCache
301else
302        echo " "
303        #echo " " > {$OGLOG}/${IP}-InfoCache
304
305fi
306}
[71643c0]307
Note: See TracBrowser for help on using the repository browser.