1 | #!/bin/bash |
---|
2 | #/** |
---|
3 | #@file Protocol.lib |
---|
4 | #@brief Librería o clase Protocol |
---|
5 | #@class Protocol |
---|
6 | #@brief Funciones para transmisión de datos |
---|
7 | #@version 1.0 |
---|
8 | #@warning License: GNU GPLv3+ |
---|
9 | #*/ |
---|
10 | |
---|
11 | #/** |
---|
12 | # ogUcastSyntax |
---|
13 | #@brief Función para generar la instrucción de transferencia de datos unicast |
---|
14 | #@param 1 Tipo de operación [ SENDPARTITION RECEIVERPARTITION SENDFILE RECEIVERFILE ] |
---|
15 | #@param 2 Sesion Unicast |
---|
16 | #@param 3 Dispositivo (opción PARTITION) o fichero(opción FILE) que será enviado. |
---|
17 | #@param 4 Tools de clonación (opcion PARTITION) |
---|
18 | #@param 5 Tools de compresion (opcion PARTITION) |
---|
19 | #@return instrucción para ser ejecutada. |
---|
20 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
21 | #@exception OG_ERR_UCASTSYNTAXT formato de la sesion unicast incorrecta. |
---|
22 | #@note Requisitos: mbuffer |
---|
23 | #@todo: controlar que mbuffer esta disponible para los clientes. |
---|
24 | #@version 1.0 - |
---|
25 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
26 | #@date 2011/03/09 |
---|
27 | #*/ ## |
---|
28 | |
---|
29 | |
---|
30 | ##################### FUNCIONES UNICAST ################ |
---|
31 | |
---|
32 | function ogUcastSyntax () |
---|
33 | { |
---|
34 | |
---|
35 | local PARM SESSION SESSIONPARM MODE PORTBASE PERROR |
---|
36 | local ADDRESS |
---|
37 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
38 | |
---|
39 | # Si se solicita, mostrar ayuda. |
---|
40 | if [ "$*" == "help" -o "$2" == "help" ]; then |
---|
41 | ogHelp "$FUNCNAME SENDPARTITION str_sessionSERVER str_device str_tools str_level" \ |
---|
42 | "$FUNCNAME RECEIVERPARTITION str_sessionCLIENT str_device str_tools str_level "\ |
---|
43 | "$FUNCNAME SENDFILE str_sessionSERVER str_file "\ |
---|
44 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
45 | "sessionServer syntax: portbase:ipCLIENT-1:ipCLIENT-2:ipCLIENT-N " \ |
---|
46 | "sessionServer example: 8000:172.17.36.11:172.17.36.12" \ |
---|
47 | "sessionClient syntax: portbase:ipMASTER " \ |
---|
48 | "sessionClient example: 8000:172.17.36.249 " |
---|
49 | return |
---|
50 | fi |
---|
51 | PERROR=0 |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | # Error si no se reciben $PARM parámetros. |
---|
57 | echo "$1" | grep "PARTITION" > /dev/null && PARM=5 || PARM=3 |
---|
58 | [ "$#" -eq "$PARM" ] || ogRaiseError $OG_ERR_FORMAT "sin parametros"|| return $? |
---|
59 | |
---|
60 | |
---|
61 | # 1er param check |
---|
62 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
63 | |
---|
64 | # 2º param check |
---|
65 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
66 | |
---|
67 | ######### No controlamos el numero de elementos de la session unicast porque en el master es variable en numero |
---|
68 | #TODO: diferenciamos los paramatros especificos de la sessión unicast |
---|
69 | #SI: controlamos todos los parametros de la sessión unicast. |
---|
70 | #[ $MODE == "client" ] && SESSIONPARM=2 || SESSIONPARM=6 |
---|
71 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
72 | |
---|
73 | |
---|
74 | #[[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
75 | |
---|
76 | |
---|
77 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
78 | PORTBASE=${SESSION[0]} |
---|
79 | ogCheckStringInGroup ${SESSION[0]} "8000 8001 8002 8003 8004 8005" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
80 | |
---|
81 | if [ $MODE == "server" ] |
---|
82 | then |
---|
83 | SIZEARRAY=${#SESSION[@]} |
---|
84 | for (( i = 1 ; i < $SIZEARRAY ; i++ )) |
---|
85 | do |
---|
86 | ADDRESS="$ADDRESS -O ${SESSION[$i]}:$PORTBASE" |
---|
87 | #echo " -O ${SESSION[$i]}:$PORTBASE" |
---|
88 | done |
---|
89 | |
---|
90 | else |
---|
91 | ADDRESS=${SESSION[1]}:${PORTBASE} |
---|
92 | fi |
---|
93 | |
---|
94 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
95 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
96 | DEVICE=$3 |
---|
97 | |
---|
98 | #4 y 5 param check . solo si es sobre particiones. |
---|
99 | if [ "$PARM" == "5" ] |
---|
100 | then |
---|
101 | # 4 param check |
---|
102 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
103 | TOOL=$4 |
---|
104 | ogCheckStringInGroup "$5" "lzop gzip LZOP GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
105 | LEVEL=$5 |
---|
106 | fi |
---|
107 | |
---|
108 | [ "$PERROR" == "0" ] || ogRaiseError $OG_ERR_UCASTSYNTAXT " $PERROR" || return $? |
---|
109 | |
---|
110 | # Generamos la instrucción base de unicast -Envio,Recepcion- |
---|
111 | SYNTAXSERVER="mbuffer $ADDRESS" |
---|
112 | SYNTAXCLIENT="mbuffer -I $ADDRESS " |
---|
113 | |
---|
114 | |
---|
115 | case "$1" in |
---|
116 | SENDPARTITION) |
---|
117 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
118 | echo "$PROG1 | $SYNTAXSERVER" |
---|
119 | ;; |
---|
120 | RECEIVERPARTITION) |
---|
121 | COMPRESSOR=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $1}'` |
---|
122 | TOOLS=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $NF}'` |
---|
123 | echo "$SYNTAXCLIENT | $COMPRESSOR | $TOOLS " |
---|
124 | ;; |
---|
125 | SENDFILE) |
---|
126 | echo "$SYNTAXSERVER --file $3" |
---|
127 | ;; |
---|
128 | RECEIVERFILE) |
---|
129 | echo "$SYNTAXCLIENT --file $3" |
---|
130 | ;; |
---|
131 | *) |
---|
132 | ;; |
---|
133 | esac |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | #/** |
---|
138 | # ogUcastSendPartition |
---|
139 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas usando UNICAST. |
---|
140 | #@param 1 disk |
---|
141 | #@param 2 partition |
---|
142 | #@param 3 sesionUcast |
---|
143 | #@param 4 tool image |
---|
144 | #@param 5 tool compresor |
---|
145 | #@return |
---|
146 | #@exception $OG_ERR_FORMAT |
---|
147 | #@exception $OG_ERR_UCASTSENDPARTITION |
---|
148 | #@note |
---|
149 | #@todo: ogIsLocked siempre devuelve 1 |
---|
150 | #@version 1.0 - |
---|
151 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
152 | #@date 2011/03/09 |
---|
153 | #*/ ## |
---|
154 | |
---|
155 | function ogUcastSendPartition () |
---|
156 | { |
---|
157 | |
---|
158 | # Variables locales |
---|
159 | local PART COMMAND RETVAL |
---|
160 | |
---|
161 | # Si se solicita, mostrar ayuda. |
---|
162 | if [ "$*" == "help" ]; then |
---|
163 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionUNICAST-SERVER tools compresor" \ |
---|
164 | "$FUNCNAME 1 1 8000:172.17.36.11:172.17.36.12 partclone lzop" |
---|
165 | return |
---|
166 | fi |
---|
167 | # Error si no se reciben 5 parámetros. |
---|
168 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
169 | #chequeamos la particion. |
---|
170 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
171 | |
---|
172 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
173 | ogUnmount $1 $2 |
---|
174 | |
---|
175 | |
---|
176 | #generamos la instrucción a ejecutar. |
---|
177 | COMMAND=`ogUcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
178 | RETVAL=$? |
---|
179 | |
---|
180 | if [ "$RETVAL" -gt "0" ] |
---|
181 | then |
---|
182 | return $RETVAL |
---|
183 | else |
---|
184 | echo $COMMAND |
---|
185 | eval $COMMAND || ogRaiseError $OG_ERR_UCASTSENDPARTITION " "; return $? |
---|
186 | fi |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | #/** |
---|
191 | # ogUcastReceiverPartition |
---|
192 | #@brief Función para recibir directamente en la partición el contenido de un fichero imagen remoto enviado por UNICAST. |
---|
193 | #@param 1 disk |
---|
194 | #@param 2 partition |
---|
195 | #@param 3 session unicast |
---|
196 | #@return |
---|
197 | #@exception OG_ERR_FORMAT |
---|
198 | #@exception OG_ERR_UCASTRECEIVERPARTITION |
---|
199 | #@note |
---|
200 | #@todo: |
---|
201 | #@version 1.0 - Integración para OpenGNSys. |
---|
202 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
203 | #@date 2011/03/09 |
---|
204 | #*/ ## |
---|
205 | function ogUcastReceiverPartition () |
---|
206 | { |
---|
207 | # Variables locales |
---|
208 | local PART COMMAND RETVAL |
---|
209 | |
---|
210 | # Si se solicita, mostrar ayuda. |
---|
211 | if [ "$*" == "help" ]; then |
---|
212 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastCLIENT tools compresor" \ |
---|
213 | "$FUNCNAME 1 1 8000:ipMASTER partclone lzop" |
---|
214 | return |
---|
215 | fi |
---|
216 | # Error si no se reciben 5 parámetros. |
---|
217 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
218 | #chequeamos la particion. |
---|
219 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
220 | |
---|
221 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
222 | ogUnmount $1 $2 |
---|
223 | |
---|
224 | |
---|
225 | #generamos la instrucción a ejecutar. |
---|
226 | COMMAND=`ogUcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
227 | RETVAL=$? |
---|
228 | |
---|
229 | if [ "$RETVAL" -gt "0" ] |
---|
230 | then |
---|
231 | return $RETVAL |
---|
232 | else |
---|
233 | echo $COMMAND |
---|
234 | eval $COMMAND || ogRaiseError $OG_ERR_UCASTRECEIVERPARTITION " "; return $? |
---|
235 | fi |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | #/** |
---|
241 | # ogMcastSyntax |
---|
242 | #@brief Función para generar la instrucción de ejucción la transferencia de datos multicast |
---|
243 | #@param 1 Tipo de operación [ SENDPARTITION RECEIVERPARTITION SENDFILE RECEIVERFILE ] |
---|
244 | #@param 2 Sesión Mulicast |
---|
245 | #@param 3 Dispositivo (opción PARTITION) o fichero(opción FILE) que será enviado. |
---|
246 | #@param 4 Tools de clonación (opcion PARTITION) |
---|
247 | #@param 5 Tools de compresion (opcion PARTITION) |
---|
248 | #@return instrucción para ser ejecutada. |
---|
249 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
250 | #@exception OG_ERR_NOTEXEC |
---|
251 | #@exception OG_ERR_MCASTSYNTAXT |
---|
252 | #@note Requisitos: upd-cast 2009 o superior |
---|
253 | #@todo localvar check versionudp |
---|
254 | #@version 1.0 - |
---|
255 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
256 | #@date 2010/05/09 |
---|
257 | #*/ ## |
---|
258 | # |
---|
259 | |
---|
260 | |
---|
261 | function ogMcastSyntax () |
---|
262 | { |
---|
263 | |
---|
264 | local ISUDPCAST PARM SESSION SESSIONPARM MODE PORTBASE PERROR |
---|
265 | local METHOD ADDRESS BITRATE NCLIENTS MAXTIME CERROR |
---|
266 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
267 | |
---|
268 | # Si se solicita, mostrar ayuda. |
---|
269 | if [ "$*" == "help" -o "$2" == "help" ]; then |
---|
270 | ogHelp "$FUNCNAME SENDPARTITION str_sessionSERVER str_device str_tools str_level" \ |
---|
271 | "$FUNCNAME RECEIVERPARTITION str_sessionCLIENT str_device str_tools str_level "\ |
---|
272 | "$FUNCNAME SENDFILE str_sessionSERVER str_file "\ |
---|
273 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
274 | "sessionServer syntax: portbase:method:mcastaddress:speed:nclients:ntimeWaitingUntilNclients " \ |
---|
275 | "sessionServer example: 9000:full-duplex|half-duplex|broadcast:239.194.17.36:80M:50:60 " \ |
---|
276 | "sessionClient syntax: portbase " \ |
---|
277 | "sessionClient example: 9000 " |
---|
278 | return |
---|
279 | fi |
---|
280 | PERROR=0 |
---|
281 | |
---|
282 | #si no tenemos updcast o su version superior 2009 udpcast error. |
---|
283 | ISUDPCAST=$(udp-receiver --help 2>&1) |
---|
284 | echo $ISUDPCAST | grep start-timeout > /dev/null || ogRaiseError $OG_ERR_NOTEXEC "upd-cast no existe o version antigua -requerida 2009-"|| return $? |
---|
285 | |
---|
286 | |
---|
287 | # Error si no se reciben $PARM parámetros. |
---|
288 | echo "$1" | grep "PARTITION" > /dev/null && PARM=5 || PARM=3 |
---|
289 | [ "$#" -eq "$PARM" ] || ogRaiseError $OG_ERR_FORMAT "sin parametros"|| return $? |
---|
290 | |
---|
291 | |
---|
292 | # 1er param check |
---|
293 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
294 | |
---|
295 | # 2º param check |
---|
296 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
297 | |
---|
298 | #TODO: diferenciamos los paramatros especificos de la sessión multicast |
---|
299 | #SI: controlamos todos los parametros de la sessión multicast. |
---|
300 | [ $MODE == "client" ] && SESSIONPARM=1 || SESSIONPARM=6 |
---|
301 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
302 | |
---|
303 | |
---|
304 | [[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
305 | |
---|
306 | |
---|
307 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
308 | PORTBASE=${SESSION[0]} |
---|
309 | ogCheckStringInGroup ${SESSION[0]} "9000 9002 9004 9006 9008 9010" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
310 | if [ $MODE == "server" ] |
---|
311 | then |
---|
312 | ogCheckStringInGroup ${SESSION[1]} "full-duplex FULL-DUPLEX half-duplex HALF-DUPLEX broadcast BROADCAST" || ogRaiseError $OG_ERR_FORMAT "McastSession method ${SESSION[1]}" || PERROR=4 #return $? |
---|
313 | METHOD=${SESSION[1]} |
---|
314 | ogCheckIpAddress ${SESSION[2]} || ogRaiseError $OG_ERR_FORMAT "McastSession address ${SESSION[2]}" || PERROR=5 #return $? |
---|
315 | ADDRESS=${SESSION[2]} |
---|
316 | ogCheckStringInReg ${SESSION[3]} "^[0-9]{1,2}\M$" || ogRaiseError $OG_ERR_FORMAT "McastSession bitrate ${SESSION[3]}" || PERROR=6 # return $? |
---|
317 | BITRATE=${SESSION[3]} |
---|
318 | ogCheckStringInReg ${SESSION[4]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession nclients ${SESSION[4]}" || PERROR=7 # return $? |
---|
319 | NCLIENTS=${SESSION[4]} |
---|
320 | ogCheckStringInReg ${SESSION[5]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession maxtime ${SESSION[5]}" || PERROR=8 # return $? |
---|
321 | MAXTIME=${SESSION[5]} |
---|
322 | fi |
---|
323 | |
---|
324 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
325 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
326 | DEVICE=$3 |
---|
327 | |
---|
328 | #4 y 5 param check . solo si es sobre particiones. |
---|
329 | if [ "$PARM" == "5" ] |
---|
330 | then |
---|
331 | # 4 param check |
---|
332 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
333 | TOOL=$4 |
---|
334 | ogCheckStringInGroup "$5" "lzop LZOP gzip GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
335 | LEVEL=$5 |
---|
336 | fi |
---|
337 | |
---|
338 | |
---|
339 | if [ "$PERROR" != "0" ]; then |
---|
340 | ogRaiseError $OG_ERR_MCASTSYNTAXT " $PERROR"; return $? |
---|
341 | fi |
---|
342 | |
---|
343 | |
---|
344 | # Valores estandar no configurables. |
---|
345 | CERROR="8x8/128" |
---|
346 | |
---|
347 | # opción del usuo de tuberia intermedia en memoria mbuffer. |
---|
348 | which mbuffer > /dev/null && MBUFFER=" --pipe 'mbuffer -q -m 20M' " |
---|
349 | |
---|
350 | # Generamos la instrucción base de multicast -Envio,Recepcion- |
---|
351 | SYNTAXSERVER="udp-sender $MBUFFER --portbase $PORTBASE --$METHOD --mcast-data-address $ADDRESS --fec $CERROR --max-bitrate $BITRATE --ttl 16 --min-clients $NCLIENTS --max-wait $MAXTIME --autostart $MAXTIME --log /tmp/mcast.log" |
---|
352 | SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE " |
---|
353 | |
---|
354 | |
---|
355 | case "$1" in |
---|
356 | SENDPARTITION) |
---|
357 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
358 | echo "$PROG1 | $SYNTAXSERVER" |
---|
359 | ;; |
---|
360 | RECEIVERPARTITION) |
---|
361 | COMPRESSOR=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $1}'` |
---|
362 | TOOLS=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $NF}'` |
---|
363 | echo "$SYNTAXCLIENT | $COMPRESSOR | $TOOLS " |
---|
364 | ;; |
---|
365 | SENDFILE) |
---|
366 | echo "$SYNTAXSERVER --file $3" |
---|
367 | ;; |
---|
368 | RECEIVERFILE) |
---|
369 | echo "$SYNTAXCLIENT --file $3" |
---|
370 | ;; |
---|
371 | *) |
---|
372 | ;; |
---|
373 | esac |
---|
374 | } |
---|
375 | |
---|
376 | |
---|
377 | |
---|
378 | #/** |
---|
379 | # ogMcastSendFile [ str_repo | int_ndisk int_npart ] /Relative_path_file sessionMulticast |
---|
380 | #@brief Envía un fichero por multicast ORIGEN(fichero) DESTINO(sessionmulticast) |
---|
381 | #@param (2 parámetros) $1 path_aboluto_fichero $2 sesionMcast |
---|
382 | #@param (3 parámetros) $1 Contenedor REPO|CACHE $2 path_absoluto_fichero $3 sesionMulticast |
---|
383 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero $4 sesionMulticast |
---|
384 | #@return |
---|
385 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
386 | #@exception $OG_ERR_NOTFOUND |
---|
387 | #@exception OG_ERR_MCASTSENDFILE |
---|
388 | #@note Requisitos: |
---|
389 | #@version 1.0 - Definición de Protocol.lib |
---|
390 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
391 | #@date 2010/05/09 |
---|
392 | #*/ ## |
---|
393 | # |
---|
394 | |
---|
395 | function ogMcastSendFile () |
---|
396 | { |
---|
397 | # Variables locales. |
---|
398 | local ARGS SOURCE TARGET COMMAND DEVICE RETVAL LOGFILE |
---|
399 | |
---|
400 | #LOGFILE="/tmp/mcast.log" |
---|
401 | |
---|
402 | #ARGS usado para controlar ubicación de la sesion multicast |
---|
403 | # Si se solicita, mostrar ayuda. |
---|
404 | if [ "$*" == "help" ]; then |
---|
405 | ogHelp "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast" \ |
---|
406 | "$FUNCNAME 1 1 /aula1/winxp.img sesionMcast" \ |
---|
407 | "$FUNCNAME REPO /aula1/ubuntu.iso sesionMcast" \ |
---|
408 | "$FUNCNAME CACHE /aula1/winxp.img sesionMcast" \ |
---|
409 | "$FUNCNAME /opt/opengnsys/images/aula1/hd500.vmx sesionMcast" |
---|
410 | return |
---|
411 | fi |
---|
412 | |
---|
413 | ARGS="$@" |
---|
414 | case "$1" in |
---|
415 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
416 | SOURCE=$(ogGetPath "$1") |
---|
417 | ARG=2 |
---|
418 | DEVICE="$1" |
---|
419 | ;; |
---|
420 | [1-9]*) # ndisco npartición. |
---|
421 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
422 | ARG=4 |
---|
423 | DEVICE="$1 $2 $3" |
---|
424 | ;; |
---|
425 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
426 | SOURCE=$(ogGetPath "$1" "$2") |
---|
427 | ARG=3 |
---|
428 | DEVICE="$1 $2 " |
---|
429 | ;; |
---|
430 | esac |
---|
431 | |
---|
432 | |
---|
433 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
434 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
435 | |
---|
436 | # Comprobar fichero origen |
---|
437 | ogGetPath $SOURCE &> /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $DEVICE not found" || return $? |
---|
438 | |
---|
439 | # eliminamos ficheros antiguos de log |
---|
440 | #rm $LOGFILE |
---|
441 | |
---|
442 | SESSION=${!ARG} |
---|
443 | |
---|
444 | |
---|
445 | |
---|
446 | #generamos la instrucción a ejecutar. |
---|
447 | COMMAND=`ogMcastSyntax "SENDFILE" "$SESSION" "$SOURCE"` |
---|
448 | RETVAL=$? |
---|
449 | |
---|
450 | if [ "$RETVAL" -gt "0" ] |
---|
451 | then |
---|
452 | return $RETVAL |
---|
453 | else |
---|
454 | echo $COMMAND |
---|
455 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDFILE " "; return $? |
---|
456 | #[ -s "$LOGFILE" ] || return 21 |
---|
457 | fi |
---|
458 | |
---|
459 | } |
---|
460 | |
---|
461 | |
---|
462 | |
---|
463 | #/** |
---|
464 | # ogMcastReceiverFile sesion Multicast [ str_repo | int_ndisk int_npart ] /Relative_path_file |
---|
465 | #@brief Recibe un fichero multicast ORIGEN(sesionmulticast) DESTINO(fichero) |
---|
466 | #@param (2 parámetros) $1 sesionMcastCLIENT $2 path_aboluto_fichero_destino |
---|
467 | #@param (3 parámetros) $1 sesionMcastCLIENT $2 Contenedor REPO|CACHE $3 path_absoluto_fichero_destino |
---|
468 | #@param (4 parámetros) $1 sesionMcastCLIENT $2 disk $3 particion $4 path_absoluto_fichero_destino |
---|
469 | #@return |
---|
470 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
471 | #@exception $OG_ERR_MCASTRECEIVERFILE |
---|
472 | #@note Requisitos: |
---|
473 | #@version 1.0 - Definición de Protocol.lib |
---|
474 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
475 | #@date 2010/05/09 |
---|
476 | #*/ ## |
---|
477 | # |
---|
478 | |
---|
479 | function ogMcastReceiverFile () |
---|
480 | { |
---|
481 | |
---|
482 | # Variables locales. |
---|
483 | local ARGS ARG TARGETDIR TARGETFILE |
---|
484 | |
---|
485 | |
---|
486 | # Si se solicita, mostrar ayuda. |
---|
487 | if [ "$*" == "help" ]; then |
---|
488 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_portMcast] [ [Relative_path_file] | [str_REPOSITORY path_file] | [int_ndisk int_npart path_file ] ]" \ |
---|
489 | "$FUNCNAME 9000 /PS1_PH1.img" \ |
---|
490 | "$FUNCNAME 9000 CACHE /aula1/PS2_PH4.img" \ |
---|
491 | "$FUNCNAME 9000 1 1 /isos/linux.iso" |
---|
492 | return |
---|
493 | fi |
---|
494 | |
---|
495 | ARGS="$@" |
---|
496 | case "$2" in |
---|
497 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
498 | TARGETDIR=$(ogGetParentPath "$2") |
---|
499 | ARG=2 |
---|
500 | ;; |
---|
501 | [1-9]*) # ndisco npartición. |
---|
502 | TARGETDIR=$(ogGetParentPath "$2" "$3" "$4") |
---|
503 | ARG=4 |
---|
504 | ;; |
---|
505 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
506 | TARGETDIR=$(ogGetParentPath "$2" "$3") |
---|
507 | ARG=3 |
---|
508 | ;; |
---|
509 | esac |
---|
510 | |
---|
511 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
512 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
513 | |
---|
514 | #obtenemos el nombre del fichero a descargar. |
---|
515 | TARGETFILE=`basename ${!ARG}` |
---|
516 | |
---|
517 | #generamos la instrucción a ejecutar. |
---|
518 | COMMAND=`ogMcastSyntax RECEIVERFILE "$1" $TARGETDIR/$TARGETFILE ` |
---|
519 | RETVAL=$? |
---|
520 | |
---|
521 | if [ "$RETVAL" -gt "0" ] |
---|
522 | then |
---|
523 | return $RETVAL |
---|
524 | else |
---|
525 | echo $COMMAND |
---|
526 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTRECEIVERFILE " "; return $? |
---|
527 | #[ -s "$LOGFILE" ] || return 21 |
---|
528 | fi |
---|
529 | } |
---|
530 | |
---|
531 | #/** |
---|
532 | # ogMcastSendPartition |
---|
533 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas. |
---|
534 | #@param 1 disk |
---|
535 | #@param 2 partition |
---|
536 | #@param 3 session multicast |
---|
537 | #@param 4 tool clone |
---|
538 | #@param 5 tool compressor |
---|
539 | #@return |
---|
540 | #@exception OG_ERR_FORMAT |
---|
541 | #@exception OG_ERR_MCASTSENDPARTITION |
---|
542 | #@note |
---|
543 | #@todo: ogIsLocked siempre devuelve 1. crear ticket |
---|
544 | #@version 1.0 - Definición de Protocol.lib |
---|
545 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
546 | #@date 2010/05/09 |
---|
547 | #*/ ## |
---|
548 | |
---|
549 | function ogMcastSendPartition () |
---|
550 | { |
---|
551 | |
---|
552 | # Variables locales |
---|
553 | local PART COMMAND RETVAL |
---|
554 | |
---|
555 | # Si se solicita, mostrar ayuda. |
---|
556 | if [ "$*" == "help" ]; then |
---|
557 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastSERVER tools compresor" \ |
---|
558 | "$FUNCNAME 1 1 9000:full-duplex:239.194.37.31:50M:20:2 partclone lzop" |
---|
559 | return |
---|
560 | fi |
---|
561 | # Error si no se reciben 5 parámetros. |
---|
562 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
563 | #chequeamos la particion. |
---|
564 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
565 | |
---|
566 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
567 | ogUnmount $1 $2 |
---|
568 | |
---|
569 | #generamos la instrucción a ejecutar. |
---|
570 | COMMAND=`ogMcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
571 | RETVAL=$? |
---|
572 | |
---|
573 | if [ "$RETVAL" -gt "0" ] |
---|
574 | then |
---|
575 | return $RETVAL |
---|
576 | else |
---|
577 | echo $COMMAND |
---|
578 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDPARTITION " "; return $? |
---|
579 | fi |
---|
580 | |
---|
581 | |
---|
582 | } |
---|
583 | |
---|
584 | #/** |
---|
585 | # ogMcastReceiverPartition |
---|
586 | #@brief Función para recibir directamente en la partición el contenido de un fichero imagen remoto enviado por multicast. |
---|
587 | #@param 1 disk |
---|
588 | #@param 2 partition |
---|
589 | #@param 3 session multicast |
---|
590 | #@param 4 tool clone |
---|
591 | #@param 5 tool compressor |
---|
592 | #@return |
---|
593 | #@exception $OG_ERR_FORMAT |
---|
594 | #@note |
---|
595 | #@todo: |
---|
596 | #@version 1.0 - Definición de Protocol.lib |
---|
597 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
598 | #@date 2010/05/09 |
---|
599 | #*/ ## |
---|
600 | function ogMcastReceiverPartition () |
---|
601 | { |
---|
602 | # Variables locales |
---|
603 | local PART COMMAND RETVAL |
---|
604 | |
---|
605 | # Si se solicita, mostrar ayuda. |
---|
606 | if [ "$*" == "help" ]; then |
---|
607 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastCLIENT tools compresor" \ |
---|
608 | "$FUNCNAME 1 1 9000 partclone lzop" |
---|
609 | return |
---|
610 | fi |
---|
611 | # Error si no se reciben 5 parámetros. |
---|
612 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
613 | #chequeamos la particion. |
---|
614 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
615 | |
---|
616 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
617 | ogUnmount $1 $2 |
---|
618 | |
---|
619 | #generamos la instrucción a ejecutar. |
---|
620 | COMMAND=`ogMcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
621 | RETVAL=$? |
---|
622 | |
---|
623 | if [ "$RETVAL" -gt "0" ] |
---|
624 | then |
---|
625 | return $RETVAL |
---|
626 | else |
---|
627 | echo $COMMAND |
---|
628 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDPARTITION " "; return $? |
---|
629 | fi |
---|
630 | |
---|
631 | } |
---|
632 | |
---|
633 | |
---|
634 | ########################################## |
---|
635 | ############## funciones torrent |
---|
636 | #/** |
---|
637 | # ogTorrentStart [ str_repo | int_ndisk int_npart ] Relative_path_file.torrent | SessionProtocol |
---|
638 | #@brief Función iniciar P2P - requiere un tracker para todos los modos, y un seeder para los modos peer y leecher y los ficheros .torrent. |
---|
639 | #@param str_pathDirectory str_Relative_path_file |
---|
640 | #@param int_disk int_partition str_Relative_path_file |
---|
641 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
642 | #@param (2 parámetros) $1 path_aboluto_fichero_torrent $2 Parametros_Session_Torrent |
---|
643 | #@param (3 parámetros) $1 Contenedor CACHE $2 path_absoluto_fichero_Torrent $3 Parametros_Session_Torrent |
---|
644 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero_Torrent 4$ Parametros_Session_Torrent |
---|
645 | |
---|
646 | #@return |
---|
647 | #@note |
---|
648 | #@todo: |
---|
649 | #@version 0.1 - Integración para OpenGNSys. |
---|
650 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
651 | #@date |
---|
652 | #@version 0.2 - Chequeo del tamaño de imagen descargado. |
---|
653 | #@author Irina . Univesidad de Sevilla. |
---|
654 | #@date |
---|
655 | #@version 0.3 - Control de los modos de operación, y estado de descarga. |
---|
656 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
657 | #@date |
---|
658 | #@version 0.4 - Enviadando señal (2) a ctorrent permiendo la comunicación final con tracker |
---|
659 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
660 | #@date |
---|
661 | #*/ ## |
---|
662 | |
---|
663 | #protocoloTORRENT mode:time |
---|
664 | #mode=seeder -> Dejar el equipo seedeando hasta que transcurra el tiempo indicado o un kill desde consola, |
---|
665 | #mode=peer -> seedear mientras descarga |
---|
666 | #mode=leecher -> NO seedear mientras descarga |
---|
667 | #time tiempo que una vez descargada la imagen queremos dejar al cliente como seeder. |
---|
668 | |
---|
669 | function ogTorrentStart () |
---|
670 | { |
---|
671 | |
---|
672 | # Variables locales. |
---|
673 | local ARGS ARG TARGETDIR TARGETFILE SESSION ERROR |
---|
674 | ERROR=0 |
---|
675 | |
---|
676 | # Si se solicita, mostrar ayuda. |
---|
677 | if [ "$*" == "help" ]; then |
---|
678 | ogHelp "$FUNCNAME $FUNCNAME [ str_repo] [ [Relative_path_fileTORRENT] | [str_REPOSITORY path_fileTORRENT] | [int_ndisk int_npart path_fileTORRENT ] ] SessionTorrent" \ |
---|
679 | "$FUNCNAME CACHE /PS1_PH1.img.torrent seeder:10000" \ |
---|
680 | "$FUNCNAME /opt/opengnsys/cache/linux.iso peer:60" \ |
---|
681 | "$FUNCNAME 1 1 /linux.iso.torrent leecher:60" |
---|
682 | return |
---|
683 | fi |
---|
684 | |
---|
685 | case "$1" in |
---|
686 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
687 | SOURCE=$(ogGetPath "$1") |
---|
688 | ARG=2 |
---|
689 | ;; |
---|
690 | [1-9]*) # ndisco npartición. |
---|
691 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
692 | ARG=4 |
---|
693 | ;; |
---|
694 | *) # Otros: Solo cache (no se permiten caminos relativos). |
---|
695 | SOURCE=$(ogGetPath "$1" "$2" 2>/dev/null) |
---|
696 | ARG=3 |
---|
697 | ;; |
---|
698 | esac |
---|
699 | |
---|
700 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
701 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
702 | |
---|
703 | #controlar source, que no se haga al repo. |
---|
704 | if [ $ARG == "3" ] |
---|
705 | then |
---|
706 | ogCheckStringInGroup "$1" "CACHE cache" || ogRaiseError $OG_ERR_FORMAT "La descarga torrent solo se hace desde local, copia el torrent a la cache y realiza la operación desde esa ubicación" || return $? |
---|
707 | fi |
---|
708 | if [ $ARG == "2" ] |
---|
709 | then |
---|
710 | if `ogCheckStringInReg "$1" "^/opt/opengnsys/images"` |
---|
711 | then |
---|
712 | ogRaiseError $OG_ERR_FORMAT "La descarga torrent solo se hace desde local, copia el torrent a la cache y realiza la operación desde esa ubicación" |
---|
713 | return $? |
---|
714 | fi |
---|
715 | fi |
---|
716 | |
---|
717 | #controlar el source, para que sea un torrent. |
---|
718 | ctorrent -x ${SOURCE} &> /dev/null; [ $? -eq 0 ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $? |
---|
719 | |
---|
720 | TARGET=`echo $SOURCE | awk -F.torrent '{print $1}'` |
---|
721 | DIRSOURCE=`ogGetParentPath $SOURCE` |
---|
722 | cd $DIRSOURCE |
---|
723 | |
---|
724 | |
---|
725 | |
---|
726 | SESSION=${!ARG} |
---|
727 | OIFS=$IFS; IFS=':' ; SESSION=($SESSION); IFS=$OIFS |
---|
728 | [[ ${#SESSION[*]} == 2 ]] || ogRaiseError $OG_ERR_FORMAT "parametros session Torrent no completa: modo:tiempo" || ERROR=1# return $? |
---|
729 | #controlamos el modo de operación del cliente- |
---|
730 | ogCheckStringInGroup ${SESSION[0]} "seeder SEEDER peer PEER leecher LEECHER" || ogRaiseError $OG_ERR_FORMAT "valor modo Torrent no valido ${SESSION[0]}" || ERROR=1 #return $? |
---|
731 | MODE=${SESSION[0]} |
---|
732 | #contolamos el tiempo para el seeder o una vez descargada la imagen como peer o leecher. |
---|
733 | ogCheckStringInReg ${SESSION[1]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "valor tiempo no valido ${SESSION[1]}" || ERROR=1 # return $? |
---|
734 | TIME=${SESSION[1]} |
---|
735 | # si ha habido error en el control de parametros error. |
---|
736 | [ "$ERROR" == "1" ] && return 1 |
---|
737 | |
---|
738 | |
---|
739 | #SYNTAXSEEDER="echo MODE seeder ctorrent ; (sleep \$TIME && kill -9 \`pidof ctorrent\`) & ; ctorrent \${SOURCE}" |
---|
740 | |
---|
741 | # si No fichero .bf, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial. |
---|
742 | if [ ! -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
743 | then |
---|
744 | echo "imagen ya descargada" |
---|
745 | case "$MODE" in |
---|
746 | seeder|SEEDER) |
---|
747 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
748 | (sleep $TIME && kill -2 `pidof ctorrent`) & |
---|
749 | ctorrent -f ${SOURCE} |
---|
750 | esac |
---|
751 | return 0 |
---|
752 | fi |
---|
753 | |
---|
754 | #Si no existe bf ni fichero destino descarga inicial. |
---|
755 | if [ ! -f ${SOURCE}.bf -a ! -f ${TARGET} ] |
---|
756 | then |
---|
757 | OPTION=DOWNLOAD |
---|
758 | echo "descarga inicial" |
---|
759 | fi |
---|
760 | |
---|
761 | # Si fichero bf descarga anterior no completada -. |
---|
762 | if [ -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
763 | then |
---|
764 | echo Continuar con Descargar inicial no terminada. |
---|
765 | OPTION=DOWNLOAD |
---|
766 | fi |
---|
767 | |
---|
768 | if [ "$OPTION" == "DOWNLOAD" ] |
---|
769 | then |
---|
770 | case "$MODE" in |
---|
771 | peer|PEER) |
---|
772 | echo "Donwloading Torrent as peer" ### echo "ctorrent -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100 $SOURCE -s $TARGET -b ${SOURCE}.bf" |
---|
773 | ctorrent -f -X "sleep 15; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bf >> $OGLOGFILE |
---|
774 | ;; |
---|
775 | leecher|LEECHER) |
---|
776 | echo "Donwloading Torrent as leecher" # echo "ctorrent ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100 -U 0" |
---|
777 | ctorrent ${SOURCE} -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 -U 0 |
---|
778 | ;; |
---|
779 | seeder|SEEDER) |
---|
780 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
781 | ctorrent -f -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bf |
---|
782 | ;; |
---|
783 | esac |
---|
784 | fi |
---|
785 | cd /tmp |
---|
786 | } |
---|
787 | |
---|
788 | #/** |
---|
789 | # ogCreateTorrent [ str_repo | int_ndisk int_npart ] Relative_path_file |
---|
790 | #@brief Función para crear el fichero torrent. |
---|
791 | #@param str_pathDirectory str_Relative_path_file |
---|
792 | #@param int_disk int_partition str_Relative_path_file |
---|
793 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
794 | #@return |
---|
795 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
796 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
797 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
798 | #@exception OG_ERR_NOTOS La partición no tiene instalado un sistema operativo. |
---|
799 | #@note |
---|
800 | #@version 0.1 - Integración para OpenGNSys. |
---|
801 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
802 | #@date |
---|
803 | #@version 0.2 - Integración para btlaunch. |
---|
804 | #@author Irina . Univesidad de Sevilla. |
---|
805 | #@date |
---|
806 | #*/ ## |
---|
807 | |
---|
808 | function ogCreateTorrent () |
---|
809 | { |
---|
810 | # Variables locales. |
---|
811 | local ARGS ARG SOURCE EXT IPTORRENT |
---|
812 | |
---|
813 | |
---|
814 | # Si se solicita, mostrar ayuda. |
---|
815 | if [ "$*" == "help" ]; then |
---|
816 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file IpBttrack" \ "$FUNCNAME 1 1 /aula1/winxp 10.1.15.23" \ |
---|
817 | "$FUNCNAME REPO /aula1/winxp 10.1.15.45" |
---|
818 | |
---|
819 | return |
---|
820 | fi |
---|
821 | |
---|
822 | # Error si se quiere crear el fichero en cache y no existe |
---|
823 | [ "$1" != "CACHE" ] || `ogFindCache >/dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE"|| return $? |
---|
824 | |
---|
825 | case "$1" in |
---|
826 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
827 | SOURCE=$(ogGetPath "$1.img") |
---|
828 | ARG=2 |
---|
829 | ;; |
---|
830 | [1-9]*) # ndisco npartición. |
---|
831 | SOURCE=$(ogGetPath "$1" "$2" "$3.img") |
---|
832 | ARG=4 |
---|
833 | ;; |
---|
834 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
835 | EXT=$(ogGetImageType "$1" "$2") |
---|
836 | SOURCE=$(ogGetPath "$1" "$2.$EXT") |
---|
837 | ARG=3 |
---|
838 | ;; |
---|
839 | esac |
---|
840 | |
---|
841 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
842 | [ $# -eq "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
843 | |
---|
844 | |
---|
845 | # Error si no existe la imagen |
---|
846 | [ $SOURCE ] || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
847 | |
---|
848 | [ -r $SOURCE.torrent ] && mv "$SOURCE.torrent" "$SOURCE.torrent.ant" && echo "Esperamos que se refresque el servidor" && sleep 20 |
---|
849 | |
---|
850 | IPTORRENT="${!#}" |
---|
851 | # Si ponemos el path completo cuando creamos el fichero torrent da error |
---|
852 | cd `dirname $SOURCE` |
---|
853 | echo ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
854 | ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
855 | |
---|
856 | } |
---|
857 | |
---|
858 | |
---|
859 | #/** |
---|
860 | # ogUpdateCacheIsNecesary [ str_repo ] Relative_path_file_OGIMG_with_/ |
---|
861 | #@brief Comprueba que el fichero que se desea almacenar en la cache del cliente, no esta. |
---|
862 | #@param 1 str_REPO |
---|
863 | #@param 2 str_Relative_path_file_OGIMG_with_/ |
---|
864 | #@return 0 si es necesario actualizar el fichero. |
---|
865 | #@return 1 si la imagen ya esta en la cache, por lo tanto no es necesario actualizar el fichero |
---|
866 | #@note |
---|
867 | #@todo: Proceso en el caso de que el fichero tenga el mismo nombre, pero su contenido sea distinto. |
---|
868 | #@todo: Se dejan mensajes mientras se confirma su funcionamiento. |
---|
869 | #@version 0.1 - Integracion para OpenGNSys. |
---|
870 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
871 | #@date |
---|
872 | #*/ ## |
---|
873 | function ogUpdateCacheIsNecesary () |
---|
874 | { |
---|
875 | |
---|
876 | # Variables locales. |
---|
877 | local ERROR SOURCE CACHE FILESOURCE MD5SOURCE FILETARGET MD5TARGET |
---|
878 | ERROR=0 |
---|
879 | |
---|
880 | # Si se solicita, mostrar ayuda. |
---|
881 | if [ "$*" == "help" ]; then |
---|
882 | ogHelp "$FUNCNAME $FUNCNAME [ str_repo] [ [Relative_path_image] " \ |
---|
883 | "$FUNCNAME REPO /PS1_PH1.img" \ |
---|
884 | "$FUNCNAME REPO /ogclient.sqfs" |
---|
885 | |
---|
886 | return |
---|
887 | fi |
---|
888 | |
---|
889 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
890 | [ $# == "2" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
891 | |
---|
892 | |
---|
893 | ogCheckStringInGroup "$1" "REPO repo" || ogRaiseError $OG_ERR_FORMAT "El contendor $1 no es valido, solo se admite REPO" || return $? |
---|
894 | |
---|
895 | FILESOURCE=`ogGetPath $1 $2` |
---|
896 | FILETARGET=`ogGetPath CACHE $2` |
---|
897 | |
---|
898 | echo "paso 1. si no existe la imagen, confirmamos que es necesaria la actualizacion de la cache." |
---|
899 | if [ -z $FILETARGET ] |
---|
900 | then |
---|
901 | # borramos el fichero bf del torrent, en el caso de que se hubiese quedado de algun proceso fallido |
---|
902 | ogDeleteFile CACHE /$2.torrent.bf &> /dev/null |
---|
903 | ogDeleteFile CACHE /$2.sum &> /dev/null |
---|
904 | echo "Salida con valor 0, paso 1, la cache no contiene esa imagen " |
---|
905 | return 0 |
---|
906 | fi |
---|
907 | echo "Paso 2. Comprobamos que la imagen no estuviese en un proceso previo torrent" |
---|
908 | if ogGetPath $FILETARGET.torrent.bf > /dev/null |
---|
909 | then |
---|
910 | echo "Salida con valor 0, paso 2 la imagen esta en un estado de descarga torrent interrumpido." |
---|
911 | #TODO: comprobar los md5 para asegurarnos que la imagen es la misma. |
---|
912 | return 0 |
---|
913 | fi |
---|
914 | |
---|
915 | ## En este punto la imagen en el repo y en la cache se llaman igual, |
---|
916 | echo "paso 4. recuperamos o calculamos los md5 de los ficheros" |
---|
917 | if [ -f $FILESOURCE.sum ] |
---|
918 | then |
---|
919 | echo "leyendo el sum del fichero sum del repo" |
---|
920 | MD5SOURCE=$(cat $FILESOURCE.sum) |
---|
921 | #elif [ -f $FILETARGET.torrent ] |
---|
922 | #then |
---|
923 | # echo "leyendo el sum del fichero torrent de la cache" |
---|
924 | # MD5SOURCE=$(ctorrent -x $FILETARGET.torrent | grep Comment | awk -F": " '{print $2}') |
---|
925 | else |
---|
926 | echo "calculando el sun del repo" |
---|
927 | MD5SOURCE=$(md5sum $FILESOURCE | cut -f1 -d" ") |
---|
928 | fi |
---|
929 | if [ -f $FILETARGET.sum ] |
---|
930 | then |
---|
931 | echo "leyendo el sum de la cache" |
---|
932 | MD5TARGET=$(cat $FILETARGET.sum) |
---|
933 | else |
---|
934 | echo "calculando el sum de la cache" |
---|
935 | md5sum $FILETARGET | cut -f1 -d" " > $FILETARGET.sum |
---|
936 | MD5TARGET=$(cat $FILETARGET.sum) |
---|
937 | fi |
---|
938 | |
---|
939 | echo "Paso 5. comparamos los md5" |
---|
940 | #TODO: que hacer cuando los md5 son distintos. Por defecto borrar. |
---|
941 | if [ "$MD5SOURCE" == "$MD5TARGET" ] |
---|
942 | then |
---|
943 | echo "paso5.A la imagen esta en cache" |
---|
944 | return 1 |
---|
945 | else |
---|
946 | echo "paso 5.b la imagen en cache es distinta, borramos la imagen anterior y devolvemos 0 para confirmar la actualizacion" |
---|
947 | rm $FILETARGET |
---|
948 | return 0 |
---|
949 | fi |
---|
950 | |
---|
951 | } |
---|
952 | |
---|
953 | |
---|
954 | |
---|