source: client/engine/Inventory.lib @ c2b03eb

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

Función ogListSoftware detecta packetes deb en 64 bits.

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

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