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