source: client/shared/scripts/updateCache @ 3cedc88

Last change on this file since 3cedc88 was e8460d2, checked in by adv <adv@…>, 14 years ago

version1.0 #369 controlando errores de inicio de multicast

git-svn-id: https://opengnsys.es/svn/branches/version1.0@1863 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 3.2 KB
Line 
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
16PROG="$(basename $0)"
17if [ $# -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 $?
20fi
21
22REPOSITORIO=$1
23PROTOCOLO=$3
24OPTPROTOCOLO=$4
25REPOIP=$(ogGetRepoIp)
26echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
27# Si el repositorio local CACHE no existe salimos.
28if ! $(ogFindCache >/dev/null); then
29        ogRaiseError $OG_ERR_NOTFOUND "CACHE"
30        exit $?
31fi
32
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-
35ogUpdateCacheIsNecesary $1 $2 || exit 0
36
37CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`)
38FILESIZE=$(ls -sk $(ogGetPath $1 $2) | cut -f1 -d" ")
39
40if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] 
41then
42        echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE"
43        exit 1
44fi
45
46ogUpdateCacheIsNecesary $1 $2 || exit 0
47
48ogMountCache
49
50## Si no existe, crear subdirectorio para el fichero en la cache.
51IMGDIR=$(ogGetParentPath "$1" "/$2")
52if [ $? != 0 ]; then
53    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
54   ogMakeDir "CACHE" $(dirname "/$2")
55   IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $?
56fi
57
58
59
60
61case "$PROTOCOLO" in
62        torrent | TORRENT )
63                echo "ogCopyFile $1 $2.torrent absolute $OGCAC$OGIMG"
64                ogCopyFile $1 $2.torrent $OGCAC$OGIMG
65                #TODO: comprobar que el tracker definido en el fichero es correcto.
66        #TODO comprobar que el fichero torrent está en cache
67                echo "ogTorrentStart CACHE $2.torrent $4"
68                ogTorrentStart CACHE $2.torrent $4
69        ;;
70        multicast | MULTICAST )
71                echo "determinando puerto principal y auxiliar."
72                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
73                let PORTAUX=$PORT+1
74        #TODO: ticket 379
75                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
76                sleep $NUMBER
77                #FIN TODO
78                echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) "
79                if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
80                then
81                        ogMcastReceiverFile $PORT CACHE $2
82                else
83                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
84                        echo "solicita la apertura:  hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO""
85                        hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
86                        #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2"
87                        sleep 10
88                        if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
89                        then
90                                ogMcastReceiverFile $PORT CACHE $2         
91                        else
92                            echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
93                            exit 1
94                        fi
95                fi     
96        ;;
97        unicast | UNICAST )
98                echo "unicast"
99        ;;
100esac
101
102if ogUpdateCacheIsNecesary $1 $2
103then
104        echo "algo ha fallado"
105        exit 1
106else
107        echo "updateCache ok"
108        exit 0
109fi
110
111
112
113#
Note: See TracBrowser for help on using the repository browser.