source: client/engine/Inventory.lib @ e42f34e

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 e42f34e was 8964f9b, checked in by ramon <ramongomez@…>, 16 years ago

Resstructuración de trunk.

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

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