source: client/engine/Inventory.lib @ e4dafd6

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 e4dafd6 was e4dafd6, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: continuar revisando variables locales y ayudas de las funciones del motor de clonación (modifica #446).

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

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