source: client/engine/Inventory.lib @ 06be672

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 06be672 was 42669ebf, checked in by ramon <ramongomez@…>, 15 years ago

Funciones adaptadas a plantilla Doxygen; nueva función ogFsToId.

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

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