source: client/engine/Inventory.lib @ 74c04a0

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 74c04a0 was 2e472ef3, checked in by ramon <ramongomez@…>, 15 years ago

Soporte básico para detectar Mandrake y Arch Linux.

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

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