source: client/engine/Inventory.lib @ 5e1020c

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 5e1020c was cdea14a, checked in by danigm <danigm@…>, 14 years ago

Documentacion de ogInfoCache encima, como en el resto

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

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