[884ea85] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file Protocol.lib |
---|
| 4 | #@brief Librería o clase Protocol |
---|
[30431f9] | 5 | #@class Protocol |
---|
[884ea85] | 6 | #@brief Funciones para transmisión de datos |
---|
[30431f9] | 7 | #@version 1.0 |
---|
[884ea85] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[62ccd9b] | 11 | #/** |
---|
| 12 | # ogUcastSyntax |
---|
[30431f9] | 13 | #@brief Función para generar la instrucción de transferencia de datos unicast |
---|
[62ccd9b] | 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. |
---|
[30431f9] | 21 | #@exception OG_ERR_UCASTSYNTAXT formato de la sesion unicast incorrecta. |
---|
[62ccd9b] | 22 | #@note Requisitos: mbuffer |
---|
[30431f9] | 23 | #@todo: controlar que mbuffer esta disponible para los clientes. |
---|
[62ccd9b] | 24 | #@version 1.0 - |
---|
| 25 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 26 | #@date 2011/03/09 |
---|
| 27 | #*/ ## |
---|
[30431f9] | 28 | |
---|
[62ccd9b] | 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 | |
---|
[30431f9] | 53 | |
---|
[62ccd9b] | 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 |
---|
[30431f9] | 102 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
[62ccd9b] | 103 | TOOL=$4 |
---|
[30431f9] | 104 | ogCheckStringInGroup "$5" "lzop gzip LZOP GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
[62ccd9b] | 105 | LEVEL=$5 |
---|
| 106 | fi |
---|
| 107 | |
---|
[30431f9] | 108 | [ "$PERROR" == "0" ] || ogRaiseError $OG_ERR_UCASTSYNTAXT " $PERROR" || return $? |
---|
[62ccd9b] | 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. |
---|
[30431f9] | 140 | #@param 1 disk |
---|
| 141 | #@param 2 partition |
---|
| 142 | #@param 3 sesionUcast |
---|
| 143 | #@param 4 tool image |
---|
| 144 | #@param 5 tool compresor |
---|
[62ccd9b] | 145 | #@return |
---|
[30431f9] | 146 | #@exception $OG_ERR_FORMAT |
---|
| 147 | #@exception $OG_ERR_UCASTSENDPARTITION |
---|
[62ccd9b] | 148 | #@note |
---|
[30431f9] | 149 | #@todo: ogIsLocked siempre devuelve 1 |
---|
| 150 | #@version 1.0 - |
---|
| 151 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 152 | #@date 2011/03/09 |
---|
[62ccd9b] | 153 | #*/ ## |
---|
| 154 | |
---|
[30431f9] | 155 | function ogUcastSendPartition () |
---|
[62ccd9b] | 156 | { |
---|
| 157 | |
---|
| 158 | # Variables locales |
---|
[30431f9] | 159 | local PART COMMAND RETVAL |
---|
[62ccd9b] | 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` |
---|
[30431f9] | 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 | |
---|
[62ccd9b] | 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. |
---|
[30431f9] | 193 | #@param 1 disk |
---|
| 194 | #@param 2 partition |
---|
| 195 | #@param 3 session unicast |
---|
[62ccd9b] | 196 | #@return |
---|
[30431f9] | 197 | #@exception OG_ERR_FORMAT |
---|
| 198 | #@exception OG_ERR_UCASTRECEIVERPARTITION |
---|
[62ccd9b] | 199 | #@note |
---|
| 200 | #@todo: |
---|
[30431f9] | 201 | #@version 1.0 - Integración para OpenGNSys. |
---|
| 202 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 203 | #@date 2011/03/09 |
---|
[62ccd9b] | 204 | #*/ ## |
---|
[30431f9] | 205 | function ogUcastReceiverPartition () |
---|
[62ccd9b] | 206 | { |
---|
| 207 | # Variables locales |
---|
[30431f9] | 208 | local PART COMMAND RETVAL |
---|
[62ccd9b] | 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 | |
---|
[30431f9] | 224 | |
---|
[62ccd9b] | 225 | #generamos la instrucción a ejecutar. |
---|
| 226 | COMMAND=`ogUcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
[30431f9] | 227 | RETVAL=$? |
---|
[62ccd9b] | 228 | |
---|
[30431f9] | 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 | } |
---|
[62ccd9b] | 237 | |
---|
[884ea85] | 238 | |
---|
| 239 | |
---|
| 240 | #/** |
---|
[761960be] | 241 | # ogMcastSyntax |
---|
[bd390f1] | 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. |
---|
[884ea85] | 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. |
---|
[30431f9] | 250 | #@exception OG_ERR_NOTEXEC |
---|
| 251 | #@exception OG_ERR_MCASTSYNTAXT |
---|
| 252 | #@note Requisitos: upd-cast 2009 o superior |
---|
[0fbc05e] | 253 | #@todo localvar check versionudp |
---|
[30431f9] | 254 | #@version 1.0 - |
---|
[884ea85] | 255 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 256 | #@date 2010/05/09 |
---|
| 257 | #*/ ## |
---|
| 258 | # |
---|
| 259 | |
---|
| 260 | |
---|
[761960be] | 261 | function ogMcastSyntax () |
---|
[884ea85] | 262 | { |
---|
[bd390f1] | 263 | |
---|
[59e3998] | 264 | local ISUDPCAST PARM SESSION SESSIONPARM MODE PORTBASE PERROR |
---|
[bd390f1] | 265 | local METHOD ADDRESS BITRATE NCLIENTS MAXTIME CERROR |
---|
[761960be] | 266 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
[bd390f1] | 267 | |
---|
[884ea85] | 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 "\ |
---|
[e8df652] | 273 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
[fa43c91] | 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 " \ |
---|
[0fbc05e] | 276 | "sessionClient syntax: portbase " \ |
---|
| 277 | "sessionClient example: 9000 " |
---|
[884ea85] | 278 | return |
---|
| 279 | fi |
---|
[59e3998] | 280 | PERROR=0 |
---|
[884ea85] | 281 | |
---|
[bd390f1] | 282 | #si no tenemos updcast o su version superior 2009 udpcast error. |
---|
| 283 | ISUDPCAST=$(udp-receiver --help 2>&1) |
---|
[30431f9] | 284 | echo $ISUDPCAST | grep start-timeout > /dev/null || ogRaiseError $OG_ERR_NOTEXEC "upd-cast no existe o version antigua -requerida 2009-"|| return $? |
---|
[bd390f1] | 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 |
---|
[59e3998] | 293 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
[bd390f1] | 294 | |
---|
| 295 | # 2º param check |
---|
| 296 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
| 297 | |
---|
[59e3998] | 298 | #TODO: diferenciamos los paramatros especificos de la sessión multicast |
---|
| 299 | #SI: controlamos todos los parametros de la sessión multicast. |
---|
[56d2d6f] | 300 | [ $MODE == "client" ] && SESSIONPARM=1 || SESSIONPARM=6 |
---|
[bd390f1] | 301 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
[59e3998] | 302 | |
---|
| 303 | |
---|
| 304 | [[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
| 305 | |
---|
| 306 | |
---|
[bd390f1] | 307 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
| 308 | PORTBASE=${SESSION[0]} |
---|
[59e3998] | 309 | ogCheckStringInGroup ${SESSION[0]} "9000 9002 9004 9006 9008 9010" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
[bd390f1] | 310 | if [ $MODE == "server" ] |
---|
| 311 | then |
---|
[59e3998] | 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 $? |
---|
[bd390f1] | 313 | METHOD=${SESSION[1]} |
---|
[59e3998] | 314 | ogCheckIpAddress ${SESSION[2]} || ogRaiseError $OG_ERR_FORMAT "McastSession address ${SESSION[2]}" || PERROR=5 #return $? |
---|
[bd390f1] | 315 | ADDRESS=${SESSION[2]} |
---|
[59e3998] | 316 | ogCheckStringInReg ${SESSION[3]} "^[0-9]{1,2}\M$" || ogRaiseError $OG_ERR_FORMAT "McastSession bitrate ${SESSION[3]}" || PERROR=6 # return $? |
---|
[bd390f1] | 317 | BITRATE=${SESSION[3]} |
---|
[59e3998] | 318 | ogCheckStringInReg ${SESSION[4]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession nclients ${SESSION[4]}" || PERROR=7 # return $? |
---|
[bd390f1] | 319 | NCLIENTS=${SESSION[4]} |
---|
[59e3998] | 320 | ogCheckStringInReg ${SESSION[5]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession maxtime ${SESSION[5]}" || PERROR=8 # return $? |
---|
[bd390f1] | 321 | MAXTIME=${SESSION[5]} |
---|
| 322 | fi |
---|
[884ea85] | 323 | |
---|
[bd390f1] | 324 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
[59e3998] | 325 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
[bd390f1] | 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 |
---|
[30431f9] | 332 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
[bd390f1] | 333 | TOOL=$4 |
---|
[30431f9] | 334 | ogCheckStringInGroup "$5" "lzop LZOP gzip GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
[bd390f1] | 335 | LEVEL=$5 |
---|
| 336 | fi |
---|
| 337 | |
---|
[59e3998] | 338 | |
---|
[30431f9] | 339 | if [ "$PERROR" != "0" ]; then |
---|
| 340 | ogRaiseError $OG_ERR_MCASTSYNTAXT " $PERROR"; return $? |
---|
| 341 | fi |
---|
| 342 | |
---|
[bd390f1] | 343 | |
---|
| 344 | # Valores estandar no configurables. |
---|
| 345 | CERROR="8x8/128" |
---|
[884ea85] | 346 | |
---|
| 347 | # opción del usuo de tuberia intermedia en memoria mbuffer. |
---|
[fa43c91] | 348 | which mbuffer > /dev/null && MBUFFER=" --pipe 'mbuffer -q -m 20M' " |
---|
[884ea85] | 349 | |
---|
| 350 | # Generamos la instrucción base de multicast -Envio,Recepcion- |
---|
[30431f9] | 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" |
---|
[761960be] | 352 | SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE " |
---|
[884ea85] | 353 | |
---|
| 354 | |
---|
| 355 | case "$1" in |
---|
[59e3998] | 356 | SENDPARTITION) |
---|
[761960be] | 357 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
| 358 | echo "$PROG1 | $SYNTAXSERVER" |
---|
[884ea85] | 359 | ;; |
---|
| 360 | RECEIVERPARTITION) |
---|
[761960be] | 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 " |
---|
[884ea85] | 364 | ;; |
---|
| 365 | SENDFILE) |
---|
[761960be] | 366 | echo "$SYNTAXSERVER --file $3" |
---|
[884ea85] | 367 | ;; |
---|
| 368 | RECEIVERFILE) |
---|
[761960be] | 369 | echo "$SYNTAXCLIENT --file $3" |
---|
[884ea85] | 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. |
---|
[30431f9] | 386 | #@exception $OG_ERR_NOTFOUND |
---|
| 387 | #@exception OG_ERR_MCASTSENDFILE |
---|
[884ea85] | 388 | #@note Requisitos: |
---|
[30431f9] | 389 | #@version 1.0 - Definición de Protocol.lib |
---|
[884ea85] | 390 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 391 | #@date 2010/05/09 |
---|
| 392 | #*/ ## |
---|
| 393 | # |
---|
| 394 | |
---|
| 395 | function ogMcastSendFile () |
---|
| 396 | { |
---|
| 397 | # Variables locales. |
---|
[30431f9] | 398 | local ARGS SOURCE TARGET COMMAND DEVICE RETVAL LOGFILE |
---|
[884ea85] | 399 | |
---|
[30431f9] | 400 | #LOGFILE="/tmp/mcast.log" |
---|
| 401 | |
---|
| 402 | #ARGS usado para controlar ubicación de la sesion multicast |
---|
[884ea85] | 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 |
---|
[bd390f1] | 415 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
[884ea85] | 416 | SOURCE=$(ogGetPath "$1") |
---|
[bd390f1] | 417 | ARG=2 |
---|
| 418 | DEVICE="$1" |
---|
[884ea85] | 419 | ;; |
---|
| 420 | [1-9]*) # ndisco npartición. |
---|
| 421 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
| 422 | ARG=4 |
---|
[bd390f1] | 423 | DEVICE="$1 $2 $3" |
---|
[884ea85] | 424 | ;; |
---|
| 425 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 426 | SOURCE=$(ogGetPath "$1" "$2") |
---|
| 427 | ARG=3 |
---|
[bd390f1] | 428 | DEVICE="$1 $2 " |
---|
[884ea85] | 429 | ;; |
---|
| 430 | esac |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 434 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[884ea85] | 435 | |
---|
| 436 | # Comprobar fichero origen |
---|
[bd390f1] | 437 | ogGetPath $SOURCE &> /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $DEVICE not found" || return $? |
---|
[884ea85] | 438 | |
---|
[30431f9] | 439 | # eliminamos ficheros antiguos de log |
---|
| 440 | #rm $LOGFILE |
---|
| 441 | |
---|
[884ea85] | 442 | SESSION=${!ARG} |
---|
[30431f9] | 443 | |
---|
| 444 | |
---|
| 445 | |
---|
| 446 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 447 | COMMAND=`ogMcastSyntax "SENDFILE" "$SESSION" "$SOURCE"` |
---|
[30431f9] | 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 | |
---|
[884ea85] | 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. |
---|
[30431f9] | 471 | #@exception $OG_ERR_MCASTRECEIVERFILE |
---|
[884ea85] | 472 | #@note Requisitos: |
---|
[30431f9] | 473 | #@version 1.0 - Definición de Protocol.lib |
---|
[884ea85] | 474 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 475 | #@date 2010/05/09 |
---|
| 476 | #*/ ## |
---|
| 477 | # |
---|
| 478 | |
---|
[30431f9] | 479 | function ogMcastReceiverFile () |
---|
[884ea85] | 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 ] ]" \ |
---|
[bd390f1] | 489 | "$FUNCNAME 9000 /PS1_PH1.img" \ |
---|
| 490 | "$FUNCNAME 9000 CACHE /aula1/PS2_PH4.img" \ |
---|
| 491 | "$FUNCNAME 9000 1 1 /isos/linux.iso" |
---|
[884ea85] | 492 | return |
---|
| 493 | fi |
---|
| 494 | |
---|
| 495 | ARGS="$@" |
---|
| 496 | case "$2" in |
---|
| 497 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 498 | TARGETDIR=$(ogGetParentPath "$2") |
---|
[bd390f1] | 499 | ARG=2 |
---|
[884ea85] | 500 | ;; |
---|
| 501 | [1-9]*) # ndisco npartición. |
---|
| 502 | TARGETDIR=$(ogGetParentPath "$2" "$3" "$4") |
---|
[bd390f1] | 503 | ARG=4 |
---|
[884ea85] | 504 | ;; |
---|
| 505 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 506 | TARGETDIR=$(ogGetParentPath "$2" "$3") |
---|
[bd390f1] | 507 | ARG=3 |
---|
[884ea85] | 508 | ;; |
---|
| 509 | esac |
---|
| 510 | |
---|
| 511 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 512 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
[884ea85] | 513 | |
---|
| 514 | #obtenemos el nombre del fichero a descargar. |
---|
| 515 | TARGETFILE=`basename ${!ARG}` |
---|
| 516 | |
---|
| 517 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 518 | COMMAND=`ogMcastSyntax RECEIVERFILE "$1" $TARGETDIR/$TARGETFILE ` |
---|
[30431f9] | 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 |
---|
[e8df652] | 529 | } |
---|
| 530 | |
---|
| 531 | #/** |
---|
| 532 | # ogMcastSendPartition |
---|
| 533 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas. |
---|
[30431f9] | 534 | #@param 1 disk |
---|
| 535 | #@param 2 partition |
---|
| 536 | #@param 3 session multicast |
---|
| 537 | #@param 4 tool clone |
---|
| 538 | #@param 5 tool compressor |
---|
[e8df652] | 539 | #@return |
---|
[30431f9] | 540 | #@exception OG_ERR_FORMAT |
---|
| 541 | #@exception OG_ERR_MCASTSENDPARTITION |
---|
[e8df652] | 542 | #@note |
---|
| 543 | #@todo: ogIsLocked siempre devuelve 1. crear ticket |
---|
[30431f9] | 544 | #@version 1.0 - Definición de Protocol.lib |
---|
| 545 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 546 | #@date 2010/05/09 |
---|
[e8df652] | 547 | #*/ ## |
---|
| 548 | |
---|
[30431f9] | 549 | function ogMcastSendPartition () |
---|
[e8df652] | 550 | { |
---|
| 551 | |
---|
| 552 | # Variables locales |
---|
[30431f9] | 553 | local PART COMMAND RETVAL |
---|
[e8df652] | 554 | |
---|
| 555 | # Si se solicita, mostrar ayuda. |
---|
| 556 | if [ "$*" == "help" ]; then |
---|
| 557 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastSERVER tools compresor" \ |
---|
[fa43c91] | 558 | "$FUNCNAME 1 1 9000:full-duplex:239.194.37.31:50M:20:2 partclone lzop" |
---|
[e8df652] | 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. |
---|
[761960be] | 570 | COMMAND=`ogMcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
[30431f9] | 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 | |
---|
[e8df652] | 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. |
---|
[30431f9] | 587 | #@param 1 disk |
---|
| 588 | #@param 2 partition |
---|
| 589 | #@param 3 session multicast |
---|
| 590 | #@param 4 tool clone |
---|
| 591 | #@param 5 tool compressor |
---|
[e8df652] | 592 | #@return |
---|
[30431f9] | 593 | #@exception $OG_ERR_FORMAT |
---|
[e8df652] | 594 | #@note |
---|
| 595 | #@todo: |
---|
[30431f9] | 596 | #@version 1.0 - Definición de Protocol.lib |
---|
| 597 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 598 | #@date 2010/05/09 |
---|
[e8df652] | 599 | #*/ ## |
---|
[30431f9] | 600 | function ogMcastReceiverPartition () |
---|
[e8df652] | 601 | { |
---|
| 602 | # Variables locales |
---|
[30431f9] | 603 | local PART COMMAND RETVAL |
---|
[e8df652] | 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. |
---|
[761960be] | 620 | COMMAND=`ogMcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
[30431f9] | 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 | |
---|
[884ea85] | 631 | } |
---|
| 632 | |
---|
[bd390f1] | 633 | |
---|
| 634 | ########################################## |
---|
[bba08bf] | 635 | ############## funciones torrent |
---|
[884ea85] | 636 | #/** |
---|
[2ab031e5] | 637 | # ogTorrentStart [ str_repo | int_ndisk int_npart ] Relative_path_file.torrent | SessionProtocol |
---|
[1678fa1] | 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. |
---|
[bba08bf] | 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 |
---|
[2ab031e5] | 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 | |
---|
[bba08bf] | 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 |
---|
[1678fa1] | 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 |
---|
[2ab031e5] | 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 |
---|
[bba08bf] | 661 | #*/ ## |
---|
[2ab031e5] | 662 | |
---|
[1678fa1] | 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. |
---|
[bba08bf] | 668 | |
---|
[30431f9] | 669 | function ogTorrentStart () |
---|
[bba08bf] | 670 | { |
---|
[2ab031e5] | 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 |
---|
[bba08bf] | 684 | |
---|
| 685 | case "$1" in |
---|
| 686 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 687 | SOURCE=$(ogGetPath "$1") |
---|
[2ab031e5] | 688 | ARG=2 |
---|
[bba08bf] | 689 | ;; |
---|
| 690 | [1-9]*) # ndisco npartición. |
---|
| 691 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
[2ab031e5] | 692 | ARG=4 |
---|
[bba08bf] | 693 | ;; |
---|
[2ab031e5] | 694 | *) # Otros: Solo cache (no se permiten caminos relativos). |
---|
[bba08bf] | 695 | SOURCE=$(ogGetPath "$1" "$2" 2>/dev/null) |
---|
[2ab031e5] | 696 | ARG=3 |
---|
| 697 | ;; |
---|
[bba08bf] | 698 | esac |
---|
| 699 | |
---|
[2ab031e5] | 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 $? |
---|
[bba08bf] | 719 | |
---|
| 720 | TARGET=`echo $SOURCE | awk -F.torrent '{print $1}'` |
---|
| 721 | DIRSOURCE=`ogGetParentPath $SOURCE` |
---|
| 722 | cd $DIRSOURCE |
---|
| 723 | |
---|
[1678fa1] | 724 | |
---|
[bba08bf] | 725 | |
---|
[2ab031e5] | 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 | |
---|
[761960be] | 739 | #SYNTAXSEEDER="echo MODE seeder ctorrent ; (sleep \$TIME && kill -9 \`pidof ctorrent\`) & ; ctorrent \${SOURCE}" |
---|
[1678fa1] | 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} ] |
---|
[bba08bf] | 743 | then |
---|
[1678fa1] | 744 | echo "imagen ya descargada" |
---|
| 745 | case "$MODE" in |
---|
| 746 | seeder|SEEDER) |
---|
[2ab031e5] | 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} |
---|
[1678fa1] | 750 | esac |
---|
| 751 | return 0 |
---|
[bba08bf] | 752 | fi |
---|
| 753 | |
---|
[1678fa1] | 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 |
---|
[bba08bf] | 766 | fi |
---|
| 767 | |
---|
[1678fa1] | 768 | if [ "$OPTION" == "DOWNLOAD" ] |
---|
[bba08bf] | 769 | then |
---|
[2ab031e5] | 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" |
---|
[914d834] | 773 | ctorrent -f -X "sleep 15; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bf >> $OGLOGFILE |
---|
[2ab031e5] | 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 |
---|
[bba08bf] | 785 | cd /tmp |
---|
| 786 | } |
---|
| 787 | |
---|
[2ab031e5] | 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 | |
---|
[30431f9] | 808 | function ogCreateTorrent () |
---|
[2ab031e5] | 809 | { |
---|
| 810 | # Variables locales. |
---|
[0fbc05e] | 811 | local ARGS ARG SOURCE EXT IPTORRENT |
---|
[2ab031e5] | 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). |
---|
[0fbc05e] | 835 | EXT=$(ogGetImageType "$1" "$2") |
---|
| 836 | SOURCE=$(ogGetPath "$1" "$2.$EXT") |
---|
[2ab031e5] | 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 | |
---|
[bba08bf] | 859 | #/** |
---|
[914d834] | 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 |
---|
[884ea85] | 866 | #@note |
---|
[914d834] | 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 |
---|
[884ea85] | 871 | #@date |
---|
| 872 | #*/ ## |
---|
[914d834] | 873 | function ogUpdateCacheIsNecesary () |
---|
[884ea85] | 874 | { |
---|
| 875 | |
---|
| 876 | # Variables locales. |
---|
[914d834] | 877 | local ERROR SOURCE CACHE FILESOURCE MD5SOURCE FILETARGET MD5TARGET |
---|
| 878 | ERROR=0 |
---|
[884ea85] | 879 | |
---|
| 880 | # Si se solicita, mostrar ayuda. |
---|
| 881 | if [ "$*" == "help" ]; then |
---|
[914d834] | 882 | ogHelp "$FUNCNAME $FUNCNAME [ str_repo] [ [Relative_path_image] " \ |
---|
| 883 | "$FUNCNAME REPO /PS1_PH1.img" \ |
---|
| 884 | "$FUNCNAME REPO /ogclient.sqfs" |
---|
| 885 | |
---|
[884ea85] | 886 | return |
---|
| 887 | fi |
---|
| 888 | |
---|
[914d834] | 889 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 890 | [ $# == "2" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
[884ea85] | 891 | |
---|
| 892 | |
---|
[914d834] | 893 | ogCheckStringInGroup "$1" "REPO repo" || ogRaiseError $OG_ERR_FORMAT "El contendor $1 no es valido, solo se admite REPO" || return $? |
---|
[884ea85] | 894 | |
---|
[914d834] | 895 | FILESOURCE=`ogGetPath $1 $2` |
---|
| 896 | FILETARGET=`ogGetPath CACHE $2` |
---|
[884ea85] | 897 | |
---|
[914d834] | 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 |
---|
[884ea85] | 906 | fi |
---|
[914d834] | 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 |
---|
[884ea85] | 913 | fi |
---|
| 914 | |
---|
[914d834] | 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) |
---|
[bd390f1] | 937 | fi |
---|
| 938 | |
---|
[914d834] | 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 |
---|
[bd390f1] | 950 | |
---|
[914d834] | 951 | } |
---|
[bd390f1] | 952 | |
---|
| 953 | |
---|
| 954 | |
---|