source: client/engine/Inventory.lib @ 47e0819

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 47e0819 was 6a08da7, checked in by ramon <ramongomez@…>, 13 years ago

#548: Corregir errata en detección de Solaris.

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

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