[884ea85] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file Protocol.lib |
---|
| 4 | #@brief Librería o clase Protocol |
---|
[eb9424f] | 5 | #@class Protocol |
---|
[884ea85] | 6 | #@brief Funciones para transmisión de datos |
---|
[91c5326] | 7 | #@version 1.0.5 |
---|
[884ea85] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[eb9424f] | 11 | |
---|
| 12 | ##################### FUNCIONES UNICAST ################ |
---|
| 13 | |
---|
[62ccd9b] | 14 | #/** |
---|
| 15 | # ogUcastSyntax |
---|
[eb9424f] | 16 | #@brief Función para generar la instrucción de transferencia de datos unicast |
---|
[62ccd9b] | 17 | #@param 1 Tipo de operación [ SENDPARTITION RECEIVERPARTITION SENDFILE RECEIVERFILE ] |
---|
| 18 | #@param 2 Sesion Unicast |
---|
| 19 | #@param 3 Dispositivo (opción PARTITION) o fichero(opción FILE) que será enviado. |
---|
| 20 | #@param 4 Tools de clonación (opcion PARTITION) |
---|
| 21 | #@param 5 Tools de compresion (opcion PARTITION) |
---|
| 22 | #@return instrucción para ser ejecutada. |
---|
| 23 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[eb9424f] | 24 | #@exception OG_ERR_UCASTSYNTAXT formato de la sesion unicast incorrecta. |
---|
[62ccd9b] | 25 | #@note Requisitos: mbuffer |
---|
[eb9424f] | 26 | #@todo: controlar que mbuffer esta disponible para los clientes. |
---|
[62ccd9b] | 27 | #@version 1.0 - |
---|
| 28 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 29 | #@date 2011/03/09 |
---|
| 30 | #*/ ## |
---|
[eb9424f] | 31 | |
---|
[62ccd9b] | 32 | function ogUcastSyntax () |
---|
| 33 | { |
---|
| 34 | |
---|
[1cd64e6] | 35 | local PARM SESSION SESSIONPARM MODE PORTBASE PERROR ADDRESS |
---|
[62ccd9b] | 36 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
| 37 | |
---|
| 38 | # Si se solicita, mostrar ayuda. |
---|
| 39 | if [ "$*" == "help" -o "$2" == "help" ]; then |
---|
| 40 | ogHelp "$FUNCNAME SENDPARTITION str_sessionSERVER str_device str_tools str_level" \ |
---|
| 41 | "$FUNCNAME RECEIVERPARTITION str_sessionCLIENT str_device str_tools str_level "\ |
---|
| 42 | "$FUNCNAME SENDFILE str_sessionSERVER str_file "\ |
---|
| 43 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
| 44 | "sessionServer syntax: portbase:ipCLIENT-1:ipCLIENT-2:ipCLIENT-N " \ |
---|
| 45 | "sessionServer example: 8000:172.17.36.11:172.17.36.12" \ |
---|
| 46 | "sessionClient syntax: portbase:ipMASTER " \ |
---|
| 47 | "sessionClient example: 8000:172.17.36.249 " |
---|
| 48 | return |
---|
| 49 | fi |
---|
| 50 | PERROR=0 |
---|
| 51 | |
---|
[eb9424f] | 52 | |
---|
[62ccd9b] | 53 | |
---|
| 54 | |
---|
| 55 | # Error si no se reciben $PARM parámetros. |
---|
| 56 | echo "$1" | grep "PARTITION" > /dev/null && PARM=5 || PARM=3 |
---|
| 57 | [ "$#" -eq "$PARM" ] || ogRaiseError $OG_ERR_FORMAT "sin parametros"|| return $? |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | # 1er param check |
---|
| 61 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
| 62 | |
---|
| 63 | # 2º param check |
---|
| 64 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
| 65 | |
---|
| 66 | ######### No controlamos el numero de elementos de la session unicast porque en el master es variable en numero |
---|
| 67 | #TODO: diferenciamos los paramatros especificos de la sessión unicast |
---|
| 68 | #SI: controlamos todos los parametros de la sessión unicast. |
---|
| 69 | #[ $MODE == "client" ] && SESSIONPARM=2 || SESSIONPARM=6 |
---|
| 70 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | #[[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
| 77 | PORTBASE=${SESSION[0]} |
---|
| 78 | ogCheckStringInGroup ${SESSION[0]} "8000 8001 8002 8003 8004 8005" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
| 79 | |
---|
| 80 | if [ $MODE == "server" ] |
---|
| 81 | then |
---|
| 82 | SIZEARRAY=${#SESSION[@]} |
---|
| 83 | for (( i = 1 ; i < $SIZEARRAY ; i++ )) |
---|
| 84 | do |
---|
| 85 | ADDRESS="$ADDRESS -O ${SESSION[$i]}:$PORTBASE" |
---|
| 86 | #echo " -O ${SESSION[$i]}:$PORTBASE" |
---|
| 87 | done |
---|
| 88 | |
---|
| 89 | else |
---|
| 90 | ADDRESS=${SESSION[1]}:${PORTBASE} |
---|
| 91 | fi |
---|
| 92 | |
---|
| 93 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
| 94 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
| 95 | DEVICE=$3 |
---|
| 96 | |
---|
| 97 | #4 y 5 param check . solo si es sobre particiones. |
---|
| 98 | if [ "$PARM" == "5" ] |
---|
| 99 | then |
---|
| 100 | # 4 param check |
---|
[eb9424f] | 101 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
[62ccd9b] | 102 | TOOL=$4 |
---|
[eb9424f] | 103 | ogCheckStringInGroup "$5" "lzop gzip LZOP GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
[62ccd9b] | 104 | LEVEL=$5 |
---|
| 105 | fi |
---|
| 106 | |
---|
[eb9424f] | 107 | [ "$PERROR" == "0" ] || ogRaiseError $OG_ERR_UCASTSYNTAXT " $PERROR" || return $? |
---|
[62ccd9b] | 108 | |
---|
| 109 | # Generamos la instrucción base de unicast -Envio,Recepcion- |
---|
| 110 | SYNTAXSERVER="mbuffer $ADDRESS" |
---|
| 111 | SYNTAXCLIENT="mbuffer -I $ADDRESS " |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | case "$1" in |
---|
| 115 | SENDPARTITION) |
---|
| 116 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
| 117 | echo "$PROG1 | $SYNTAXSERVER" |
---|
| 118 | ;; |
---|
| 119 | RECEIVERPARTITION) |
---|
| 120 | COMPRESSOR=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $1}'` |
---|
| 121 | TOOLS=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $NF}'` |
---|
| 122 | echo "$SYNTAXCLIENT | $COMPRESSOR | $TOOLS " |
---|
| 123 | ;; |
---|
| 124 | SENDFILE) |
---|
[eb9424f] | 125 | echo "$SYNTAXSERVER -i $3" |
---|
[62ccd9b] | 126 | ;; |
---|
| 127 | RECEIVERFILE) |
---|
[eb9424f] | 128 | echo "$SYNTAXCLIENT -i $3" |
---|
[62ccd9b] | 129 | ;; |
---|
| 130 | *) |
---|
| 131 | ;; |
---|
| 132 | esac |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | #/** |
---|
| 137 | # ogUcastSendPartition |
---|
| 138 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas usando UNICAST. |
---|
[eb9424f] | 139 | #@param 1 disk |
---|
| 140 | #@param 2 partition |
---|
| 141 | #@param 3 sesionUcast |
---|
| 142 | #@param 4 tool image |
---|
| 143 | #@param 5 tool compresor |
---|
[62ccd9b] | 144 | #@return |
---|
[eb9424f] | 145 | #@exception $OG_ERR_FORMAT |
---|
| 146 | #@exception $OG_ERR_UCASTSENDPARTITION |
---|
[62ccd9b] | 147 | #@note |
---|
[eb9424f] | 148 | #@todo: ogIsLocked siempre devuelve 1 |
---|
| 149 | #@version 1.0 - |
---|
| 150 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 151 | #@date 2011/03/09 |
---|
[62ccd9b] | 152 | #*/ ## |
---|
| 153 | |
---|
[eb9424f] | 154 | function ogUcastSendPartition () |
---|
[62ccd9b] | 155 | { |
---|
| 156 | |
---|
| 157 | # Variables locales |
---|
[1cd64e6] | 158 | local PART COMMAND RETVAL |
---|
[62ccd9b] | 159 | |
---|
| 160 | # Si se solicita, mostrar ayuda. |
---|
| 161 | if [ "$*" == "help" ]; then |
---|
| 162 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionUNICAST-SERVER tools compresor" \ |
---|
| 163 | "$FUNCNAME 1 1 8000:172.17.36.11:172.17.36.12 partclone lzop" |
---|
| 164 | return |
---|
| 165 | fi |
---|
| 166 | # Error si no se reciben 5 parámetros. |
---|
| 167 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 168 | #chequeamos la particion. |
---|
| 169 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 170 | |
---|
| 171 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 172 | ogUnmount $1 $2 |
---|
| 173 | |
---|
| 174 | #generamos la instrucción a ejecutar. |
---|
| 175 | COMMAND=`ogUcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
[eb9424f] | 176 | RETVAL=$? |
---|
| 177 | |
---|
| 178 | if [ "$RETVAL" -gt "0" ] |
---|
| 179 | then |
---|
| 180 | return $RETVAL |
---|
| 181 | else |
---|
| 182 | echo $COMMAND |
---|
| 183 | eval $COMMAND || ogRaiseError $OG_ERR_UCASTSENDPARTITION " "; return $? |
---|
| 184 | fi |
---|
| 185 | |
---|
[62ccd9b] | 186 | } |
---|
| 187 | |
---|
[1cd64e6] | 188 | |
---|
[62ccd9b] | 189 | #/** |
---|
| 190 | # ogUcastReceiverPartition |
---|
| 191 | #@brief Función para recibir directamente en la partición el contenido de un fichero imagen remoto enviado por UNICAST. |
---|
[eb9424f] | 192 | #@param 1 disk |
---|
| 193 | #@param 2 partition |
---|
| 194 | #@param 3 session unicast |
---|
[62ccd9b] | 195 | #@return |
---|
[eb9424f] | 196 | #@exception OG_ERR_FORMAT |
---|
| 197 | #@exception OG_ERR_UCASTRECEIVERPARTITION |
---|
[62ccd9b] | 198 | #@note |
---|
| 199 | #@todo: |
---|
[eb9424f] | 200 | #@version 1.0 - Integración para OpenGNSys. |
---|
| 201 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 202 | #@date 2011/03/09 |
---|
[62ccd9b] | 203 | #*/ ## |
---|
[eb9424f] | 204 | function ogUcastReceiverPartition () |
---|
[62ccd9b] | 205 | { |
---|
| 206 | # Variables locales |
---|
[1cd64e6] | 207 | local PART COMMAND RETVAL |
---|
[62ccd9b] | 208 | |
---|
| 209 | # Si se solicita, mostrar ayuda. |
---|
| 210 | if [ "$*" == "help" ]; then |
---|
| 211 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastCLIENT tools compresor" \ |
---|
| 212 | "$FUNCNAME 1 1 8000:ipMASTER partclone lzop" |
---|
| 213 | return |
---|
| 214 | fi |
---|
| 215 | # Error si no se reciben 5 parámetros. |
---|
| 216 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 217 | #chequeamos la particion. |
---|
| 218 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 219 | |
---|
| 220 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 221 | ogUnmount $1 $2 |
---|
| 222 | |
---|
| 223 | #generamos la instrucción a ejecutar. |
---|
| 224 | COMMAND=`ogUcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
[eb9424f] | 225 | RETVAL=$? |
---|
| 226 | |
---|
| 227 | if [ "$RETVAL" -gt "0" ] |
---|
| 228 | then |
---|
| 229 | return $RETVAL |
---|
| 230 | else |
---|
| 231 | echo $COMMAND |
---|
| 232 | eval $COMMAND || ogRaiseError $OG_ERR_UCASTRECEIVERPARTITION " "; return $? |
---|
| 233 | fi |
---|
[62ccd9b] | 234 | } |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | |
---|
[eb9424f] | 238 | #/** |
---|
| 239 | # ogUcastSendFile [ str_repo | int_ndisk int_npart ] /Relative_path_file sessionMulticast |
---|
| 240 | #@brief Envía un fichero por unicast ORIGEN(fichero) DESTINO(sessionmulticast) |
---|
| 241 | #@param (2 parámetros) $1 path_aboluto_fichero $2 sesionMcast |
---|
| 242 | #@param (3 parámetros) $1 Contenedor REPO|CACHE $2 path_absoluto_fichero $3 sesionMulticast |
---|
| 243 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero $4 sesionMulticast |
---|
| 244 | #@return |
---|
| 245 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 246 | #@exception $OG_ERR_NOTFOUND |
---|
| 247 | #@exception OG_ERR_UCASTSENDFILE |
---|
| 248 | #@note Requisitos: |
---|
| 249 | #@version 1.0 - Definición de Protocol.lib |
---|
| 250 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 251 | #@date 2010/05/09 |
---|
| 252 | #*/ ## |
---|
| 253 | # |
---|
| 254 | |
---|
| 255 | function ogUcastSendFile () |
---|
| 256 | { |
---|
| 257 | # Variables locales. |
---|
[1cd64e6] | 258 | local ARG ARGS SOURCE TARGET COMMAND DEVICE RETVAL LOGFILE |
---|
[eb9424f] | 259 | |
---|
| 260 | |
---|
| 261 | #ARGS usado para controlar ubicación de la sesion multicast |
---|
| 262 | # Si se solicita, mostrar ayuda. |
---|
| 263 | if [ "$*" == "help" ]; then |
---|
| 264 | ogHelp "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast(puerto:ip:ip:ip)" \ |
---|
| 265 | "$FUNCNAME 1 1 /aula1/winxp.img 8000:172.17.36.11:172.17.36.12" \ |
---|
| 266 | "$FUNCNAME REPO /aula1/ubuntu.iso sesionUcast" \ |
---|
| 267 | "$FUNCNAME CACHE /aula1/winxp.img sesionUcast" \ |
---|
| 268 | "$FUNCNAME /opt/opengnsys/images/aula1/hd500.vmx sesionUcast" |
---|
| 269 | return |
---|
| 270 | fi |
---|
| 271 | |
---|
| 272 | ARGS="$@" |
---|
| 273 | case "$1" in |
---|
| 274 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 275 | SOURCE=$(ogGetPath "$1") |
---|
| 276 | ARG=2 |
---|
| 277 | DEVICE="$1" |
---|
| 278 | ;; |
---|
| 279 | [1-9]*) # ndisco npartición. |
---|
| 280 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
| 281 | ARG=4 |
---|
| 282 | DEVICE="$1 $2 $3" |
---|
| 283 | ;; |
---|
| 284 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 285 | SOURCE=$(ogGetPath "$1" "$2") |
---|
| 286 | ARG=3 |
---|
| 287 | DEVICE="$1 $2 " |
---|
| 288 | ;; |
---|
| 289 | esac |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 293 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 294 | |
---|
| 295 | # Comprobar fichero origen |
---|
| 296 | ogGetPath $SOURCE &> /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $DEVICE not found" || return $? |
---|
| 297 | |
---|
| 298 | |
---|
| 299 | SESSION=${!ARG} |
---|
| 300 | |
---|
| 301 | #generamos la instrucción a ejecutar. |
---|
| 302 | COMMAND=`ogUcastSyntax "SENDFILE" "$SESSION" "$SOURCE"` |
---|
| 303 | RETVAL=$? |
---|
| 304 | |
---|
| 305 | if [ "$RETVAL" -gt "0" ] |
---|
| 306 | then |
---|
| 307 | return $RETVAL |
---|
| 308 | else |
---|
| 309 | echo $COMMAND |
---|
| 310 | eval $COMMAND || ogRaiseError $OG_ERR_UCASTSENDFILE " "; return $? |
---|
| 311 | fi |
---|
| 312 | |
---|
| 313 | } |
---|
| 314 | |
---|
[884ea85] | 315 | |
---|
| 316 | |
---|
| 317 | #/** |
---|
[761960be] | 318 | # ogMcastSyntax |
---|
[bd390f1] | 319 | #@brief Función para generar la instrucción de ejucción la transferencia de datos multicast |
---|
| 320 | #@param 1 Tipo de operación [ SENDPARTITION RECEIVERPARTITION SENDFILE RECEIVERFILE ] |
---|
| 321 | #@param 2 Sesión Mulicast |
---|
| 322 | #@param 3 Dispositivo (opción PARTITION) o fichero(opción FILE) que será enviado. |
---|
[884ea85] | 323 | #@param 4 Tools de clonación (opcion PARTITION) |
---|
| 324 | #@param 5 Tools de compresion (opcion PARTITION) |
---|
| 325 | #@return instrucción para ser ejecutada. |
---|
| 326 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[eb9424f] | 327 | #@exception OG_ERR_NOTEXEC |
---|
| 328 | #@exception OG_ERR_MCASTSYNTAXT |
---|
| 329 | #@note Requisitos: upd-cast 2009 o superior |
---|
[0fbc05e] | 330 | #@todo localvar check versionudp |
---|
[eb9424f] | 331 | #@version 1.0 - |
---|
[884ea85] | 332 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 333 | #@date 2010/05/09 |
---|
[6a25c5d] | 334 | #@version 2.0 - cambios en udp-receiver para permitir multicast entre subredes |
---|
| 335 | #@author Juan Carlos Garcia, Universidad de Zaragoza |
---|
| 336 | #@date 2015/11/17 |
---|
[0dcf48a] | 337 | #@version 1.1 - Control de errores en transferencia multicast (ticket #781) |
---|
| 338 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
| 339 | #@date 2017/04/20 |
---|
[884ea85] | 340 | #*/ ## |
---|
| 341 | # |
---|
| 342 | |
---|
[761960be] | 343 | function ogMcastSyntax () |
---|
[884ea85] | 344 | { |
---|
[bd390f1] | 345 | |
---|
[59e3998] | 346 | local ISUDPCAST PARM SESSION SESSIONPARM MODE PORTBASE PERROR |
---|
[bd390f1] | 347 | local METHOD ADDRESS BITRATE NCLIENTS MAXTIME CERROR |
---|
[761960be] | 348 | local TOOL LEVEL DEVICE MBUFFER SYNTAXSERVER SYNTAXCLIENT |
---|
[bd390f1] | 349 | |
---|
[884ea85] | 350 | # Si se solicita, mostrar ayuda. |
---|
| 351 | if [ "$*" == "help" -o "$2" == "help" ]; then |
---|
| 352 | ogHelp "$FUNCNAME SENDPARTITION str_sessionSERVER str_device str_tools str_level" \ |
---|
| 353 | "$FUNCNAME RECEIVERPARTITION str_sessionCLIENT str_device str_tools str_level "\ |
---|
| 354 | "$FUNCNAME SENDFILE str_sessionSERVER str_file "\ |
---|
[e8df652] | 355 | "$FUNCNAME RECEIVERFILE str_sessionCLIENT str_file " \ |
---|
[fa43c91] | 356 | "sessionServer syntax: portbase:method:mcastaddress:speed:nclients:ntimeWaitingUntilNclients " \ |
---|
| 357 | "sessionServer example: 9000:full-duplex|half-duplex|broadcast:239.194.17.36:80M:50:60 " \ |
---|
[0fbc05e] | 358 | "sessionClient syntax: portbase " \ |
---|
| 359 | "sessionClient example: 9000 " |
---|
[884ea85] | 360 | return |
---|
| 361 | fi |
---|
[59e3998] | 362 | PERROR=0 |
---|
[884ea85] | 363 | |
---|
[bd390f1] | 364 | #si no tenemos updcast o su version superior 2009 udpcast error. |
---|
| 365 | ISUDPCAST=$(udp-receiver --help 2>&1) |
---|
[eb9424f] | 366 | echo $ISUDPCAST | grep start-timeout > /dev/null || ogRaiseError $OG_ERR_NOTEXEC "upd-cast no existe o version antigua -requerida 2009-"|| return $? |
---|
[bd390f1] | 367 | |
---|
| 368 | |
---|
| 369 | # Error si no se reciben $PARM parámetros. |
---|
| 370 | echo "$1" | grep "PARTITION" > /dev/null && PARM=5 || PARM=3 |
---|
| 371 | [ "$#" -eq "$PARM" ] || ogRaiseError $OG_ERR_FORMAT "sin parametros"|| return $? |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | # 1er param check |
---|
[59e3998] | 375 | ogCheckStringInGroup "$1" "SENDPARTITION sendpartition RECEIVERPARTITION receiverpartition SENDFILE sendfile RECEIVERFILE receiverfile" || ogRaiseError $OG_ERR_FORMAT "1st param: $1" || PERROR=1 #return $? |
---|
[bd390f1] | 376 | |
---|
| 377 | # 2º param check |
---|
| 378 | echo "$1" | grep "SEND" > /dev/null && MODE=server || MODE=client |
---|
| 379 | |
---|
[59e3998] | 380 | #TODO: diferenciamos los paramatros especificos de la sessión multicast |
---|
| 381 | #SI: controlamos todos los parametros de la sessión multicast. |
---|
[56d2d6f] | 382 | [ $MODE == "client" ] && SESSIONPARM=1 || SESSIONPARM=6 |
---|
[bd390f1] | 383 | OIFS=$IFS; IFS=':' ; SESSION=($2); IFS=$OIFS |
---|
[59e3998] | 384 | |
---|
| 385 | |
---|
| 386 | [[ ${#SESSION[*]} == $SESSIONPARM ]] || ogRaiseError $OG_ERR_FORMAT "parametros session multicast no completa" || PERROR=2# return $? |
---|
| 387 | |
---|
| 388 | |
---|
[bd390f1] | 389 | #controlamos el PORTBASE de la sesion. Comun.- |
---|
| 390 | PORTBASE=${SESSION[0]} |
---|
[70498c1] | 391 | ogCheckStringInGroup ${SESSION[0]} "$(seq 9000 2 9050)" || ogRaiseError $OG_ERR_FORMAT "McastSession portbase ${SESSION[0]}" || PERROR=3 #return $? |
---|
[bd390f1] | 392 | if [ $MODE == "server" ] |
---|
| 393 | then |
---|
[59e3998] | 394 | 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] | 395 | METHOD=${SESSION[1]} |
---|
[59e3998] | 396 | ogCheckIpAddress ${SESSION[2]} || ogRaiseError $OG_ERR_FORMAT "McastSession address ${SESSION[2]}" || PERROR=5 #return $? |
---|
[bd390f1] | 397 | ADDRESS=${SESSION[2]} |
---|
[b8065e8] | 398 | ogCheckStringInReg ${SESSION[3]} "^[0-9]{1,3}\M$" || ogRaiseError $OG_ERR_FORMAT "McastSession bitrate ${SESSION[3]}" || PERROR=6 # return $? |
---|
[bd390f1] | 399 | BITRATE=${SESSION[3]} |
---|
[59e3998] | 400 | ogCheckStringInReg ${SESSION[4]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession nclients ${SESSION[4]}" || PERROR=7 # return $? |
---|
[bd390f1] | 401 | NCLIENTS=${SESSION[4]} |
---|
[59e3998] | 402 | ogCheckStringInReg ${SESSION[5]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "McastSession maxtime ${SESSION[5]}" || PERROR=8 # return $? |
---|
[bd390f1] | 403 | MAXTIME=${SESSION[5]} |
---|
| 404 | fi |
---|
[884ea85] | 405 | |
---|
[bd390f1] | 406 | #3er param check - que puede ser un dispositvo o un fichero. |
---|
[59e3998] | 407 | #ogGetPath "$3" > /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $3" || PERROR=9 #return $? |
---|
[bd390f1] | 408 | DEVICE=$3 |
---|
| 409 | |
---|
| 410 | #4 y 5 param check . solo si es sobre particiones. |
---|
| 411 | if [ "$PARM" == "5" ] |
---|
| 412 | then |
---|
| 413 | # 4 param check |
---|
[eb9424f] | 414 | ogCheckStringInGroup "$4" "partclone PARTCLONE partimage PARTIMAGE ntfsclone NTFSCLONE" || ogRaiseError $OG_ERR_NOTFOUND " herramienta $4 no soportada" || PERROR=10 #return $? |
---|
[bd390f1] | 415 | TOOL=$4 |
---|
[eb9424f] | 416 | ogCheckStringInGroup "$5" "lzop LZOP gzip GZIP 0 1" || ogRaiseError $OG_ERR_NOTFOUND " compresor $5 no valido" || PERROR=11 #return $? |
---|
[bd390f1] | 417 | LEVEL=$5 |
---|
| 418 | fi |
---|
| 419 | |
---|
[59e3998] | 420 | |
---|
[eb9424f] | 421 | if [ "$PERROR" != "0" ]; then |
---|
| 422 | ogRaiseError $OG_ERR_MCASTSYNTAXT " $PERROR"; return $? |
---|
| 423 | fi |
---|
| 424 | |
---|
[bd390f1] | 425 | |
---|
| 426 | # Valores estandar no configurables. |
---|
| 427 | CERROR="8x8/128" |
---|
[884ea85] | 428 | |
---|
| 429 | # opción del usuo de tuberia intermedia en memoria mbuffer. |
---|
[fa43c91] | 430 | which mbuffer > /dev/null && MBUFFER=" --pipe 'mbuffer -q -m 20M' " |
---|
[884ea85] | 431 | |
---|
| 432 | # Generamos la instrucción base de multicast -Envio,Recepcion- |
---|
[eb9424f] | 433 | SYNTAXSERVER="udp-sender $MBUFFER --nokbd --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" |
---|
[6a25c5d] | 434 | #SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE " |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | # Deteccion automatica de la subred del cliente para anadir la IP del repositorio a la orden udp-receiver en el caso de encontrarse en distinta subred del repo |
---|
| 438 | REPOIP="$(ogGetRepoIp)" |
---|
| 439 | CLIENTIP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}') |
---|
| 440 | MASCARA=`echo $CLIENTIP | cut -f2 -d/` |
---|
| 441 | CLIENTIP=`echo $CLIENTIP | cut -f1 -d/` |
---|
| 442 | RIPBT="" |
---|
| 443 | IPBT="" |
---|
| 444 | for (( i = 1 ; i < 5 ; i++ )) |
---|
| 445 | do |
---|
| 446 | RIP=`echo $REPOIP | cut -f$i -d.` |
---|
| 447 | RIP=`echo "$[$RIP + 256]"` |
---|
| 448 | RIPB="" |
---|
| 449 | while [ $RIP -gt 0 ] |
---|
| 450 | do |
---|
| 451 | let COCIENTE=$RIP/2 |
---|
| 452 | let RESTO=$RIP%2 |
---|
| 453 | RIPB=$RESTO$RIPB |
---|
| 454 | RIP=$COCIENTE |
---|
| 455 | done |
---|
| 456 | RIPB=`echo "$RIPB" | cut -c2-` |
---|
| 457 | RIPBT=$RIPBT$RIPB |
---|
| 458 | IP=`echo $CLIENTIP | cut -f$i -d.` |
---|
| 459 | IP=`echo "$[$IP + 256]"` |
---|
| 460 | IPB="" |
---|
| 461 | while [ $IP -gt 0 ] |
---|
| 462 | do |
---|
| 463 | let COCIENTE=$IP/2 |
---|
| 464 | let RESTO=$IP%2 |
---|
| 465 | IPB=$RESTO$IPB |
---|
| 466 | IP=$COCIENTE |
---|
| 467 | done |
---|
| 468 | IPB=`echo "$IPB" | cut -c2-` |
---|
| 469 | IPBT=$IPBT$IPB |
---|
| 470 | done |
---|
[0dcf48a] | 471 | MCASTWAIT=${MCASTWAIT:-120} |
---|
[6a25c5d] | 472 | REPOSUBRED=`echo $RIPBT | cut -c1-$MASCARA` |
---|
| 473 | CLIENTSUBRED=`echo $IPBT | cut -c1-$MASCARA` |
---|
| 474 | if [ $REPOSUBRED == $CLIENTSUBRED ]; then |
---|
[0dcf48a] | 475 | SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE --start-timeout $MCASTWAIT --receive-timeout $MCASTWAIT" |
---|
[6a25c5d] | 476 | else |
---|
[0dcf48a] | 477 | SYNTAXCLIENT="udp-receiver $MBUFFER --portbase $PORTBASE --mcast-rdv-address $REPOIP --start-timeout $MCASTWAIT --receive-timeout $MCASTWAIT" |
---|
[6a25c5d] | 478 | fi |
---|
| 479 | |
---|
| 480 | |
---|
[884ea85] | 481 | |
---|
| 482 | |
---|
| 483 | case "$1" in |
---|
[59e3998] | 484 | SENDPARTITION) |
---|
[761960be] | 485 | PROG1=`ogCreateImageSyntax $DEVICE " " $TOOL $LEVEL | awk -F"|" '{print $1 "|" $3}' | tr -d ">"` |
---|
| 486 | echo "$PROG1 | $SYNTAXSERVER" |
---|
[884ea85] | 487 | ;; |
---|
| 488 | RECEIVERPARTITION) |
---|
[761960be] | 489 | COMPRESSOR=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $1}'` |
---|
| 490 | TOOLS=`ogRestoreImageSyntax " " $DEVICE $TOOL $LEVEL | awk -F\| '{print $NF}'` |
---|
| 491 | echo "$SYNTAXCLIENT | $COMPRESSOR | $TOOLS " |
---|
[884ea85] | 492 | ;; |
---|
| 493 | SENDFILE) |
---|
[761960be] | 494 | echo "$SYNTAXSERVER --file $3" |
---|
[884ea85] | 495 | ;; |
---|
| 496 | RECEIVERFILE) |
---|
[761960be] | 497 | echo "$SYNTAXCLIENT --file $3" |
---|
[884ea85] | 498 | ;; |
---|
| 499 | *) |
---|
| 500 | ;; |
---|
| 501 | esac |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | #/** |
---|
| 507 | # ogMcastSendFile [ str_repo | int_ndisk int_npart ] /Relative_path_file sessionMulticast |
---|
| 508 | #@brief Envía un fichero por multicast ORIGEN(fichero) DESTINO(sessionmulticast) |
---|
| 509 | #@param (2 parámetros) $1 path_aboluto_fichero $2 sesionMcast |
---|
| 510 | #@param (3 parámetros) $1 Contenedor REPO|CACHE $2 path_absoluto_fichero $3 sesionMulticast |
---|
| 511 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero $4 sesionMulticast |
---|
| 512 | #@return |
---|
| 513 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[eb9424f] | 514 | #@exception $OG_ERR_NOTFOUND |
---|
| 515 | #@exception OG_ERR_MCASTSENDFILE |
---|
[884ea85] | 516 | #@note Requisitos: |
---|
[eb9424f] | 517 | #@version 1.0 - Definición de Protocol.lib |
---|
[884ea85] | 518 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 519 | #@date 2010/05/09 |
---|
| 520 | #*/ ## |
---|
| 521 | # |
---|
| 522 | |
---|
| 523 | function ogMcastSendFile () |
---|
| 524 | { |
---|
| 525 | # Variables locales. |
---|
[1cd64e6] | 526 | local ARGS ARG SOURCE TARGET COMMAND DEVICE RETVAL LOGFILE |
---|
[884ea85] | 527 | |
---|
[eb9424f] | 528 | #LOGFILE="/tmp/mcast.log" |
---|
| 529 | |
---|
| 530 | #ARGS usado para controlar ubicación de la sesion multicast |
---|
[884ea85] | 531 | # Si se solicita, mostrar ayuda. |
---|
| 532 | if [ "$*" == "help" ]; then |
---|
| 533 | ogHelp "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast" \ |
---|
| 534 | "$FUNCNAME 1 1 /aula1/winxp.img sesionMcast" \ |
---|
| 535 | "$FUNCNAME REPO /aula1/ubuntu.iso sesionMcast" \ |
---|
| 536 | "$FUNCNAME CACHE /aula1/winxp.img sesionMcast" \ |
---|
| 537 | "$FUNCNAME /opt/opengnsys/images/aula1/hd500.vmx sesionMcast" |
---|
| 538 | return |
---|
| 539 | fi |
---|
| 540 | |
---|
| 541 | ARGS="$@" |
---|
| 542 | case "$1" in |
---|
[bd390f1] | 543 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
[884ea85] | 544 | SOURCE=$(ogGetPath "$1") |
---|
[bd390f1] | 545 | ARG=2 |
---|
| 546 | DEVICE="$1" |
---|
[884ea85] | 547 | ;; |
---|
| 548 | [1-9]*) # ndisco npartición. |
---|
| 549 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
| 550 | ARG=4 |
---|
[bd390f1] | 551 | DEVICE="$1 $2 $3" |
---|
[884ea85] | 552 | ;; |
---|
| 553 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 554 | SOURCE=$(ogGetPath "$1" "$2") |
---|
| 555 | ARG=3 |
---|
[bd390f1] | 556 | DEVICE="$1 $2 " |
---|
[884ea85] | 557 | ;; |
---|
| 558 | esac |
---|
| 559 | |
---|
| 560 | |
---|
| 561 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 562 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[884ea85] | 563 | |
---|
| 564 | # Comprobar fichero origen |
---|
[bd390f1] | 565 | ogGetPath $SOURCE &> /dev/null || ogRaiseError $OG_ERR_NOTFOUND " device or file $DEVICE not found" || return $? |
---|
[884ea85] | 566 | |
---|
[eb9424f] | 567 | # eliminamos ficheros antiguos de log |
---|
| 568 | #rm $LOGFILE |
---|
| 569 | |
---|
[884ea85] | 570 | SESSION=${!ARG} |
---|
[eb9424f] | 571 | |
---|
| 572 | |
---|
| 573 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 574 | COMMAND=`ogMcastSyntax "SENDFILE" "$SESSION" "$SOURCE"` |
---|
[eb9424f] | 575 | RETVAL=$? |
---|
| 576 | |
---|
| 577 | if [ "$RETVAL" -gt "0" ] |
---|
| 578 | then |
---|
| 579 | return $RETVAL |
---|
| 580 | else |
---|
| 581 | echo $COMMAND |
---|
| 582 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDFILE " "; return $? |
---|
| 583 | #[ -s "$LOGFILE" ] || return 21 |
---|
| 584 | fi |
---|
| 585 | |
---|
[884ea85] | 586 | } |
---|
| 587 | |
---|
| 588 | |
---|
| 589 | |
---|
| 590 | #/** |
---|
| 591 | # ogMcastReceiverFile sesion Multicast [ str_repo | int_ndisk int_npart ] /Relative_path_file |
---|
| 592 | #@brief Recibe un fichero multicast ORIGEN(sesionmulticast) DESTINO(fichero) |
---|
| 593 | #@param (2 parámetros) $1 sesionMcastCLIENT $2 path_aboluto_fichero_destino |
---|
| 594 | #@param (3 parámetros) $1 sesionMcastCLIENT $2 Contenedor REPO|CACHE $3 path_absoluto_fichero_destino |
---|
| 595 | #@param (4 parámetros) $1 sesionMcastCLIENT $2 disk $3 particion $4 path_absoluto_fichero_destino |
---|
| 596 | #@return |
---|
| 597 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[eb9424f] | 598 | #@exception $OG_ERR_MCASTRECEIVERFILE |
---|
[884ea85] | 599 | #@note Requisitos: |
---|
[eb9424f] | 600 | #@version 1.0 - Definición de Protocol.lib |
---|
[884ea85] | 601 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 602 | #@date 2010/05/09 |
---|
| 603 | #*/ ## |
---|
| 604 | # |
---|
| 605 | |
---|
[eb9424f] | 606 | function ogMcastReceiverFile () |
---|
[884ea85] | 607 | { |
---|
| 608 | |
---|
| 609 | # Variables locales. |
---|
| 610 | local ARGS ARG TARGETDIR TARGETFILE |
---|
| 611 | |
---|
| 612 | |
---|
| 613 | # Si se solicita, mostrar ayuda. |
---|
| 614 | if [ "$*" == "help" ]; then |
---|
| 615 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_portMcast] [ [Relative_path_file] | [str_REPOSITORY path_file] | [int_ndisk int_npart path_file ] ]" \ |
---|
[bd390f1] | 616 | "$FUNCNAME 9000 /PS1_PH1.img" \ |
---|
| 617 | "$FUNCNAME 9000 CACHE /aula1/PS2_PH4.img" \ |
---|
| 618 | "$FUNCNAME 9000 1 1 /isos/linux.iso" |
---|
[884ea85] | 619 | return |
---|
| 620 | fi |
---|
| 621 | |
---|
| 622 | ARGS="$@" |
---|
| 623 | case "$2" in |
---|
| 624 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 625 | TARGETDIR=$(ogGetParentPath "$2") |
---|
[bd390f1] | 626 | ARG=2 |
---|
[884ea85] | 627 | ;; |
---|
| 628 | [1-9]*) # ndisco npartición. |
---|
| 629 | TARGETDIR=$(ogGetParentPath "$2" "$3" "$4") |
---|
[bd390f1] | 630 | ARG=4 |
---|
[884ea85] | 631 | ;; |
---|
| 632 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 633 | TARGETDIR=$(ogGetParentPath "$2" "$3") |
---|
[bd390f1] | 634 | ARG=3 |
---|
[884ea85] | 635 | ;; |
---|
| 636 | esac |
---|
| 637 | |
---|
| 638 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
[bd390f1] | 639 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
[884ea85] | 640 | |
---|
| 641 | #obtenemos el nombre del fichero a descargar. |
---|
| 642 | TARGETFILE=`basename ${!ARG}` |
---|
| 643 | |
---|
| 644 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 645 | COMMAND=`ogMcastSyntax RECEIVERFILE "$1" $TARGETDIR/$TARGETFILE ` |
---|
[eb9424f] | 646 | RETVAL=$? |
---|
| 647 | |
---|
| 648 | if [ "$RETVAL" -gt "0" ] |
---|
| 649 | then |
---|
| 650 | return $RETVAL |
---|
| 651 | else |
---|
| 652 | echo $COMMAND |
---|
[0dcf48a] | 653 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTRECEIVERFILE "$TARGETFILE"; return $? |
---|
[eb9424f] | 654 | #[ -s "$LOGFILE" ] || return 21 |
---|
| 655 | fi |
---|
[e8df652] | 656 | } |
---|
| 657 | |
---|
[1cd64e6] | 658 | |
---|
[e8df652] | 659 | #/** |
---|
| 660 | # ogMcastSendPartition |
---|
| 661 | #@brief Función para enviar el contenido de una partición a multiples particiones remotas. |
---|
[eb9424f] | 662 | #@param 1 disk |
---|
| 663 | #@param 2 partition |
---|
| 664 | #@param 3 session multicast |
---|
| 665 | #@param 4 tool clone |
---|
| 666 | #@param 5 tool compressor |
---|
[e8df652] | 667 | #@return |
---|
[eb9424f] | 668 | #@exception OG_ERR_FORMAT |
---|
| 669 | #@exception OG_ERR_MCASTSENDPARTITION |
---|
[e8df652] | 670 | #@note |
---|
| 671 | #@todo: ogIsLocked siempre devuelve 1. crear ticket |
---|
[eb9424f] | 672 | #@version 1.0 - Definición de Protocol.lib |
---|
| 673 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 674 | #@date 2010/05/09 |
---|
[e8df652] | 675 | #*/ ## |
---|
| 676 | |
---|
[eb9424f] | 677 | function ogMcastSendPartition () |
---|
[e8df652] | 678 | { |
---|
| 679 | |
---|
| 680 | # Variables locales |
---|
[1cd64e6] | 681 | local PART COMMAND RETVAL |
---|
[e8df652] | 682 | |
---|
| 683 | # Si se solicita, mostrar ayuda. |
---|
| 684 | if [ "$*" == "help" ]; then |
---|
| 685 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastSERVER tools compresor" \ |
---|
[fa43c91] | 686 | "$FUNCNAME 1 1 9000:full-duplex:239.194.37.31:50M:20:2 partclone lzop" |
---|
[e8df652] | 687 | return |
---|
| 688 | fi |
---|
| 689 | # Error si no se reciben 5 parámetros. |
---|
| 690 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 691 | #chequeamos la particion. |
---|
| 692 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 693 | |
---|
| 694 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 695 | ogUnmount $1 $2 |
---|
| 696 | |
---|
| 697 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 698 | COMMAND=`ogMcastSyntax SENDPARTITION "$3" $PART $4 $5` |
---|
[eb9424f] | 699 | RETVAL=$? |
---|
| 700 | |
---|
| 701 | if [ "$RETVAL" -gt "0" ] |
---|
| 702 | then |
---|
| 703 | return $RETVAL |
---|
| 704 | else |
---|
| 705 | echo $COMMAND |
---|
| 706 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDPARTITION " "; return $? |
---|
| 707 | fi |
---|
| 708 | |
---|
| 709 | |
---|
[e8df652] | 710 | } |
---|
| 711 | |
---|
| 712 | #/** |
---|
| 713 | # ogMcastReceiverPartition |
---|
| 714 | #@brief Función para recibir directamente en la partición el contenido de un fichero imagen remoto enviado por multicast. |
---|
[eb9424f] | 715 | #@param 1 disk |
---|
| 716 | #@param 2 partition |
---|
| 717 | #@param 3 session multicast |
---|
| 718 | #@param 4 tool clone |
---|
| 719 | #@param 5 tool compressor |
---|
[e8df652] | 720 | #@return |
---|
[eb9424f] | 721 | #@exception $OG_ERR_FORMAT |
---|
[e8df652] | 722 | #@note |
---|
| 723 | #@todo: |
---|
[eb9424f] | 724 | #@version 1.0 - Definición de Protocol.lib |
---|
| 725 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 726 | #@date 2010/05/09 |
---|
[e8df652] | 727 | #*/ ## |
---|
[eb9424f] | 728 | function ogMcastReceiverPartition () |
---|
[e8df652] | 729 | { |
---|
| 730 | # Variables locales |
---|
[1cd64e6] | 731 | local PART COMMAND RETVAL |
---|
[e8df652] | 732 | |
---|
| 733 | # Si se solicita, mostrar ayuda. |
---|
| 734 | if [ "$*" == "help" ]; then |
---|
| 735 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart SessionMulticastCLIENT tools compresor" \ |
---|
| 736 | "$FUNCNAME 1 1 9000 partclone lzop" |
---|
| 737 | return |
---|
| 738 | fi |
---|
| 739 | # Error si no se reciben 5 parámetros. |
---|
| 740 | [ "$#" == 5 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 741 | #chequeamos la particion. |
---|
| 742 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 743 | |
---|
| 744 | #ogIsLocked $1 $2 || ogRaiseError $OG_ERR_LOCKED "$1,$2" || return $? |
---|
| 745 | ogUnmount $1 $2 |
---|
| 746 | |
---|
| 747 | #generamos la instrucción a ejecutar. |
---|
[761960be] | 748 | COMMAND=`ogMcastSyntax RECEIVERPARTITION "$3" $PART $4 $5` |
---|
[eb9424f] | 749 | RETVAL=$? |
---|
| 750 | |
---|
| 751 | if [ "$RETVAL" -gt "0" ] |
---|
| 752 | then |
---|
| 753 | return $RETVAL |
---|
| 754 | else |
---|
| 755 | echo $COMMAND |
---|
| 756 | eval $COMMAND || ogRaiseError $OG_ERR_MCASTSENDPARTITION " "; return $? |
---|
| 757 | fi |
---|
| 758 | |
---|
[884ea85] | 759 | } |
---|
| 760 | |
---|
[bd390f1] | 761 | |
---|
[91c5326] | 762 | #/** |
---|
| 763 | # ogMcastRequest |
---|
| 764 | #@brief Función temporal para solicitar al ogRepoAux el envio de un fichero por multicast |
---|
| 765 | #@param 1 Fichero a enviar ubicado en el REPO. puede ser ruta absoluta o relatica a /opt/opengnsys/images |
---|
| 766 | #@param 2 PROTOOPT opciones protocolo multicast |
---|
| 767 | #@return |
---|
| 768 | #@exception |
---|
| 769 | #@note |
---|
| 770 | #@todo: |
---|
| 771 | #@version 1.0.5 |
---|
| 772 | #@author Antonio Doblas Viso, Universidad de Málaga |
---|
| 773 | #@date 2012/05/29 |
---|
[0dcf48a] | 774 | #@version 1.1 - Control de errores en transferencia multicast (ticket #781) |
---|
| 775 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
| 776 | #@date 2017/04/20 |
---|
[b3a5e02] | 777 | #@version 1.1 - Unidades organizativas con directorio de imágenes separado. (ticket #678) |
---|
| 778 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
| 779 | #@date 2017/06/23 |
---|
[91c5326] | 780 | #*/ ## |
---|
| 781 | function ogMcastRequest { |
---|
| 782 | # Variables locales |
---|
[b3a5e02] | 783 | local FILE PROTOOPT PORT PORTAUX REPOIP REPOPORTAUX REPEAT OGUNIT |
---|
| 784 | OGUNIT="$(df|awk '/ogimages/ {print $1}'|cut -d/ -f5)/" |
---|
| 785 | FILE="$OGUNIT$1" |
---|
[91c5326] | 786 | PROTOOPT="$2" |
---|
| 787 | |
---|
| 788 | #TODO AYUDA |
---|
| 789 | #TODO: CONTROL PARAMETROS |
---|
| 790 | |
---|
| 791 | PORT=$(echo $2 | cut -f1 -d":") |
---|
| 792 | let PORTAUX=$PORT+1 |
---|
| 793 | REPOIP=$(ogGetRepoIp) |
---|
| 794 | REPOPORTAUX=2009 |
---|
| 795 | REPEAT=0 |
---|
| 796 | until nmap -n -sU -p $PORTAUX $REPOIP | grep open |
---|
| 797 | do |
---|
[0dcf48a] | 798 | let REPEAT=$REPEAT+1 |
---|
| 799 | [ "$REPEAT" -lt 6 ] || ogRaiseError session log $OG_ERR_PROTOCOLJOINMASTER "MULTICAST \"$FILE\" \"$PROTOOPT\" $FILELIST" || return $? |
---|
[b3a5e02] | 800 | echo "$MSG_SCRIPTS_TASK_START : hose $REPOIP $REPOPORTAUX --out sh -c "echo -ne START_MULTICAST $FILE $2"" |
---|
[91c5326] | 801 | #update-cache: |
---|
| 802 | hose $REPOIP $REPOPORTAUX --out sh -c "echo -ne START_MULTICAST "$FILE" "$PROTOOPT"" |
---|
| 803 | #multicas-direct: hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST /$IMAGE.img $OPTPROTOCOLO" |
---|
| 804 | sleep 10 |
---|
| 805 | done |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | |
---|
[bd390f1] | 809 | ########################################## |
---|
[bba08bf] | 810 | ############## funciones torrent |
---|
[884ea85] | 811 | #/** |
---|
[2ab031e5] | 812 | # ogTorrentStart [ str_repo | int_ndisk int_npart ] Relative_path_file.torrent | SessionProtocol |
---|
[1678fa1] | 813 | #@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] | 814 | #@param str_pathDirectory str_Relative_path_file |
---|
| 815 | #@param int_disk int_partition str_Relative_path_file |
---|
| 816 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
[2ab031e5] | 817 | #@param (2 parámetros) $1 path_aboluto_fichero_torrent $2 Parametros_Session_Torrent |
---|
| 818 | #@param (3 parámetros) $1 Contenedor CACHE $2 path_absoluto_fichero_Torrent $3 Parametros_Session_Torrent |
---|
| 819 | #@param (4 parámetros) $1 disk $2 particion $3 path_absoluto_fichero_Torrent 4$ Parametros_Session_Torrent |
---|
| 820 | |
---|
[bba08bf] | 821 | #@return |
---|
| 822 | #@note |
---|
| 823 | #@todo: |
---|
| 824 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 825 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 826 | #@date |
---|
| 827 | #@version 0.2 - Chequeo del tamaño de imagen descargado. |
---|
| 828 | #@author Irina . Univesidad de Sevilla. |
---|
| 829 | #@date |
---|
[1678fa1] | 830 | #@version 0.3 - Control de los modos de operación, y estado de descarga. |
---|
| 831 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
| 832 | #@date |
---|
[2ab031e5] | 833 | #@version 0.4 - Enviadando señal (2) a ctorrent permiendo la comunicación final con tracker |
---|
| 834 | #@author Antonio J. Doblas Viso. Univesidad de Málaga. |
---|
| 835 | #@date |
---|
[bba08bf] | 836 | #*/ ## |
---|
[2ab031e5] | 837 | |
---|
[1678fa1] | 838 | #protocoloTORRENT mode:time |
---|
| 839 | #mode=seeder -> Dejar el equipo seedeando hasta que transcurra el tiempo indicado o un kill desde consola, |
---|
| 840 | #mode=peer -> seedear mientras descarga |
---|
| 841 | #mode=leecher -> NO seedear mientras descarga |
---|
| 842 | #time tiempo que una vez descargada la imagen queremos dejar al cliente como seeder. |
---|
[bba08bf] | 843 | |
---|
[eb9424f] | 844 | function ogTorrentStart () |
---|
[bba08bf] | 845 | { |
---|
[2ab031e5] | 846 | |
---|
| 847 | # Variables locales. |
---|
| 848 | local ARGS ARG TARGETDIR TARGETFILE SESSION ERROR |
---|
| 849 | ERROR=0 |
---|
| 850 | |
---|
| 851 | # Si se solicita, mostrar ayuda. |
---|
| 852 | if [ "$*" == "help" ]; then |
---|
| 853 | ogHelp "$FUNCNAME $FUNCNAME [ str_repo] [ [Relative_path_fileTORRENT] | [str_REPOSITORY path_fileTORRENT] | [int_ndisk int_npart path_fileTORRENT ] ] SessionTorrent" \ |
---|
| 854 | "$FUNCNAME CACHE /PS1_PH1.img.torrent seeder:10000" \ |
---|
| 855 | "$FUNCNAME /opt/opengnsys/cache/linux.iso peer:60" \ |
---|
| 856 | "$FUNCNAME 1 1 /linux.iso.torrent leecher:60" |
---|
| 857 | return |
---|
| 858 | fi |
---|
[bba08bf] | 859 | |
---|
| 860 | case "$1" in |
---|
| 861 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 862 | SOURCE=$(ogGetPath "$1") |
---|
[2ab031e5] | 863 | ARG=2 |
---|
[bba08bf] | 864 | ;; |
---|
| 865 | [1-9]*) # ndisco npartición. |
---|
| 866 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
[2ab031e5] | 867 | ARG=4 |
---|
[bba08bf] | 868 | ;; |
---|
[2ab031e5] | 869 | *) # Otros: Solo cache (no se permiten caminos relativos). |
---|
[bba08bf] | 870 | SOURCE=$(ogGetPath "$1" "$2" 2>/dev/null) |
---|
[2ab031e5] | 871 | ARG=3 |
---|
| 872 | ;; |
---|
[bba08bf] | 873 | esac |
---|
| 874 | |
---|
[2ab031e5] | 875 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 876 | [ $# == "$ARG" ] || ogRaiseError $OG_ERR_FORMAT "Parametros no admitidos"|| return $? |
---|
| 877 | |
---|
| 878 | #controlar source, que no se haga al repo. |
---|
| 879 | if [ $ARG == "3" ] |
---|
| 880 | then |
---|
| 881 | 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 $? |
---|
| 882 | fi |
---|
| 883 | if [ $ARG == "2" ] |
---|
| 884 | then |
---|
| 885 | if `ogCheckStringInReg "$1" "^/opt/opengnsys/images"` |
---|
| 886 | then |
---|
| 887 | 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" |
---|
| 888 | return $? |
---|
| 889 | fi |
---|
| 890 | fi |
---|
| 891 | |
---|
| 892 | #controlar el source, para que sea un torrent. |
---|
| 893 | ctorrent -x ${SOURCE} &> /dev/null; [ $? -eq 0 ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $? |
---|
[bba08bf] | 894 | |
---|
| 895 | TARGET=`echo $SOURCE | awk -F.torrent '{print $1}'` |
---|
| 896 | DIRSOURCE=`ogGetParentPath $SOURCE` |
---|
| 897 | cd $DIRSOURCE |
---|
| 898 | |
---|
[1678fa1] | 899 | |
---|
[bba08bf] | 900 | |
---|
[2ab031e5] | 901 | SESSION=${!ARG} |
---|
| 902 | OIFS=$IFS; IFS=':' ; SESSION=($SESSION); IFS=$OIFS |
---|
| 903 | [[ ${#SESSION[*]} == 2 ]] || ogRaiseError $OG_ERR_FORMAT "parametros session Torrent no completa: modo:tiempo" || ERROR=1# return $? |
---|
| 904 | #controlamos el modo de operación del cliente- |
---|
| 905 | ogCheckStringInGroup ${SESSION[0]} "seeder SEEDER peer PEER leecher LEECHER" || ogRaiseError $OG_ERR_FORMAT "valor modo Torrent no valido ${SESSION[0]}" || ERROR=1 #return $? |
---|
| 906 | MODE=${SESSION[0]} |
---|
| 907 | #contolamos el tiempo para el seeder o una vez descargada la imagen como peer o leecher. |
---|
| 908 | ogCheckStringInReg ${SESSION[1]} "^[0-9]{1,10}$" || ogRaiseError $OG_ERR_FORMAT "valor tiempo no valido ${SESSION[1]}" || ERROR=1 # return $? |
---|
| 909 | TIME=${SESSION[1]} |
---|
| 910 | # si ha habido error en el control de parametros error. |
---|
| 911 | [ "$ERROR" == "1" ] && return 1 |
---|
| 912 | |
---|
| 913 | |
---|
[761960be] | 914 | #SYNTAXSEEDER="echo MODE seeder ctorrent ; (sleep \$TIME && kill -9 \`pidof ctorrent\`) & ; ctorrent \${SOURCE}" |
---|
[1678fa1] | 915 | |
---|
| 916 | # si No fichero .bf, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial. |
---|
| 917 | if [ ! -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
[bba08bf] | 918 | then |
---|
[1678fa1] | 919 | echo "imagen ya descargada" |
---|
| 920 | case "$MODE" in |
---|
| 921 | seeder|SEEDER) |
---|
[2ab031e5] | 922 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
| 923 | (sleep $TIME && kill -2 `pidof ctorrent`) & |
---|
| 924 | ctorrent -f ${SOURCE} |
---|
[1678fa1] | 925 | esac |
---|
| 926 | return 0 |
---|
[bba08bf] | 927 | fi |
---|
| 928 | |
---|
[1678fa1] | 929 | #Si no existe bf ni fichero destino descarga inicial. |
---|
| 930 | if [ ! -f ${SOURCE}.bf -a ! -f ${TARGET} ] |
---|
| 931 | then |
---|
| 932 | OPTION=DOWNLOAD |
---|
| 933 | echo "descarga inicial" |
---|
| 934 | fi |
---|
| 935 | |
---|
| 936 | # Si fichero bf descarga anterior no completada -. |
---|
| 937 | if [ -f ${SOURCE}.bf -a -f ${TARGET} ] |
---|
| 938 | then |
---|
| 939 | echo Continuar con Descargar inicial no terminada. |
---|
| 940 | OPTION=DOWNLOAD |
---|
[bba08bf] | 941 | fi |
---|
| 942 | |
---|
[1678fa1] | 943 | if [ "$OPTION" == "DOWNLOAD" ] |
---|
[bba08bf] | 944 | then |
---|
[2ab031e5] | 945 | case "$MODE" in |
---|
| 946 | peer|PEER) |
---|
[9de72436] | 947 | echo "Donwloading Torrent as peer" ### echo "ctorrent -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100 $SOURCE -s $TARGET -b ${SOURCE}" |
---|
| 948 | # Creamos el fichero de resumen por defecto |
---|
| 949 | touch ${SOURCE}.bf |
---|
| 950 | # ctorrent controla otro fichero -b ${SOURCE}.bfog |
---|
| 951 | ctorrent -f -c -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bfog |
---|
[2ab031e5] | 952 | ;; |
---|
| 953 | leecher|LEECHER) |
---|
[cf211075] | 954 | echo "Donwloading Torrent as leecher" # echo "ctorrent ${SOURCE} -X 'sleep 30; kill -9 \$(pidof ctorrent)' -C 100 -U 0" |
---|
| 955 | ctorrent ${SOURCE} -X "sleep 30; kill -2 \$(pidof ctorrent)" -C 100 -U 0 |
---|
[2ab031e5] | 956 | ;; |
---|
| 957 | seeder|SEEDER) |
---|
| 958 | echo "MODE seeder ctorrent" #### ${SOURCE} -X 'sleep $TIME; kill -9 \$(pidof ctorrent)' -C 100" |
---|
[9de72436] | 959 | # Creamos el fichero de resumen por defecto |
---|
| 960 | touch ${SOURCE}.bf |
---|
| 961 | # ctorrent controla otro fichero -b ${SOURCE}.bfog |
---|
| 962 | ctorrent -f -c -X "sleep $TIME; kill -2 \$(pidof ctorrent)" -C 100 ${SOURCE} -s ${TARGET} -b ${SOURCE}.bfog |
---|
[2ab031e5] | 963 | ;; |
---|
| 964 | esac |
---|
| 965 | fi |
---|
[bba08bf] | 966 | cd /tmp |
---|
| 967 | } |
---|
| 968 | |
---|
[2ab031e5] | 969 | #/** |
---|
| 970 | # ogCreateTorrent [ str_repo | int_ndisk int_npart ] Relative_path_file |
---|
| 971 | #@brief Función para crear el fichero torrent. |
---|
| 972 | #@param str_pathDirectory str_Relative_path_file |
---|
| 973 | #@param int_disk int_partition str_Relative_path_file |
---|
| 974 | #@param str_REPOSITORY(CACHE - LOCAL) str_Relative_path_file |
---|
| 975 | #@return |
---|
| 976 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 977 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 978 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 979 | #@exception OG_ERR_NOTOS La partición no tiene instalado un sistema operativo. |
---|
| 980 | #@note |
---|
| 981 | #@version 0.1 - Integración para OpenGNSys. |
---|
| 982 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 983 | #@date |
---|
| 984 | #@version 0.2 - Integración para btlaunch. |
---|
| 985 | #@author Irina . Univesidad de Sevilla. |
---|
| 986 | #@date |
---|
| 987 | #*/ ## |
---|
| 988 | |
---|
[eb9424f] | 989 | function ogCreateTorrent () |
---|
[2ab031e5] | 990 | { |
---|
| 991 | # Variables locales. |
---|
[0fbc05e] | 992 | local ARGS ARG SOURCE EXT IPTORRENT |
---|
[2ab031e5] | 993 | |
---|
| 994 | |
---|
| 995 | # Si se solicita, mostrar ayuda. |
---|
| 996 | if [ "$*" == "help" ]; then |
---|
| 997 | ogHelp "$FUNCNAME" "$FUNCNAME [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file IpBttrack" \ "$FUNCNAME 1 1 /aula1/winxp 10.1.15.23" \ |
---|
| 998 | "$FUNCNAME REPO /aula1/winxp 10.1.15.45" |
---|
| 999 | |
---|
| 1000 | return |
---|
| 1001 | fi |
---|
| 1002 | |
---|
| 1003 | # Error si se quiere crear el fichero en cache y no existe |
---|
| 1004 | [ "$1" != "CACHE" ] || `ogFindCache >/dev/null` || ogRaiseError $OG_ERR_NOTFOUND "CACHE"|| return $? |
---|
| 1005 | |
---|
| 1006 | case "$1" in |
---|
| 1007 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 1008 | SOURCE=$(ogGetPath "$1.img") |
---|
| 1009 | ARG=2 |
---|
| 1010 | ;; |
---|
| 1011 | [1-9]*) # ndisco npartición. |
---|
| 1012 | SOURCE=$(ogGetPath "$1" "$2" "$3.img") |
---|
| 1013 | ARG=4 |
---|
| 1014 | ;; |
---|
| 1015 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[0fbc05e] | 1016 | EXT=$(ogGetImageType "$1" "$2") |
---|
| 1017 | SOURCE=$(ogGetPath "$1" "$2.$EXT") |
---|
[2ab031e5] | 1018 | ARG=3 |
---|
| 1019 | ;; |
---|
| 1020 | esac |
---|
| 1021 | |
---|
| 1022 | # Error si no se reciben los argumentos ARG necesarios según la opcion. |
---|
| 1023 | [ $# -eq "$ARG" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1024 | |
---|
| 1025 | |
---|
| 1026 | # Error si no existe la imagen |
---|
[1cd64e6] | 1027 | [ $SOURCE ] || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
[2ab031e5] | 1028 | |
---|
| 1029 | [ -r $SOURCE.torrent ] && mv "$SOURCE.torrent" "$SOURCE.torrent.ant" && echo "Esperamos que se refresque el servidor" && sleep 20 |
---|
| 1030 | |
---|
| 1031 | IPTORRENT="${!#}" |
---|
| 1032 | # Si ponemos el path completo cuando creamos el fichero torrent da error |
---|
| 1033 | cd `dirname $SOURCE` |
---|
| 1034 | echo ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
| 1035 | ctorrent -t `basename $SOURCE` -u http://$IPTORRENT:6969/announce -s $SOURCE.torrent |
---|
| 1036 | |
---|
| 1037 | } |
---|
| 1038 | |
---|
| 1039 | |
---|
[bba08bf] | 1040 | #/** |
---|
[914d834] | 1041 | # ogUpdateCacheIsNecesary [ str_repo ] Relative_path_file_OGIMG_with_/ |
---|
| 1042 | #@brief Comprueba que el fichero que se desea almacenar en la cache del cliente, no esta. |
---|
| 1043 | #@param 1 str_REPO |
---|
| 1044 | #@param 2 str_Relative_path_file_OGIMG_with_/ |
---|
[279dcb69] | 1045 | #@param 3 md5 to check: use full to check download image torrent |
---|
[1a2fa9d8] | 1046 | #@return 0 (true) cache sin imagen, SI es necesario actualizar el fichero. |
---|
| 1047 | #@return 1 (false) imagen en la cache, NO es necesario actualizar el fichero |
---|
[279dcb69] | 1048 | #@return >1 (false) error de sintaxis (TODO) |
---|
[884ea85] | 1049 | #@note |
---|
[914d834] | 1050 | #@todo: Proceso en el caso de que el fichero tenga el mismo nombre, pero su contenido sea distinto. |
---|
| 1051 | #@todo: Se dejan mensajes mientras se confirma su funcionamiento. |
---|
| 1052 | #@version 0.1 - Integracion para OpenGNSys. |
---|
| 1053 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
[884ea85] | 1054 | #@date |
---|
[dfcc55a] | 1055 | #@version 1.6 - gestiona ficheros hash full.sum (TORRENT) y .sum (MULTICAST) |
---|
[279dcb69] | 1056 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 1057 | #@date |
---|
[884ea85] | 1058 | #*/ ## |
---|
[914d834] | 1059 | function ogUpdateCacheIsNecesary () |
---|
[884ea85] | 1060 | { |
---|
[279dcb69] | 1061 | #echo "admite full check con 3param TORRENT" |
---|
[884ea85] | 1062 | # Variables locales. |
---|
[1cd64e6] | 1063 | local ERROR SOURCE CACHE FILESOURCE MD5SOURCE FILETARGET MD5TARGET |
---|
[914d834] | 1064 | ERROR=0 |
---|
[884ea85] | 1065 | |
---|
| 1066 | # Si se solicita, mostrar ayuda. |
---|
| 1067 | if [ "$*" == "help" ]; then |
---|
[dfcc55a] | 1068 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo relative_path_image [protocol|FULL]" \ |
---|
| 1069 | "$FUNCNAME REPO /PS1_PH1.img UNICAST" \ |
---|
| 1070 | "$FUNCNAME REPO /ogclient.sqfs FULL" |
---|
[914d834] | 1071 | |
---|
[884ea85] | 1072 | return |
---|
| 1073 | fi |
---|
| 1074 | |
---|
[936b15e] | 1075 | #Control de la cache |
---|
[dfcc55a] | 1076 | ogFindCache &>/dev/null || return $(ogRaiseError $OG_ERR_NOTCACHE; echo $?) |
---|
[884ea85] | 1077 | |
---|
[279dcb69] | 1078 | #Control de parametros: ahora admite tres. |
---|
[dfcc55a] | 1079 | [ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_repo relative_path_image [protocol|FULL]"; echo $?) |
---|
[279dcb69] | 1080 | |
---|
[cc42233] | 1081 | ogCheckStringInGroup "$1" "REPO repo" || return $(ogRaiseError $OG_ERR_NOTFOUND " $1 $2"; echo $?) |
---|
| 1082 | FILESOURCE=`ogGetPath $1 $2` || return $(ogRaiseError $OG_ERR_NOTFOUND " $1 $2"; echo $?) |
---|
[884ea85] | 1083 | |
---|
[1a2fa9d8] | 1084 | #echo "paso 1. si no existe la imagen, confirmar que es necesario actualizar la cache." |
---|
[cc42233] | 1085 | FILETARGET=`ogGetPath CACHE $2` |
---|
[914d834] | 1086 | if [ -z $FILETARGET ] |
---|
| 1087 | then |
---|
[936b15e] | 1088 | # borramos el fichero bf del torrent, en el caso de que se hubiese quedado de algun proceso fallido |
---|
[1a2fa9d8] | 1089 | ogGetPath CACHE "/$2.torrent.bf" && ogDeleteFile CACHE "/$2.torrent.bf" &> /dev/null |
---|
| 1090 | ogGetPath CACHE "/$2.sum" && ogDeleteFile CACHE "/$2.sum" &> /dev/null |
---|
| 1091 | ogGetPath CACHE "/$2.full.sum" && ogDeleteFile CACHE "/$2.full.sum" &> /dev/null |
---|
| 1092 | echo "TRUE(0), es necesario actualizar. Paso 1, la cache no contiene esa imagen " |
---|
[936b15e] | 1093 | return 0 |
---|
[884ea85] | 1094 | fi |
---|
[cc42233] | 1095 | |
---|
| 1096 | #echo "Paso 2. Comprobamos que la imagen no estuviese en un proceso previo torrent" |
---|
[914d834] | 1097 | if ogGetPath $FILETARGET.torrent.bf > /dev/null |
---|
| 1098 | then |
---|
[1a2fa9d8] | 1099 | #TODO: comprobar los md5 del fichero .torrent para asegurarnos que la imagen a descarga es la misma. |
---|
| 1100 | echo "TRUE(0), es necesario actualizar. Paso 2, la imagen esta en un estado de descarga torrent interrumpido" |
---|
[914d834] | 1101 | return 0 |
---|
[884ea85] | 1102 | fi |
---|
| 1103 | |
---|
[914d834] | 1104 | ## En este punto la imagen en el repo y en la cache se llaman igual, |
---|
[1a2fa9d8] | 1105 | #echo "paso 4. Obtener los md5 del fichero imagen en la cacha segun PROTOCOLO $3" |
---|
[dfcc55a] | 1106 | case "${3^^}" in |
---|
| 1107 | FULL|TORRENT) |
---|
[279dcb69] | 1108 | #Buscamos MD5 en el REPO SOURCE |
---|
| 1109 | if [ -f $FILESOURCE.full.sum ] |
---|
| 1110 | then |
---|
| 1111 | MD5SOURCE=$(cat $FILESOURCE.full.sum) |
---|
| 1112 | else |
---|
| 1113 | MD5SOURCE=$(ogCalculateFullChecksum $FILESOURCE) |
---|
| 1114 | fi |
---|
| 1115 | # Generamos el MD5 (full) en la CACHE |
---|
| 1116 | [ ! -f $FILETARGET.full.sum ] && ogCalculateFullChecksum $FILETARGET > $FILETARGET.full.sum |
---|
| 1117 | MD5TARGET=$(cat $FILETARGET.full.sum) |
---|
| 1118 | # Generamos el MD5 (little) en la CACHE para posteriores usos del protocolo MULTICAST |
---|
| 1119 | [ ! -f $FILETARGET.sum ] && ogCalculateChecksum $FILETARGET > $FILETARGET.sum |
---|
| 1120 | ;; |
---|
| 1121 | *) |
---|
| 1122 | #Buscamos MD5 en el REPO SOURCE |
---|
| 1123 | if [ -f $FILESOURCE.sum ] |
---|
| 1124 | then |
---|
| 1125 | MD5SOURCE=$(cat $FILESOURCE.sum) |
---|
| 1126 | else |
---|
| 1127 | MD5SOURCE=$(ogCalculateChecksum $FILESOURCE) |
---|
| 1128 | fi |
---|
| 1129 | # Generamos el MD5 (little) en la CACHE |
---|
| 1130 | [ ! -f $FILETARGET.sum ] && ogCalculateChecksum $FILETARGET > $FILETARGET.sum |
---|
| 1131 | MD5TARGET=$(cat $FILETARGET.sum) |
---|
[dfcc55a] | 1132 | #Generamos o copiamos MD5 (full) en la CACHE para posteriores usos con Torrent |
---|
| 1133 | # Si no existe el full.sum y si existe el .sum es porque el upateCACHE multicast o unicast ha sido correcto. |
---|
| 1134 | if [ ! -f $FILETARGET.full.sum -a $FILETARGET.sum ] |
---|
| 1135 | then |
---|
| 1136 | if [ -f $FILESOURCE.full.sum ] |
---|
| 1137 | then |
---|
| 1138 | #Existe el .full.sum en REPO realizamos COPIA |
---|
| 1139 | cp $FILESOURCE.full.sum $FILETARGET.full.sum |
---|
| 1140 | else |
---|
| 1141 | #No existe .full.sum no en REPO LO GENERAMOS en la cache: situacion dificil que ocurra |
---|
| 1142 | ogCalculateFullChecksum $FILETARGET > $FILETARGET.full.sum |
---|
| 1143 | fi |
---|
| 1144 | fi |
---|
| 1145 | |
---|
[279dcb69] | 1146 | esac |
---|
[bd390f1] | 1147 | |
---|
[1a2fa9d8] | 1148 | #echo "Paso 5. comparar los md5" |
---|
[914d834] | 1149 | if [ "$MD5SOURCE" == "$MD5TARGET" ] |
---|
[279dcb69] | 1150 | then |
---|
[1a2fa9d8] | 1151 | echo "FALSE (1), No es neceario actualizar. Paso5.A la imagen esta en cache" |
---|
[936b15e] | 1152 | return 1 |
---|
[914d834] | 1153 | else |
---|
[1a2fa9d8] | 1154 | echo "imagen en cache distinta, borramos la imagen anterior" |
---|
| 1155 | rm -f $FILETARGET $FILETARGET.sum $FILETARGET.torrent $FILETARGET.full.sum |
---|
| 1156 | echo "TRUE (0), Si es necesario actualizar." |
---|
[936b15e] | 1157 | return 0 |
---|
[914d834] | 1158 | fi |
---|
| 1159 | } |
---|
[bd390f1] | 1160 | |
---|