[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. |
---|
[1c04494] | 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 |
---|
[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 |
---|
| 26 | #*/ |
---|
| 27 | function ogGetOsVersion () { |
---|
| 28 | |
---|
| 29 | # Variables locales. |
---|
| 30 | local MNTDIR TYPE VERSION FILE |
---|
| 31 | |
---|
| 32 | #/// Si se solicita, mostrar ayuda. |
---|
[be74e2d] | 33 | if [ "$*" == "help" ]; then |
---|
[1d531f9] | 34 | ogHelp "$FUNCNAME" "$FUNCNAME" |
---|
| 35 | return |
---|
| 36 | fi |
---|
| 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. |
---|
| 41 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
| 42 | |
---|
[89403cd] | 43 | #/// Elección del tipo de sistema operativo. |
---|
[1d531f9] | 44 | case "$(ogGetFsType $1 $2)" in |
---|
| 45 | EXT[234] | REISERFS | REISER4) |
---|
[1c04494] | 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 | ;; |
---|
[1d531f9] | 60 | NTFS | HTNFS | FAT32 | HFAT32) |
---|
[1c04494] | 61 | TYPE="Windows" |
---|
| 62 | #/// Para Windows: leer la version del registro. |
---|
| 63 | VERSION=$(ogGetRegistryValue $MNTDIR software '\Microsoft\Windows NT\CurrentVersion\ProductName') |
---|
| 64 | ;; |
---|
[1d531f9] | 65 | esac |
---|
| 66 | |
---|
| 67 | #/// Mostrar resultado y salir sin errores. |
---|
| 68 | [ -n "$VERSION" ] && echo "$TYPE:$VERSION" |
---|
[d071d9b] | 69 | return 0 |
---|
[1d531f9] | 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | #/** |
---|
[1c04494] | 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 | #*/ |
---|
| 82 | function ogGetOsType () { |
---|
| 83 | ogGetOsVersion "$@" | cut -sf1 -d: |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | #/** |
---|
[b550747] | 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 | #*/ |
---|
| 98 | function ogListHardwareInfo () { |
---|
| 99 | |
---|
| 100 | #/// Si se solicita, mostrar ayuda. |
---|
[be74e2d] | 101 | if [ "$*" == "help" ]; then |
---|
[b550747] | 102 | ogHelp "$FUNCNAME" "$FUNCNAME" |
---|
| 103 | return |
---|
| 104 | fi |
---|
| 105 | |
---|
| 106 | #/// Recopilación de disposibivos procesando la salida de \c lshw |
---|
| 107 | ogEcho info "$MSG_HARDWAREINVENTORY}" |
---|
| 108 | lshw | 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") |
---|
[c2b03eb] | 114 | print type"="size; |
---|
| 115 | else |
---|
| 116 | if (type!="" && prod!="") |
---|
| 117 | print type"="vend,prod,size,vers; |
---|
| 118 | type=prod=vend=vers=size="";} |
---|
[b550747] | 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!="") |
---|
[c2b03eb] | 133 | print type"="vend,prod,size,vers;} |
---|
[b550747] | 134 | ' |
---|
[89403cd] | 135 | # */ (necesario para Doxygen) |
---|
[b550747] | 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
[50a094c] | 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 | #*/ |
---|
| 150 | function ogListSoftware () { |
---|
| 151 | |
---|
| 152 | # Variables locales. |
---|
| 153 | local MNTDIR TYPE DPKGDIR RPMDIR KEYS k PROG VERS |
---|
| 154 | |
---|
| 155 | #/// Si se solicita, mostrar ayuda. |
---|
[be74e2d] | 156 | if [ "$*" == "help" ]; then |
---|
[50a094c] | 157 | ogHelp "$FUNCNAME" "$FUNCNAME 1 1" |
---|
| 158 | return |
---|
| 159 | fi |
---|
| 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. |
---|
| 164 | TYPE=$(ogGetFsType $1 $2) || return $? |
---|
| 165 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
| 166 | |
---|
| 167 | case "$TYPE" in |
---|
[c2b03eb] | 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" |
---|
[50a094c] | 217 | return $? ;; |
---|
| 218 | esac |
---|
| 219 | } |
---|
| 220 | |
---|
[be74e2d] | 221 | function 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 | #*/ |
---|
| 230 | if ogMountCache |
---|
| 231 | then |
---|
| 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 |
---|
| 255 | else |
---|
| 256 | echo " " |
---|
| 257 | #echo " " > {$OGLOG}/${IP}-InfoCache |
---|
| 258 | |
---|
| 259 | fi |
---|
| 260 | } |
---|