source: client/engine/Inventory.lib @ a0da76f

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 a0da76f 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
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 1.0.4
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 - tipo y versión del sistema operativo.
37#@note    OSType = { Android, BSD, Linux, MacOS, Solaris, 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#@version 1.0.4 - Incluir tipos BSD, MacOS y Solaris.
46#@author  Ramon Gomez, ETSII Universidad de Sevilla
47#@date    2012-06-29
48#*/ ##
49function ogGetOsVersion ()
50{
51# Variables locales.
52local MNTDIR TYPE DISTRIB VERSION FILE
53# Si se solicita, mostrar ayuda.
54if [ "$*" == "help" ]; then
55    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
56           "$FUNCNAME 1 2  =>  Linux:Ubuntu 11.04 64 bits"
57    return
58fi
59# Error si no se reciben 2 parametros.
60[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
61
62# Montar la particion, si no lo estaba previamente.
63MNTDIR=$(ogMount $1 $2) || return $?
64
65# Elección del tipo de sistema operativo.
66case "$(ogGetFsType $1 $2)" in
67    EXT[234] | BTRFS | REISERFS | REISER4)
68        TYPE="Linux"
69        # Para Linux: leer descripción.
70        VERSION=$(chroot $MNTDIR lsb_release -d 2>/dev/null | awk -F":\t" '{print $2}')
71        # Si no se puede obtener, buscar en ficheros del sistema.
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)"
75            for DISTRIB in redhat SuSE mandrake gentoo; do
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"
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
88        fi
89        [ -e $MNTDIR/lib64 ] && VERSION="$VERSION $MSG_64BIT"
90        ;;
91    NTFS | HNTFS | FAT32 | HFAT32)
92        TYPE="Windows"
93        # Para Windows: leer la version del registro.
94        VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName')
95        [ -n "$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows\CurrentVersion\ProgramW6432Dir' 2>/dev/null)" ] && VERSION="$VERSION $MSG_64BIT"
96        ;;
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.
115        FILE="$MNTDIR/etc/release"
116        [ -r $FILE ] && VERSION="$(head -1 $FILE)"
117        ;;
118esac
119
120# Mostrar resultado y salir sin errores.
121[ -n "$VERSION" ] && echo "$TYPE:$VERSION"
122return 0
123}
124
125
126#/**
127#         ogGetOsType int_ndisk int_npartition
128#@brief   Devuelve el tipo del sistema operativo instalado.
129#@param   int_ndisk      nº de orden del disco
130#@param   int_npartition nº de orden de la partición
131#@return  OSType - Tipo de sistema operativo.
132#@note    OSType = { Android, BSD, Linux, MacOS, Windows }
133#@see     ogGetOsVersion
134#*/ ##
135function ogGetOsType ()
136{
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
143ogGetOsVersion "$@" | cut -sf1 -d:
144}
145
146
147#/**
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
154#@version 0.1 - Primeras pruebas con OpenGnSys
155#@author  Ramon Gomez, ETSII Universidad de Sevilla
156#@date    2009-07-28
157#*/ ##
158function ogListHardwareInfo ()
159{
160# Si se solicita, mostrar ayuda.
161if [ "$*" == "help" ]; then
162    ogHelp "$FUNCNAME" "$FUNCNAME"
163    return
164fi
165
166# Recopilación de disposibivos procesando la salida de \c lshw
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")
174                    print type"="size;
175                else
176                    if (type!="" && prod!="")
177                        print type"="vend,prod,size,vers;
178                type=prod=vend=vers=size="";}
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!="")
193                    print type"="vend,prod,size,vers;}
194      '
195# */ (comentario para Doxygen)
196}
197
198
199#/**
200#         ogListSoftware int_ndisk int_npartition
201#@brief   Lista el inventario de software instalado en un sistema operativo.
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 ...
205#@warning Se ignoran los parámetros de entrada.
206#@note    Requisitos: ...
207#@todo    Detectar software en Linux
208#@version 0.1 - Primeras pruebas con OpenGnSys
209#@author  Ramon Gomez, ETSII Universidad de Sevilla
210#@date    2009-09-23
211#*/ ##
212function ogListSoftware ()
213{
214# Variables locales.
215local MNTDIR TYPE DPKGDIR RPMDIR PACMANDIR KEYS KEYS32 k PROG VERS
216
217# Si se solicita, mostrar ayuda.
218if [ "$*" == "help" ]; then
219    ogHelp "$FUNCNAME" "$FUNCNAME 1 1"
220    return
221fi
222# Error si no se reciben 2 parametros.
223[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
224
225# Obtener tipo de sistema de archivos y montarlo.
226TYPE=$(ogGetFsType $1 $2) || return $?
227MNTDIR=$(ogMount $1 $2) || return $?
228
229case "$TYPE" in
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
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
271        ;;
272    NTFS|HNTFS|FAT32|HFAT32)
273        # Claves de registro para programas instalados: formato "{clave}".
274        KEYS=$(ogListRegistryKeys $MNTDIR software '\Microsoft\Windows\CurrentVersion\Uninstall')
275        KEYS32=$(ogListRegistryKeys $MNTDIR software '\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
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
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
290        done) | sort | uniq
291        ;;
292    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
293        return $? ;;
294esac
295}
296
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#*/
305function ogInfoCache ()
306{
307local info infoFilesystem infoSize infoUsed infoUsedPorcet infoMountedOn content
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}
339
Note: See TracBrowser for help on using the repository browser.