source: client/engine/Inventory.lib @ 6654a24

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

Correcciones en scripts; metafunción ogGetOsType.

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

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