source: client/engine/Inventory.lib @ 18679ed

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 18679ed was b1f562f, checked in by ramon <ramongomez@…>, 13 years ago

Función ogGetOsVersion detecta Windwos de 64 bits.

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

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