[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 | |
---|
| 11 | |
---|
[bd390f1] | 12 | #/** |
---|
| 13 | # ogCheckStringInGroup |
---|
| 14 | #@brief Función para determinar si el elemento pertenece a un conjunto |
---|
| 15 | #@param 1 elemento a comprobar |
---|
| 16 | #@param 2 grupo de elementos para comprobar tipo "valor1 valor2 valor3" |
---|
| 17 | #@return 0 si pertenece al grupo |
---|
| 18 | #@return 1 si NO pertenece al grupo |
---|
| 19 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 20 | #@note |
---|
[0fbc05e] | 21 | #@todo |
---|
[bd390f1] | 22 | #@version 0.91 - Definición de |
---|
| 23 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 24 | #@date 2010/05/09 |
---|
| 25 | #*/ ## |
---|
| 26 | #/** |
---|
| 27 | ogCheckStringInGroup () |
---|
| 28 | { |
---|
| 29 | # Si se solicita, mostrar ayuda. |
---|
| 30 | if [ "$*" == "help" ]; then |
---|
| 31 | ogHelp "$FUNCNAME str_elemento str_grupo" \ |
---|
| 32 | "$FUNCNAME full-duplex \"full-duplex half-duplex broadcast\" " |
---|
| 33 | return |
---|
| 34 | fi |
---|
| 35 | |
---|
| 36 | # Error si no se recibe 2 parámetro. |
---|
| 37 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | for i in `echo $2` |
---|
| 41 | do |
---|
| 42 | if [ "$1" == "$i" ] |
---|
| 43 | then |
---|
| 44 | return 0 |
---|
| 45 | fi |
---|
| 46 | done |
---|
| 47 | |
---|
| 48 | return 1 |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | #/** |
---|
| 52 | # ogCheckStringInReg |
---|
| 53 | #@brief Función para determinar si el elemento contiene una "expresión regular" |
---|
| 54 | #@param 1 elemento a comprobar |
---|
| 55 | #@param 2 expresión regular" |
---|
| 56 | #@return 0 si coincide con la expresión |
---|
| 57 | #@return 1 si NO coincide con la expresión |
---|
| 58 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 59 | #@note |
---|
[0fbc05e] | 60 | #@todo |
---|
[bd390f1] | 61 | #@version 0.91 - Definición de |
---|
| 62 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 63 | #@date 2010/05/09 |
---|
| 64 | #*/ ## |
---|
| 65 | #/** |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | ogCheckStringInReg() |
---|
| 69 | { |
---|
| 70 | |
---|
| 71 | local REG |
---|
| 72 | |
---|
| 73 | # Si se solicita, mostrar ayuda. |
---|
| 74 | if [ "$*" == "help" ]; then |
---|
| 75 | ogHelp "$FUNCNAME str_elemento str_expresión_regular" \ |
---|
| 76 | "$FUNCNAME 50M \"^[0-9]{1,2}\M$\" " |
---|
| 77 | return |
---|
| 78 | fi |
---|
| 79 | |
---|
| 80 | # Error si no se recibe 2 parámetro. |
---|
| 81 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 82 | |
---|
| 83 | REG=$2 |
---|
| 84 | [[ $1 =~ $REG ]] && return 0 || return 1 |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | #/** |
---|
| 90 | # ogCheckIpAddress |
---|
| 91 | #@brief Función para determinar si una cadena es una dirección ipv4 válida |
---|
| 92 | #@param 1 string de la ip a comprobar |
---|
| 93 | #@return 0 si es una dirección válida |
---|
| 94 | #@return 1 si NO es una dirección válida |
---|
| 95 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 96 | #@note |
---|
[0fbc05e] | 97 | #@todo |
---|
[bd390f1] | 98 | #@version 0.91 - Definición de |
---|
| 99 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 100 | #@date 2010/05/09 |
---|
| 101 | #*/ ## |
---|
| 102 | #/** |
---|
| 103 | ogCheckIpAddress() |
---|
| 104 | { |
---|
| 105 | local REG IP arrIP |
---|
| 106 | |
---|
| 107 | # Si se solicita, mostrar ayuda. |
---|
| 108 | if [ "$*" == "help" ]; then |
---|
| 109 | ogHelp "$FUNCNAME str_IpAddressToCheck" \ |
---|
| 110 | "$FUNCNAME 192.18.35.3" |
---|
| 111 | return |
---|
| 112 | fi |
---|
| 113 | |
---|
| 114 | # Error si no se recibe 1 parámetro. |
---|
| 115 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | IP=$1 |
---|
| 119 | REG="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" |
---|
| 120 | if [[ "$IP" =~ $REG ]] |
---|
| 121 | then |
---|
| 122 | OIFS=$IFS; |
---|
| 123 | IFS='.' ; |
---|
| 124 | arrIP=($IP) |
---|
| 125 | IFS=$OIFS |
---|
| 126 | if [[ ${arrIP[0]} -le 255 && ${arrIP[1]} -le 255 && ${arrIP[2]} -le 255 && ${arrIP[3]} -le 255 ]] |
---|
| 127 | then |
---|
| 128 | return 0 |
---|
| 129 | fi |
---|
| 130 | fi |
---|
| 131 | return 1 |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
[884ea85] | 135 | |
---|
| 136 | #/** |
---|
[761960be] | 137 | # ogMcastSyntax |
---|
[bd390f1] | 138 | #@brief Función para generar la instrucción de ejucción la transferencia de datos multicast |
---|
| 139 | #@param 1 Tipo de operación [ SENDPARTITION RECEIVERPARTITION SENDFILE RECEIVERFILE ] |
---|
| 140 | #@param 2 Sesión Mulicast |
---|
| 141 | #@param 3 Dispositivo (opción PARTITION) o fichero(opción FILE) que será enviado. |
---|
[884ea85] | 142 | #@param 4 Tools de clonación (opcion PARTITION) |
---|
| 143 | #@param 5 Tools de compresion (opcion PARTITION) |
---|
| 144 | #@return instrucción para ser ejecutada. |
---|
| 145 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[bd390f1] | 146 | #@note Requisitos: upd-cast 2009 |
---|
[0fbc05e] | 147 | #@todo localvar check versionudp |
---|
[884ea85] | 148 | #@version 0.91 - Definición de FileTransfer |
---|
| 149 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 150 | #@date 2010/05/09 |
---|
| 151 | #*/ ## |
---|
| 152 | #/** |
---|
| 153 | # |
---|
| 154 | |
---|
| 155 | |
---|
[761960be] | 156 | function ogMcastSyntax () |
---|
[884ea85] | 157 | { |
---|
[bd390f1] | 158 | |
---|
[59e3998] | 159 | local ISUDPCAST PARM SESSION SESSIONPARM MODE PORTBASE PERROR |
---|
[bd390f1] | 160 | local METHOD ADDRESS BITRATE NCLIENTS MAXTIME CERROR |
---|
[761960be] | 161 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
[bd390f1] | 162 | |
---|
[884ea85] | 163 | # Si se solicita, mostrar ayuda. |
---|
| 164 | if [ "$*" == "help" -o "$2" == "help" ]; then |
---|
| 165 | ogHelp "$FUNCNAME SENDPARTITION str_sessionSERVER str_device str_tools str_level" \ |
---|
| 166 | "$FUNCNAME RECEIVERPARTITION str_sessionCLIENT str_device str_tools str_level "\ |
---|
| 167 | "$FUNCNAME SENDFILE str_sessionSERVER str_file "\ |
---|
[e8df652] | 168 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
[fa43c91] | 169 | "sessionServer syntax: portbase:method:mcastaddress:speed:nclients:ntimeWaitingUntilNclients " \ |
---|
| 170 | "sessionServer example: 9000:full-duplex|half-duplex|broadcast:239.194.17.36:80M:50:60 " \ |
---|
[0fbc05e] | 171 | "sessionClient syntax: portbase " \ |
---|
| 172 | "sessionClient example: 9000 " |
---|
[884ea85] | 173 | return |
---|
| 174 | fi |
---|
[59e3998] | 175 | PERROR=0 |
---|
[884ea85] | 176 | |
---|
[bd390f1] | 177 | #si no tenemos updcast o su version superior 2009 udpcast error. |
---|
| 178 | ISUDPCAST=$(udp-receiver --help 2>&1) |
---|
| 179 | echo $ISUDPCAST | grep start-timeout > /dev/null || ogRaiseError $OG_ERR_FORMAT "upd-cast no existe o version antigua -requerida 2009-"|| return $? |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | # Error si no se reciben $PARM parámetros. |
---|
| 183 | echo "$1" | grep "PARTITION" > /dev/null && PARM=5 || PARM=3 |
---|
| 184 | [ "$#" -eq "$PARM" ] || ogRaiseError $OG_ERR_FORMAT "sin parametros"|| return $? |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | # 1er param check |
---|
[59e3998] | 188 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
[bd390f1] | 189 | |
---|
| 190 | # 2º param check |
---|
| 191 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
| 192 | |
---|
[59e3998] | 193 | #TODO: diferenciamos los paramatros especificos de la sessión multicast |
---|
| 194 | #SI: controlamos todos los parametros de la sessión multicast. |
---|
[56d2d6f] | 195 | [ $MODE == "client" ] && SESSIONPARM=1 || SESSIONPARM=6 |
---|
[bd390f1] | 196 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
[59e3998] | 197 | |
---|
| 198 | |
---|
| 199 | [[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
| 200 | |
---|
| 201 | |
---|
[bd390f1] | 202 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
| 203 | PORTBASE=${SESSION[0]} |
---|
[59e3998] | 204 | ogCheckStringInGroup ${SESSION[0]} "9000 9002 9004 9006 9008 9010" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
[bd390f1] | 205 | if [ $MODE == "server" ] |
---|
| 206 | then |
---|
[59e3998] | 207 | 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] | 208 | METHOD=${SESSION[1]} |
---|
[59e3998] | 209 | ogCheckIpAddress ${SESSION[2]} || ogRaiseError $OG_ERR_FORMAT "McastSession address ${SESSION[2]}" || PERROR=5 #return $? |
---|
[bd390f1] | 210 | ADDRESS=${SESSION[2]} |
---|
[59e3998] | 211 | ogCheckStringInReg ${SESSION[3]} "^[0-9]{1,2}\M$" || ogRaiseError $OG_ERR_FORMAT "McastSession bitrate ${SESSION[3]}" || PERROR=6 # return $? |
---|
[bd390f1] | 212 | BITRATE=${SESSION[3]} |
---|
[59e3998] | 213 | ogCheckStringInReg ${SESSION[4]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession nclients ${SESSION[4]}" || PERROR=7 # return $? |
---|
[bd390f1] | 214 | NCLIENTS=${SESSION[4]} |
---|
[59e3998] | 215 | ogCheckStringInReg ${SESSION[5]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession maxtime ${SESSION[5]}" || PERROR=8 # return $? |
---|
[bd390f1] | 216 | MAXTIME=${SESSION[5]} |
---|
| 217 | fi |
---|
[884ea85] | 218 | |
---|
[bd390f1] | 219 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
[59e3998] | 220 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
[bd390f1] | 221 | DEVICE=$3 |
---|
| 222 | |
---|
| 223 | #4 y 5 param check . solo si es sobre particiones. |
---|
| 224 | if [ "$PARM" == "5" ] |
---|
| 225 | then |
---|
| 226 | # 4 param check |
---|
[59e3998] | 227 | ogCheckStringInGroup "$4" "partclone partimage ntfsclone" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
[bd390f1] | 228 | TOOL=$4 |
---|
[59e3998] | 229 | ogCheckStringInGroup "$5" "lzop gzip 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
[bd390f1] | 230 | LEVEL=$5 |
---|
| 231 | fi |
---|
| 232 | |
---|
[59e3998] | 233 | |
---|
| 234 | [ "$PERROR" -gt "0" ] && return 1 |
---|
[bd390f1] | 235 | |
---|
| 236 | # Valores estandar no configurables. |
---|
| 237 | CERROR="8x8/128" |
---|
[884ea85] | 238 | |
---|
| 239 | # opción del usuo de tuberia intermedia en memoria mbuffer. |
---|
[fa43c91] | 240 | which mbuffer > /dev/null && MBUFFER=" --pipe 'mbuffer -q -m 20M' " |
---|
[884ea85] | 241 | |
---|
| 242 | # Generamos la instrucción base de multicast -Envio,Recepcion- |
---|
[fa43c91] | 243 | 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] | 244 | SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE " |
---|
[884ea85] | 245 | |
---|
| 246 | |
---|
| 247 | case "$1" in |
---|
[59e3998] | 248 | SENDPARTITION) |
---|
[761960be] | 249 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
| 250 | echo "$PROG1 | $SYNTAXSERVER" |
---|
[884ea85] | 251 | ;; |
---|
| 252 | RECEIVERPARTITION) |
---|
[761960be] | 253 | COMPRESSOR=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $1}'` |
---|
| 254 | TOOLS=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $NF}'` |
---|
| 255 | echo "$SYNTAXCLIENT | $COMPRESSOR | $TOOLS " |
---|
[884ea85] | 256 | ;; |
---|
| 257 | SENDFILE) |
---|
[761960be] | 258 | echo "$SYNTAXSERVER --file $3" |
---|
[884ea85] | 259 | ;; |
---|
| 260 | RECEIVERFILE) |
---|
[761960be] | 261 | echo "$SYNTAXCLIENT --file $3" |
---|
[884ea85] | 262 | ;; |
---|
| 263 | *) |
---|
| 264 | ;; |
---|
| 265 | esac |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | #/** |
---|
| 271 | # ogMcastSendFile [ str_repo | int_ndisk int_npart ] /Relative_path_file sessionMulticast |
---|
| 272 | #@brief Envía un fichero por multicast ORIGEN(fichero) DESTINO(sessionmulticast) |
---|
| 273 | #@param (2 parámetros) $1 path_aboluto_fichero $2 sesionMcast |
---|
| 274 | #@param (3 parámetros) $1 Contenedor REPO|CACHE $2 path_absoluto_fichero $3 sesionMulticast |
---|
| 275 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero $4 sesionMulticast |
---|
| 276 | #@return |
---|
| 277 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 278 | #@note Requisitos: |
---|
[bd390f1] | 279 | #@version 0.91 - Definición de Protocol.lib |
---|
[884ea85] | 280 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 281 | #@date 2010/05/09 |
---|
| 282 | #*/ ## |
---|
| 283 | #/** |
---|
| 284 | # |
---|
| 285 | |
---|
| 286 | function ogMcastSendFile () |
---|
| 287 | { |
---|
| 288 | # Variables locales. |
---|
[bd390f1] | 289 | local ARGS SOURCE TARGET COMMAND DEVICE |
---|
[884ea85] | 290 | #ARGS usado para controlar ubicación de la sesion multicast |
---|
| 291 | |
---|
| 292 | # Si se solicita, mostrar ayuda. |
---|
| 293 | if [ "$*" == "help" ]; then |
---|
| 294 | ogHelp "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast" \ |
---|
| 295 | "$FUNCNAME 1 1 /aula1/winxp.img sesionMcast" \ |
---|
| 296 | "$FUNCNAME REPO /aula1/ubuntu.iso sesionMcast" \ |
---|
| 297 | "$FUNCNAME CACHE /aula1/winxp.img sesionMcast" \ |
---|
| 298 | "$FUNCNAME /opt/opengnsys/images/aula1/hd500.vmx sesionMcast" |
---|
| 299 | return |
---|
| 300 | fi |
---|
| 301 | |
---|
| 302 | ARGS="$@" |
---|
| 303 | case "$1" in |
---|
[bd390f1] | 304 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
[884ea85] | 305 | SOURCE=$(ogGetPath "$1") |
---|
[bd390f1] | 306 | ARG=2 |
---|
| 307 | DEVICE="$1" |
---|
[884ea85] | 308 | ;; |
---|
| 309 | [1-9]*) # ndisco npartición. |
---|
| 310 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
| 311 | ARG=4 |
---|
[bd390f1] | 312 | DEVICE="$1 $2 $3" |
---|
[884ea85] | 313 | ;; |
---|
| 314 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 315 | SOURCE=$(ogGetPath "$1" "$2") |
---|
| 316 | ARG=3 |
---|
[bd390f1] | 317 | DEVICE="$1 $2 " |
---|
[884ea85] | 318 | ;; |
---|
| 319 | esac |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 323 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[884ea85] | 324 | |
---|
| 325 | # Comprobar fichero origen |
---|
[bd390f1] | 326 | ogGetPath $SOURCE &> /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $DEVICE not found" || return $? |
---|
[884ea85] | 327 | |
---|
| 328 | SESSION=${!ARG} |
---|
| 329 | # llamando a la funcion con param1 session $SESSION y param2 $SOURCE |
---|
[761960be] | 330 | COMMAND=`ogMcastSyntax "SENDFILE" "$SESSION" "$SOURCE"` |
---|
[884ea85] | 331 | echo $COMMAND |
---|
| 332 | eval $COMMAND |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | #/** |
---|
| 338 | # ogMcastReceiverFile sesion Multicast [ str_repo | int_ndisk int_npart ] /Relative_path_file |
---|
| 339 | #@brief Recibe un fichero multicast ORIGEN(sesionmulticast) DESTINO(fichero) |
---|
| 340 | #@param (2 parámetros) $1 sesionMcastCLIENT $2 path_aboluto_fichero_destino |
---|
| 341 | #@param (3 parámetros) $1 sesionMcastCLIENT $2 Contenedor REPO|CACHE $3 path_absoluto_fichero_destino |
---|
| 342 | #@param (4 parámetros) $1 sesionMcastCLIENT $2 disk $3 particion $4 path_absoluto_fichero_destino |
---|
| 343 | #@return |
---|
| 344 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 345 | #@note Requisitos: |
---|
[bd390f1] | 346 | #@version 0.91 - Definición de Protocol.lib |
---|
[884ea85] | 347 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 348 | #@date 2010/05/09 |
---|
| 349 | #*/ ## |
---|
| 350 | #/** |
---|
| 351 | # |
---|
| 352 | |
---|
| 353 | ogMcastReceiverFile () |
---|
| 354 | { |
---|
| 355 | |
---|
| 356 | # Variables locales. |
---|
| 357 | local ARGS ARG TARGETDIR TARGETFILE |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | # Si se solicita, mostrar ayuda. |
---|
| 361 | if [ "$*" == "help" ]; then |
---|
| 362 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_portMcast] [ [Relative_path_file] | [str_REPOSITORY path_file] | [int_ndisk int_npart path_file ] ]" \ |
---|
[bd390f1] | 363 | "$FUNCNAME 9000 /PS1_PH1.img" \ |
---|
| 364 | "$FUNCNAME 9000 CACHE /aula1/PS2_PH4.img" \ |
---|
| 365 | "$FUNCNAME 9000 1 1 /isos/linux.iso" |
---|
[884ea85] | 366 | return |
---|
| 367 | fi |
---|
| 368 | |
---|
| 369 | ARGS="$@" |
---|
| 370 | case "$2" in |
---|
| 371 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 372 | TARGETDIR=$(ogGetParentPath "$2") |
---|
[bd390f1] | 373 | ARG=2 |
---|
[884ea85] | 374 | ;; |
---|
| 375 | [1-9]*) # ndisco npartición. |
---|
| 376 | TARGETDIR=$(ogGetParentPath "$2" "$3" "$4") |
---|
[bd390f1] | 377 | ARG=4 |
---|
[884ea85] | 378 | ;; |
---|
| 379 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 380 | TARGETDIR=$(ogGetParentPath "$2" "$3") |
---|
[bd390f1] | 381 | ARG=3 |
---|
[884ea85] | 382 | ;; |
---|
| 383 | esac |
---|
| 384 | |
---|
| 385 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 386 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
[884ea85] | 387 | |
---|
| 388 | #obtenemos el nombre del fichero a descargar. |
---|
| 389 | TARGETFILE=`basename ${!ARG}` |
---|
| 390 | |
---|
| 391 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 392 | COMMAND=`ogMcastSyntax RECEIVERFILE "$1" $TARGETDIR/$TARGETFILE ` |
---|
[e8df652] | 393 | echo $COMMAND |
---|
| 394 | eval $COMMAND |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | #/** |
---|
| 398 | # ogMcastSendPartition |
---|
| 399 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas. |
---|
| 400 | #@param |
---|
| 401 | #@param |
---|
| 402 | #@param |
---|
| 403 | #@return |
---|
| 404 | #@exception |
---|
| 405 | #@note |
---|
| 406 | #@todo: ogIsLocked siempre devuelve 1. crear ticket |
---|
| 407 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 408 | #@author |
---|
| 409 | #@date |
---|
| 410 | #*/ ## |
---|
| 411 | |
---|
| 412 | ogMcastSendPartition () |
---|
| 413 | { |
---|
| 414 | |
---|
| 415 | # Variables locales |
---|
| 416 | local PART COMMAND |
---|
| 417 | |
---|
| 418 | # Si se solicita, mostrar ayuda. |
---|
| 419 | if [ "$*" == "help" ]; then |
---|
| 420 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastSERVER tools compresor" \ |
---|
[fa43c91] | 421 | "$FUNCNAME 1 1 9000:full-duplex:239.194.37.31:50M:20:2 partclone lzop" |
---|
[e8df652] | 422 | return |
---|
| 423 | fi |
---|
| 424 | # Error si no se reciben 5 parámetros. |
---|
| 425 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 426 | #chequeamos la particion. |
---|
| 427 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 428 | |
---|
| 429 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 430 | ogUnmount $1 $2 |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 434 | COMMAND=`ogMcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
[e8df652] | 435 | echo $COMMAND |
---|
| 436 | eval $COMMAND |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | #/** |
---|
| 440 | # ogMcastReceiverPartition |
---|
| 441 | #@brief Función para recibir directamente en la partición el contenido de un fichero imagen remoto enviado por multicast. |
---|
| 442 | #@param |
---|
| 443 | #@param |
---|
| 444 | #@param |
---|
| 445 | #@return |
---|
| 446 | #@exception |
---|
| 447 | #@note |
---|
| 448 | #@todo: |
---|
| 449 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 450 | #@author |
---|
| 451 | #@date |
---|
| 452 | #*/ ## |
---|
| 453 | ogMcastReceiverPartition () |
---|
| 454 | { |
---|
| 455 | # Variables locales |
---|
| 456 | local PART COMMAND |
---|
| 457 | |
---|
| 458 | # Si se solicita, mostrar ayuda. |
---|
| 459 | if [ "$*" == "help" ]; then |
---|
| 460 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastCLIENT tools compresor" \ |
---|
| 461 | "$FUNCNAME 1 1 9000 partclone lzop" |
---|
| 462 | return |
---|
| 463 | fi |
---|
| 464 | # Error si no se reciben 5 parámetros. |
---|
| 465 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 466 | #chequeamos la particion. |
---|
| 467 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 468 | |
---|
| 469 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 470 | ogUnmount $1 $2 |
---|
| 471 | |
---|
| 472 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 473 | COMMAND=`ogMcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
[884ea85] | 474 | echo $COMMAND |
---|
| 475 | eval $COMMAND |
---|
| 476 | } |
---|
| 477 | |
---|
[bd390f1] | 478 | |
---|
| 479 | ########################################## |
---|
[bba08bf] | 480 | ############## funciones torrent |
---|
[884ea85] | 481 | #/** |
---|
[2ab031e5] | 482 | # ogTorrentStart [ str_repo | int_ndisk int_npart ] Relative_path_file.torrent | SessionProtocol |
---|
[1678fa1] | 483 | #@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] | 484 | #@param str_pathDirectory str_Relative_path_file |
---|
| 485 | #@param int_disk int_partition str_Relative_path_file |
---|
| 486 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
[2ab031e5] | 487 | #@param (2 parámetros) $1 path_aboluto_fichero_torrent $2 Parametros_Session_Torrent |
---|
| 488 | #@param (3 parámetros) $1 Contenedor CACHE $2 path_absoluto_fichero_Torrent $3 Parametros_Session_Torrent |
---|
| 489 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero_Torrent 4$ Parametros_Session_Torrent |
---|
| 490 | |
---|
[bba08bf] | 491 | #@return |
---|
| 492 | #@note |
---|
| 493 | #@todo: |
---|
| 494 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 495 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 496 | #@date |
---|
| 497 | #@version 0.2 - Chequeo del tamaño de imagen descargado. |
---|
| 498 | #@author Irina . Univesidad de Sevilla. |
---|
| 499 | #@date |
---|
[1678fa1] | 500 | #@version 0.3 - Control de los modos de operación, y estado de descarga. |
---|
| 501 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
| 502 | #@date |
---|
[2ab031e5] | 503 | #@version 0.4 - Enviadando señal (2) a ctorrent permiendo la comunicación final con tracker |
---|
| 504 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
| 505 | #@date |
---|
[bba08bf] | 506 | #*/ ## |
---|
[2ab031e5] | 507 | |
---|
[1678fa1] | 508 | #protocoloTORRENT mode:time |
---|
| 509 | #mode=seeder -> Dejar el equipo seedeando hasta que transcurra el tiempo indicado o un kill desde consola, |
---|
| 510 | #mode=peer -> seedear mientras descarga |
---|
| 511 | #mode=leecher -> NO seedear mientras descarga |
---|
| 512 | #time tiempo que una vez descargada la imagen queremos dejar al cliente como seeder. |
---|
[bba08bf] | 513 | |
---|
| 514 | ogTorrentStart () |
---|
| 515 | { |
---|
[2ab031e5] | 516 | |
---|
| 517 | # Variables locales. |
---|
| 518 | local ARGS ARG TARGETDIR TARGETFILE SESSION ERROR |
---|
| 519 | ERROR=0 |
---|
| 520 | |
---|
| 521 | # Si se solicita, mostrar ayuda. |
---|
| 522 | if [ "$*" == "help" ]; then |
---|
| 523 | ogHelp "$FUNCNAME $FUNCNAME [ str_repo] [ [Relative_path_fileTORRENT] | [str_REPOSITORY path_fileTORRENT] | [int_ndisk int_npart path_fileTORRENT ] ] SessionTorrent" \ |
---|
| 524 | "$FUNCNAME CACHE /PS1_PH1.img.torrent seeder:10000" \ |
---|
| 525 | "$FUNCNAME /opt/opengnsys/cache/linux.iso peer:60" \ |
---|
| 526 | "$FUNCNAME 1 1 /linux.iso.torrent leecher:60" |
---|
| 527 | return |
---|
| 528 | fi |
---|
[bba08bf] | 529 | |
---|
| 530 | case "$1" in |
---|
| 531 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 532 | SOURCE=$(ogGetPath "$1") |
---|
[2ab031e5] | 533 | ARG=2 |
---|
[bba08bf] | 534 | ;; |
---|
| 535 | [1-9]*) # ndisco npartición. |
---|
| 536 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
[2ab031e5] | 537 | ARG=4 |
---|
[bba08bf] | 538 | ;; |
---|
[2ab031e5] | 539 | *) # Otros: Solo cache (no se permiten caminos relativos). |
---|
[bba08bf] | 540 | SOURCE=$(ogGetPath "$1" "$2" 2>/dev/null) |
---|
[2ab031e5] | 541 | ARG=3 |
---|
| 542 | ;; |
---|
[bba08bf] | 543 | esac |
---|
| 544 | |
---|
[2ab031e5] | 545 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 546 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
| 547 | |
---|
| 548 | #controlar source, que no se haga al repo. |
---|
| 549 | if [ $ARG == "3" ] |
---|
| 550 | then |
---|
| 551 | 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 $? |
---|
| 552 | fi |
---|
| 553 | if [ $ARG == "2" ] |
---|
| 554 | then |
---|
| 555 | if `ogCheckStringInReg "$1" "^/opt/opengnsys/images"` |
---|
| 556 | then |
---|
| 557 | 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" |
---|
| 558 | return $? |
---|
| 559 | fi |
---|
| 560 | fi |
---|
| 561 | |
---|
| 562 | #controlar el source, para que sea un torrent. |
---|
| 563 | ctorrent -x ${SOURCE} &> /dev/null; [ $? -eq 0 ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $? |
---|
[bba08bf] | 564 | |
---|
| 565 | TARGET=`echo $SOURCE | awk -F.torrent '{print $1}'` |
---|
| 566 | DIRSOURCE=`ogGetParentPath $SOURCE` |
---|
| 567 | cd $DIRSOURCE |
---|
| 568 | |
---|
[1678fa1] | 569 | |
---|
[bba08bf] | 570 | |
---|
[2ab031e5] | 571 | SESSION=${!ARG} |
---|
| 572 | OIFS=$IFS; IFS=':' ; SESSION=($SESSION); IFS=$OIFS |
---|
| 573 | [[ ${#SESSION[*]} == 2 ]] || ogRaiseError $OG_ERR_FORMAT "parametros session Torrent no completa: modo:tiempo" || ERROR=1# return $? |
---|
| 574 | #controlamos el modo de operación del cliente- |
---|
| 575 | ogCheckStringInGroup ${SESSION[0]} "seeder SEEDER peer PEER leecher LEECHER" || ogRaiseError $OG_ERR_FORMAT "valor modo Torrent no valido ${SESSION[0]}" || ERROR=1 #return $? |
---|
| 576 | MODE=${SESSION[0]} |
---|
| 577 | #contolamos el tiempo para el seeder o una vez descargada la imagen como peer o leecher. |
---|
| 578 | ogCheckStringInReg ${SESSION[1]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "valor tiempo no valido ${SESSION[1]}" || ERROR=1 # return $? |
---|
| 579 | TIME=${SESSION[1]} |
---|
| 580 | # si ha habido error en el control de parametros error. |
---|
| 581 | [ "$ERROR" == "1" ] && return 1 |
---|
| 582 | |
---|
| 583 | |
---|
[761960be] | 584 | #SYNTAXSEEDER="echo MODE seeder ctorrent ; (sleep \$TIME && kill -9 \`pidof ctorrent\`) & ; ctorrent \${SOURCE}" |
---|
[1678fa1] | 585 | |
---|
| 586 | # si No fichero .bf, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial. |
---|
| 587 | if [ ! -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
[bba08bf] | 588 | then |
---|
[1678fa1] | 589 | echo "imagen ya descargada" |
---|
| 590 | case "$MODE" in |
---|
| 591 | seeder|SEEDER) |
---|
[2ab031e5] | 592 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
| 593 | (sleep $TIME && kill -2 `pidof ctorrent`) & |
---|
| 594 | ctorrent -f ${SOURCE} |
---|
[1678fa1] | 595 | esac |
---|
| 596 | return 0 |
---|
[bba08bf] | 597 | fi |
---|
| 598 | |
---|
[1678fa1] | 599 | #Si no existe bf ni fichero destino descarga inicial. |
---|
| 600 | if [ ! -f ${SOURCE}.bf -a ! -f ${TARGET} ] |
---|
| 601 | then |
---|
| 602 | OPTION=DOWNLOAD |
---|
| 603 | echo "descarga inicial" |
---|
| 604 | fi |
---|
| 605 | |
---|
| 606 | # Si fichero bf descarga anterior no completada -. |
---|
| 607 | if [ -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
| 608 | then |
---|
| 609 | echo Continuar con Descargar inicial no terminada. |
---|
| 610 | OPTION=DOWNLOAD |
---|
[bba08bf] | 611 | fi |
---|
| 612 | |
---|
[1678fa1] | 613 | if [ "$OPTION" == "DOWNLOAD" ] |
---|
[bba08bf] | 614 | then |
---|
[2ab031e5] | 615 | case "$MODE" in |
---|
| 616 | peer|PEER) |
---|
| 617 | echo "Donwloading Torrent as peer" ### echo "ctorrent -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100 $SOURCE -s $TARGET -b ${SOURCE}.bf" |
---|
[0fbc05e] | 618 | ctorrent -v -f -X "sleep 15; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bf >> $OGLOGFILE |
---|
[2ab031e5] | 619 | ;; |
---|
| 620 | leecher|LEECHER) |
---|
| 621 | echo "Donwloading Torrent as leecher" # echo "ctorrent ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100 -U 0" |
---|
| 622 | ctorrent ${SOURCE} -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 -U 0 |
---|
| 623 | ;; |
---|
| 624 | seeder|SEEDER) |
---|
| 625 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
| 626 | ctorrent -f -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bf |
---|
| 627 | ;; |
---|
| 628 | esac |
---|
| 629 | fi |
---|
| 630 | if [ "$OPTION" == "DOWNLOAD" ] |
---|
| 631 | then |
---|
| 632 | echo "comprobando el fichero descargado. Espere: " |
---|
| 633 | #echo " ctorrent -s $TARGET -c $SOURCE | tail -n1 | cut -f2 -d\( " |
---|
[1678fa1] | 634 | TOTAL=`ctorrent -s $TARGET -c $SOURCE | tail -n1 | cut -f2 -d\(` |
---|
| 635 | if [ "$TOTAL" == "100%)" ] |
---|
| 636 | then |
---|
| 637 | return 0 |
---|
| 638 | else |
---|
| 639 | return 1 |
---|
| 640 | fi |
---|
| 641 | |
---|
| 642 | fi |
---|
| 643 | |
---|
[bba08bf] | 644 | cd /tmp |
---|
| 645 | } |
---|
| 646 | |
---|
[2ab031e5] | 647 | #/** |
---|
| 648 | # ogCreateTorrent [ str_repo | int_ndisk int_npart ] Relative_path_file |
---|
| 649 | #@brief Función para crear el fichero torrent. |
---|
| 650 | #@param str_pathDirectory str_Relative_path_file |
---|
| 651 | #@param int_disk int_partition str_Relative_path_file |
---|
| 652 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
| 653 | #@return |
---|
| 654 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 655 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 656 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 657 | #@exception OG_ERR_NOTOS La partición no tiene instalado un sistema operativo. |
---|
| 658 | #@note |
---|
| 659 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 660 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 661 | #@date |
---|
| 662 | #@version 0.2 - Integración para btlaunch. |
---|
| 663 | #@author Irina . Univesidad de Sevilla. |
---|
| 664 | #@date |
---|
| 665 | #*/ ## |
---|
| 666 | |
---|
| 667 | ogCreateTorrent () |
---|
| 668 | { |
---|
| 669 | # Variables locales. |
---|
[0fbc05e] | 670 | local ARGS ARG SOURCE EXT IPTORRENT |
---|
[2ab031e5] | 671 | |
---|
| 672 | |
---|
| 673 | # Si se solicita, mostrar ayuda. |
---|
| 674 | if [ "$*" == "help" ]; then |
---|
| 675 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file IpBttrack" \ "$FUNCNAME 1 1 /aula1/winxp 10.1.15.23" \ |
---|
| 676 | "$FUNCNAME REPO /aula1/winxp 10.1.15.45" |
---|
| 677 | |
---|
| 678 | return |
---|
| 679 | fi |
---|
| 680 | |
---|
| 681 | # Error si se quiere crear el fichero en cache y no existe |
---|
| 682 | [ "$1" != "CACHE" ] || `ogFindCache >/dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE"|| return $? |
---|
| 683 | |
---|
| 684 | case "$1" in |
---|
| 685 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 686 | SOURCE=$(ogGetPath "$1.img") |
---|
| 687 | ARG=2 |
---|
| 688 | ;; |
---|
| 689 | [1-9]*) # ndisco npartición. |
---|
| 690 | SOURCE=$(ogGetPath "$1" "$2" "$3.img") |
---|
| 691 | ARG=4 |
---|
| 692 | ;; |
---|
| 693 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[0fbc05e] | 694 | EXT=$(ogGetImageType "$1" "$2") |
---|
| 695 | SOURCE=$(ogGetPath "$1" "$2.$EXT") |
---|
[2ab031e5] | 696 | ARG=3 |
---|
| 697 | ;; |
---|
| 698 | esac |
---|
| 699 | |
---|
| 700 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 701 | [ $# -eq "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 702 | |
---|
| 703 | |
---|
| 704 | # Error si no existe la imagen |
---|
| 705 | [ $SOURCE ] || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
| 706 | |
---|
| 707 | [ -r $SOURCE.torrent ] && mv "$SOURCE.torrent" "$SOURCE.torrent.ant" && echo "Esperamos que se refresque el servidor" && sleep 20 |
---|
| 708 | |
---|
| 709 | IPTORRENT="${!#}" |
---|
| 710 | # Si ponemos el path completo cuando creamos el fichero torrent da error |
---|
| 711 | cd `dirname $SOURCE` |
---|
| 712 | echo ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
| 713 | ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
| 714 | |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | |
---|
| 718 | |
---|
| 719 | |
---|
[bba08bf] | 720 | |
---|
| 721 | |
---|
| 722 | ############################################################ |
---|
[e9a6792] | 723 | ### FUNCIONES MULTICAST EN DESARROLLO ########## |
---|
[bba08bf] | 724 | |
---|
| 725 | |
---|
| 726 | #/** |
---|
| 727 | # ogMcastSessionCheck [session] |
---|
| 728 | #@brief Controla los parámetros de una sessión multicast |
---|
| 729 | #@param str_session |
---|
| 730 | #@return (nada, por determinar) |
---|
| 731 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 732 | #@note Requisitos: |
---|
| 733 | #@version 0.91 - Definición de FileTransfer |
---|
| 734 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 735 | #@date 2010/05/09 |
---|
| 736 | #*/ ## |
---|
| 737 | ogMcastSessionCheck () |
---|
| 738 | { |
---|
| 739 | echo "en pruebas" |
---|
| 740 | #sessionSERVER PORTBASE:METHOD:ADDRESS:BITRATE:NCLINTS:MAXTIME:TOOLCLONE:COMPRESSOR |
---|
| 741 | #sessionCLIENT PORTBASE:TOOLCLONE:COMPRESSOR |
---|
| 742 | #PORTBASE: 9000 (incluye el 9001), 9002 (incluye el 9003), 9004 |
---|
| 743 | #METHOD: full-duplex half-duplex brodcast |
---|
| 744 | #ADDRESS: Dirección habilitada para la transferencia. 339.194.ip2.ip3 |
---|
| 745 | #BITRATE: 90M 80M 70M |
---|
| 746 | #NCLIENTS: |
---|
| 747 | #MAXTIME: |
---|
| 748 | #TOOLCLONE: |
---|
| 749 | #COMPRESSOR: |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | |
---|
| 753 | #/** |
---|
| 754 | # ogMcastSessionList |
---|
| 755 | #@brief Lista las sessiones abiertas multicast. |
---|
| 756 | #@param (en pruebas) |
---|
| 757 | #@return (nada, por determinar) |
---|
| 758 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 759 | #@note Requisitos: |
---|
| 760 | #@version 0.91 - Definición de FileTransfer |
---|
| 761 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 762 | #@date 2010/05/09 |
---|
| 763 | #*/ ## |
---|
| 764 | ogMcastSessionList() |
---|
| 765 | { |
---|
| 766 | echo "en preubas" |
---|
| 767 | #puertos a utilizar 9000 - 9008 => se definen 10 sesiones |
---|
| 768 | #lsof -i -nP | grep 900 | awk '{print $9}' | awk -F: '{print $2}' | uniq |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | #/** |
---|
| 772 | # ogMcastSessionDelete |
---|
| 773 | #@brief Libera una session Mulitcast. |
---|
| 774 | #@param (en pruebas) |
---|
| 775 | #@return (nada, por determinar) |
---|
| 776 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 777 | #@note Requisitos: |
---|
| 778 | #@version 0.91 - Definición de FileTransfer |
---|
| 779 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 780 | #@date 2010/05/09 |
---|
| 781 | #*/ ## |
---|
| 782 | ogMcastSessionDelete() |
---|
| 783 | { |
---|
| 784 | echo "en pruebas" |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | |
---|
| 788 | |
---|
| 789 | |
---|
| 790 | |
---|
| 791 | ########################## FUNCIONES TORRENT EN DESARROLLO |
---|
| 792 | ################################################## |
---|
[884ea85] | 793 | #/** |
---|
| 794 | # ogStartTracker |
---|
| 795 | #@brief Inicia el tracker |
---|
| 796 | #@param str_pathDirectory str_Relative_path_file |
---|
| 797 | #@param int_disk int_partition str_Relative_path_file |
---|
| 798 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
| 799 | #@return |
---|
| 800 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 801 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 802 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 803 | #@exception OG_ERR_NOTOS La partición no tiene instalado un sistema operativo. |
---|
| 804 | #@note |
---|
| 805 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 806 | #@author |
---|
| 807 | #@date |
---|
| 808 | #*/ ## |
---|
| 809 | ogStartTracker () |
---|
| 810 | { |
---|
| 811 | echo " bug2: usar el tracker del bittornado. " |
---|
| 812 | echo " solucion bug2: apt-get autoremove bittorrent python-bittorrent " |
---|
| 813 | echo "soulución bug2: apt-get install bittornado. " |
---|
| 814 | echo "#Paso 2: iniciar track " |
---|
| 815 | local TESTBTT |
---|
| 816 | TESTBTT=`ps aux | grep bttrack | egrep -v grep | wc -l` |
---|
| 817 | if [ "$TESTBTT" == "0" ]; then |
---|
| 818 | bttrack --reannounce_interval 10 --port 6969 --dfile /root/dstate --logfile /root/bttracker.log --save_dfile_interval 10 --timeout_downloaders_interval 10 2>/dev/null & |
---|
| 819 | else |
---|
| 820 | echo "bttrack iniciado" |
---|
| 821 | fi |
---|
| 822 | |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | ogShareTorrent () |
---|
| 826 | { |
---|
| 827 | # Variables locales. |
---|
[0fbc05e] | 828 | local ARGS SOURCE EXT TARGET |
---|
[884ea85] | 829 | |
---|
| 830 | |
---|
| 831 | # Si se solicita, mostrar ayuda. |
---|
| 832 | if [ "$*" == "help" ]; then |
---|
| 833 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file" \ |
---|
| 834 | "$FUNCNAME 1 1 /aula1/winxp" \ |
---|
| 835 | "$FUNCNAME REPO /aula1/winxp" |
---|
| 836 | |
---|
| 837 | return |
---|
| 838 | fi |
---|
| 839 | |
---|
| 840 | # Error si se quiere compartir un fichero en cache y no existe la cache |
---|
| 841 | [ "$1" != "CACHE" ] || `ogFindCache >/dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE"|| return $? |
---|
| 842 | |
---|
| 843 | case "$1" in |
---|
| 844 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 845 | SOURCE=$(ogGetPath "$1.img") |
---|
| 846 | ARG=1 |
---|
| 847 | ;; |
---|
| 848 | [1-9]*) # ndisco npartición. |
---|
| 849 | SOURCE=$(ogGetPath "$1" "$2" "$3.img") |
---|
| 850 | ARG=3 |
---|
| 851 | ;; |
---|
| 852 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[0fbc05e] | 853 | EXT=$(ogGetImageType "$1" "$2") |
---|
| 854 | SOURCE=$(ogGetPath "$1" "$2.$EXT" 2>/dev/null) |
---|
[884ea85] | 855 | ARG=2 |
---|
| 856 | ;; |
---|
| 857 | esac |
---|
| 858 | |
---|
| 859 | |
---|
| 860 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 861 | [ $# -ne "$ARG" ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 862 | |
---|
| 863 | # Comprobar fichero origen |
---|
| 864 | [ -n "$SOURCE.torrent" ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $? |
---|
| 865 | |
---|
| 866 | echo ctorrent $SOURCE.torrent -d |
---|
| 867 | ctorrent $SOURCE.torrent -d |
---|
| 868 | |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | |
---|
| 872 | ogTorrentReceiverFile () |
---|
| 873 | { |
---|
| 874 | # obligatorio disponer de cache |
---|
| 875 | # origen destino. |
---|
| 876 | #origen es el .torrent |
---|
| 877 | # origen: REPO /file.torrent |
---|
| 878 | # Si REPO, (nfs, http) copiamos a CACHE. |
---|
| 879 | |
---|
| 880 | # destino es el fichero final. |
---|
| 881 | # destino: CACHE /file |
---|
| 882 | # destino: disk part /file |
---|
| 883 | |
---|
| 884 | # Variables locales. |
---|
| 885 | local ARGS ARG SOURCEDIR SOURCEFILE TARGETDIR TARGETFILE |
---|
| 886 | |
---|
| 887 | # Si se solicita, mostrar ayuda. |
---|
| 888 | if [ "$*" == "help" ]; then |
---|
| 889 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file" \ |
---|
| 890 | "$FUNCNAME REPO /aula1/winxp.torrent CACHE /aula1/winxp" \ |
---|
| 891 | "$FUNCNAME REPO /aula1/winxp.torrent 1 1 /iso" |
---|
| 892 | fi |
---|
| 893 | # Comprobamos que existe Cache |
---|
| 894 | `ogFindCache > /dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE" || return $? |
---|
| 895 | |
---|
| 896 | # guardamos torrent. controlamos tamaño del fichero y comprobamos con cache. |
---|
| 897 | ogCopyFile $1 $2 $3 $4 |
---|
| 898 | |
---|
| 899 | |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | ogReceiveTorrent () |
---|
| 903 | { |
---|
| 904 | # Variables locales. |
---|
| 905 | local ARGS ARG TARGETDIR TARGETFILE |
---|
| 906 | |
---|
| 907 | |
---|
| 908 | |
---|
| 909 | # Si se solicita, mostrar ayuda. |
---|
| 910 | if [ "$*" == "help" ]; then |
---|
| 911 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file" \ |
---|
| 912 | "$FUNCNAME 1 1 /aula1/winxp" \ |
---|
| 913 | "$FUNCNAME REPO /aula1/winxp" \ |
---|
| 914 | "$FUNCNAME /mnt/sda2/winxp" |
---|
| 915 | |
---|
| 916 | |
---|
| 917 | return |
---|
| 918 | fi |
---|
| 919 | |
---|
| 920 | # Comprobamos que existe Cache |
---|
| 921 | `ogFindCache > /dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE" || return $? |
---|
| 922 | |
---|
| 923 | ARGS="$*" |
---|
| 924 | case "$1" in |
---|
| 925 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 926 | TARGETDIR=$(ogGetParentPath "$1") |
---|
| 927 | ARG=1 |
---|
| 928 | ;; |
---|
| 929 | [1-9]*) # ndisco npartición. |
---|
| 930 | TARGETDIR=$(ogGetParentPath "$1" "$2" "$3") |
---|
| 931 | ARG=3 |
---|
| 932 | ;; |
---|
| 933 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[0fbc05e] | 934 | EXT=$(ogGetImageType "$1" "$2") |
---|
[884ea85] | 935 | TARGETDIR=$(ogGetParentPath "$1" "$2") |
---|
| 936 | ARG=2 |
---|
| 937 | ;; |
---|
| 938 | esac |
---|
| 939 | #echo $TARGETDIR |
---|
[0fbc05e] | 940 | EXT=${EXT:-"img"} |
---|
[884ea85] | 941 | |
---|
| 942 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 943 | [ "$#" -ne "$ARG" ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 944 | |
---|
| 945 | #obtenemos el nombre del fichero a descargar. |
---|
| 946 | TARGETFILE=`basename ${!ARG}` |
---|
| 947 | CACHE=`ogMountCache` |
---|
| 948 | |
---|
| 949 | # Error si no existe el fichero torrent |
---|
[0fbc05e] | 950 | [ -r $TARGETDIR/$TARGETFILE.$EXT.torrent ] || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
[884ea85] | 951 | [ -d ${CACHE}/$OGIMG ] || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
| 952 | |
---|
| 953 | TimeToWaitForCloseAfterDownload=20 # tiempo que deseamos que el cliente este como semilla, despues de la descarga. |
---|
| 954 | |
---|
| 955 | # Si el fichero ya se ha bajado antes de iniciar el ctorrent no se ejecuta el comando kill, siguen encendido siempre |
---|
| 956 | # Comprobamos si se ha descargado antes, si es asi nos salimos |
---|
[0fbc05e] | 957 | Total=`ctorrent -s ${CACHE}/$OGIMG/${TARGETFILE}.$EXT -c $TARGETDIR/$TARGETFILE.$EXT.torrent|tail -n1|cut -f2 -d\(` |
---|
[884ea85] | 958 | [ $Total == "100%)" ] && return 0 |
---|
| 959 | |
---|
[0fbc05e] | 960 | #echo "ctorrent -X 'sleep $TimeToWaitForCloseAfterDownload; kill -9 \$(pidof ctorrent)' $TARGETDIR/$TARGETFILE.img.torrent -s ${CACHE}/$OGIMG/${TARGETFILE}.img -b ${CACHE}/$OGIMG/$TARGETFILE.bf -C 100" |
---|
| 961 | ctorrent -X "sleep $TimeToWaitForCloseAfterDownload; kill -9 \$(pidof ctorrent)" $TARGETDIR/$TARGETFILE.$EXT.torrent -s ${CACHE}/$OGIMG/${TARGETFILE}.$EXT -b ${CACHE}/$OGIMG/$TARGETFILE.bf -C 100 |
---|
[884ea85] | 962 | |
---|
| 963 | [ -r ${CACHE}/$OGIMG/$TARGETFILE.bf ] && rm ${CACHE}/$OGIMG/$TARGETFILE.bf |
---|
[bd390f1] | 964 | } |
---|
| 965 | |
---|
| 966 | ogCheckSessionMulticast () |
---|
| 967 | { |
---|
| 968 | # $1 tipo de sesion server client |
---|
| 969 | # 2 la sesisón. |
---|
| 970 | #variables locales |
---|
| 971 | local NPARM MODE SESSION |
---|
| 972 | |
---|
| 973 | # Si se solicita, mostrar ayuda. |
---|
| 974 | if [ "$*" == "help" ]; then |
---|
| 975 | ogHelp "$FUNCNAME str_mode array_session" \ |
---|
| 976 | "$FUNCNAME client PORTBASE"\ |
---|
| 977 | "$FUNCNAME server PORTBASE:METHOD:ADDRESS:BITRATE:NCLIENTS:MAXTIME" |
---|
| 978 | return |
---|
| 979 | fi |
---|
| 980 | |
---|
| 981 | |
---|
| 982 | # Error si no se recibe 2 parámetro. |
---|
| 983 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 984 | |
---|
| 985 | # controlamos el primer parametro. |
---|
| 986 | ogCheckStringInGroup "$1" "client server" || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 987 | |
---|
| 988 | #controlamos el segundo parametro. La sessión multicast. |
---|
| 989 | [ $1 == "client" ] && NPARM=1 || NPARM=6 |
---|
| 990 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
| 991 | [[ ${#SESSION[*]} == $NPARM ]] || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 992 | |
---|
| 993 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
| 994 | ogCheckStringInGroup ${SESSION[0]} "9000 9002 9004 9006 9008 9010" || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 995 | |
---|
| 996 | if [ "$1" == "server" ] |
---|
| 997 | then |
---|
| 998 | # $METHOD |
---|
| 999 | ogCheckStringInGroup ${SESSION[1]} "full-duplex half-duplex broadcast" || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 1000 | # $ADDRESS |
---|
| 1001 | ogCheckIpAddress ${SESSION[2]} || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 1002 | #BITRATE |
---|
| 1003 | ogCheckStringInReg ${SESSION[3]} "^[1-9]{1,2}M$" || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 1004 | #NCLIENTS |
---|
| 1005 | ogCheckStringInReg ${SESSION[4]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_OUTOFLIMIT || return $? |
---|
| 1006 | #MAXTIME |
---|
| 1007 | ogCheckStringInReg ${SESSION[5]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_OUTOFLIMIT " " || return $? |
---|
| 1008 | fi |
---|
| 1009 | return 0 |
---|
| 1010 | } |
---|