source: client/engine/Inventory.lib @ 4c475a32

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 4c475a32 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
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.
[42669ebf]15#@param   int_ndisk      nº de orden del disco
16#@param   int_npartition nº de orden de la partición
[1c04494]17#@return  OSType:OSVersion
[1d531f9]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.
[1c04494]23#@version 0.9 - Primera versión para OpenGNSys
[1d531f9]24#@author  Ramon Gomez, ETSII Universidad de Sevilla
25#@date    2009-09-15
[1e7eaab]26#*/ ##
[42669ebf]27function ogGetOsVersion ()
28{
[1d531f9]29# Variables locales.
[2e472ef3]30local MNTDIR TYPE DISTRIB VERSION FILE
[1d531f9]31
[42669ebf]32# Si se solicita, mostrar ayuda.
[be74e2d]33if [ "$*" == "help" ]; then
[1d531f9]34    ogHelp "$FUNCNAME" "$FUNCNAME"
35    return
36fi
[42669ebf]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
[42669ebf]43# Elección del tipo de sistema operativo.
[1d531f9]44case "$(ogGetFsType $1 $2)" in
45    EXT[234] | REISERFS | REISER4)
[1c04494]46        TYPE="Linux"
[42669ebf]47        # Para Linux: leer descripción.
[1c04494]48        VERSION=$(chroot $MNTDIR lsb_release -d 2>/dev/null| awk -F: '{gsub (/\t/,""); print $2}')
[42669ebf]49        # Si no se puede obtener, buscar en ficheros del sistema.
[1c04494]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)"
[2e472ef3]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"
[1c04494]59        fi
60        [ -e $MNTDIR/lib64 ] && VERSION="$VERSION 64 bits"
61        ;;
[1d531f9]62    NTFS | HTNFS | FAT32 | HFAT32)
[1c04494]63        TYPE="Windows"
[42669ebf]64        # Para Windows: leer la version del registro.
[1c04494]65        VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName')
66        ;;
[1d531f9]67esac
68
[42669ebf]69# Mostrar resultado y salir sin errores.
[1d531f9]70[ -n "$VERSION" ] && echo "$TYPE:$VERSION"
[d071d9b]71return 0
[1d531f9]72}
73
74
75#/**
[1c04494]76#         ogGetOsType int_ndisk int_npartition
77#@brief   Devuelve el tipo del sistema operativo instalado.
[42669ebf]78#@param   int_ndisk      nº de orden del disco
79#@param   int_npartition nº de orden de la partición
[1c04494]80#@return  OSType
81#@note    OSType = { Linux, Windows }
82#@see     ogGetOsVersion
[1e7eaab]83#*/ ##
[42669ebf]84function ogGetOsType ()
85{
[1c04494]86ogGetOsVersion "$@" | cut -sf1 -d:
87}
88
89
90#/**
[b550747]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
[1e7eaab]100#*/ ##
[42669ebf]101function ogListHardwareInfo ()
102{
103# Si se solicita, mostrar ayuda.
[be74e2d]104if [ "$*" == "help" ]; then
[b550747]105    ogHelp "$FUNCNAME" "$FUNCNAME"
106    return
107fi
108
[42669ebf]109# Recopilación de disposibivos procesando la salida de \c lshw
[b550747]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")
[c2b03eb]117                    print type"="size;
118                else
119                    if (type!="" && prod!="")
120                        print type"="vend,prod,size,vers;
121                type=prod=vend=vers=size="";}
[b550747]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!="")
[c2b03eb]136                    print type"="vend,prod,size,vers;}
[b550747]137      '
[42669ebf]138# */ (comentario para Doxygen)
[b550747]139}
140
141
[50a094c]142#/**
[42669ebf]143#         ogListSoftware int_ndisk int_npartition
[50a094c]144#@brief   Lista el inventario de software instalado en un sistema operativo.
[42669ebf]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 ...
[50a094c]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
[1e7eaab]154#*/ ##
[42669ebf]155function ogListSoftware ()
156{
[50a094c]157# Variables locales.
158local MNTDIR TYPE DPKGDIR RPMDIR KEYS k PROG VERS
159
[42669ebf]160# Si se solicita, mostrar ayuda.
[be74e2d]161if [ "$*" == "help" ]; then
[50a094c]162    ogHelp "$FUNCNAME" "$FUNCNAME 1 1"
163    return
164fi
[42669ebf]165# Error si no se reciben 2 parametros.
[50a094c]166[ $# = 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
167
[42669ebf]168# Obtener tipo de sistema de archivos y montarlo.
[50a094c]169TYPE=$(ogGetFsType $1 $2) || return $?
170MNTDIR=$(ogMount $1 $2) || return $?
171
172case "$TYPE" in
[c2b03eb]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
[2e472ef3]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
[c2b03eb]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"
[50a094c]228        return $? ;;
229esac
230}
231
[be74e2d]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.