source: client/engine/Inventory.lib @ 18679ed

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 18679ed was b1f562f, checked in by ramon <ramongomez@…>, 13 years ago

Función ogGetOsVersion detecta Windwos de 64 bits.

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

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