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