[914d834] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Scirpt para la actualizacion de datos en la cache. |
---|
| 4 | # Versión: 0.9.1, 2008/03/17, - integracion eac |
---|
| 5 | # Versión: 0.9.2, 2010/07/27, - integracion opengnsys |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | #1 REPO |
---|
| 10 | #2 nombre del fichero con su extension, tipo /imagen1.img o /ubuntu.iso |
---|
| 11 | #3 Protocolo TORRENT | MULTICAST | UNICAST |
---|
| 12 | #4 opciones protocolo |
---|
| 13 | #5 opciones de update cache |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | PROG="$(basename $0)" |
---|
| 17 | if [ $# -lt 4 ]; then |
---|
| 18 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE" |
---|
| 19 | exit $? |
---|
| 20 | fi |
---|
| 21 | |
---|
| 22 | REPOSITORIO=$1 |
---|
| 23 | PROTOCOLO=$3 |
---|
| 24 | OPTPROTOCOLO=$4 |
---|
[9b6e62c] | 25 | REPOIP=$(ogGetRepoIp) |
---|
| 26 | echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO |
---|
[914d834] | 27 | # Si el repositorio local CACHE no existe salimos. |
---|
| 28 | if ! $(ogFindCache >/dev/null); then |
---|
[5c44f86] | 29 | ogRaiseError $OG_ERR_NOTCACHE "CACHE" |
---|
[914d834] | 30 | exit $? |
---|
| 31 | fi |
---|
| 32 | |
---|
[9b6e62c] | 33 | #Comprobamos si Actualizacion - existe una imagen con igual nombre pero distinto sum- |
---|
| 34 | #TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum- |
---|
| 35 | ogUpdateCacheIsNecesary $1 $2 || exit 0 |
---|
[914d834] | 36 | |
---|
| 37 | CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`) |
---|
| 38 | FILESIZE=$(ls -sk $(ogGetPath $1 $2) | cut -f1 -d" ") |
---|
| 39 | |
---|
| 40 | if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] |
---|
| 41 | then |
---|
| 42 | echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE" |
---|
[5c44f86] | 43 | ogRaiseError $OG_ERR_CACHESIZE "CACHE" |
---|
| 44 | exit $? |
---|
[914d834] | 45 | fi |
---|
| 46 | |
---|
| 47 | ogUpdateCacheIsNecesary $1 $2 || exit 0 |
---|
| 48 | |
---|
| 49 | ogMountCache |
---|
| 50 | |
---|
| 51 | ## Si no existe, crear subdirectorio para el fichero en la cache. |
---|
| 52 | IMGDIR=$(ogGetParentPath "$1" "/$2") |
---|
| 53 | if [ $? != 0 ]; then |
---|
| 54 | echo "[5] Crear subdirectorio del fichero \"$2 $(dirname "$2")." |
---|
| 55 | ogMakeDir "CACHE" $(dirname "/$2") |
---|
| 56 | IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $? |
---|
| 57 | fi |
---|
| 58 | |
---|
| 59 | |
---|
[9b6e62c] | 60 | |
---|
| 61 | |
---|
[914d834] | 62 | case "$PROTOCOLO" in |
---|
| 63 | torrent | TORRENT ) |
---|
[9b6e62c] | 64 | echo "ogCopyFile $1 $2.torrent absolute $OGCAC$OGIMG" |
---|
| 65 | ogCopyFile $1 $2.torrent $OGCAC$OGIMG |
---|
| 66 | #TODO: comprobar que el tracker definido en el fichero es correcto. |
---|
| 67 | #TODO comprobar que el fichero torrent está en cache |
---|
| 68 | echo "ogTorrentStart CACHE $2.torrent $4" |
---|
| 69 | ogTorrentStart CACHE $2.torrent $4 |
---|
[914d834] | 70 | ;; |
---|
| 71 | multicast | MULTICAST ) |
---|
[9b6e62c] | 72 | echo "determinando puerto principal y auxiliar." |
---|
| 73 | PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":") |
---|
| 74 | let PORTAUX=$PORT+1 |
---|
[e8460d2] | 75 | #TODO: ticket 379 |
---|
| 76 | NUMBER=$[ ( $RANDOM % 30 ) + 1 ] |
---|
| 77 | sleep $NUMBER |
---|
| 78 | #FIN TODO |
---|
[9b6e62c] | 79 | echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) " |
---|
| 80 | if (nmap -n -sU -p $PORTAUX $REPOIP | grep open) |
---|
| 81 | then |
---|
| 82 | ogMcastReceiverFile $PORT CACHE $2 |
---|
| 83 | else |
---|
[e8460d2] | 84 | # TODO ticket 379 Realizar la petición basada en identificador de operacion |
---|
[9b6e62c] | 85 | echo "solicita la apertura: hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"" |
---|
| 86 | hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO" |
---|
| 87 | #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2" |
---|
[e8460d2] | 88 | sleep 10 |
---|
| 89 | if (nmap -n -sU -p $PORTAUX $REPOIP | grep open) |
---|
| 90 | then |
---|
| 91 | ogMcastReceiverFile $PORT CACHE $2 |
---|
| 92 | else |
---|
| 93 | echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO" |
---|
| 94 | exit 1 |
---|
| 95 | fi |
---|
| 96 | fi |
---|
[914d834] | 97 | ;; |
---|
| 98 | unicast | UNICAST ) |
---|
[9b6e62c] | 99 | echo "unicast" |
---|
[5c44f86] | 100 | ogCopyFile $1 $2 $OGCAC$OGIMG |
---|
[914d834] | 101 | ;; |
---|
| 102 | esac |
---|
| 103 | |
---|
| 104 | if ogUpdateCacheIsNecesary $1 $2 |
---|
| 105 | then |
---|
| 106 | echo "algo ha fallado" |
---|
| 107 | exit 1 |
---|
| 108 | else |
---|
| 109 | echo "updateCache ok" |
---|
| 110 | exit 0 |
---|
| 111 | fi |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | # |
---|