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