1 | #!/bin/bash |
---|
2 | |
---|
3 | |
---|
4 | #/** |
---|
5 | # updateCache |
---|
6 | #@brief Actualiza la cache del cliente con imagen o fichero iso. |
---|
7 | #@param 1 REPO Origen del fichero. -accesible por nfs-samba- |
---|
8 | #@param 2 str_fichero.{img iso} nombre del fichero a actualizar. |
---|
9 | #@param 3 str_protoco. TORRENT | MULTICAST | UNICAST. |
---|
10 | #@param 4 str_opcionesprotocolo |
---|
11 | #@param 4 str_opcionesupdatecache |
---|
12 | #@ejemplo: oneRemoteFromMaster 172.17.36.11 CACHE /imagen1 9000:full-duplex:239.194.17.36:70M:50:100 1 1 partclone lzop |
---|
13 | #@return |
---|
14 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
15 | #@note |
---|
16 | #@todo: |
---|
17 | #@version 0.9.1 - integracion EAC |
---|
18 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
19 | #@date 2008/03/17 |
---|
20 | #@version 0.9.2 - integracion OpenGnsys |
---|
21 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
22 | #@date 2010/07/27 |
---|
23 | #*/ ## |
---|
24 | |
---|
25 | PROG="$(basename $0)" |
---|
26 | if [ $# -lt 3 ]; then |
---|
27 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE" |
---|
28 | exit $? |
---|
29 | fi |
---|
30 | |
---|
31 | REPOSITORIO=$1 |
---|
32 | PROTOCOLO=$3 |
---|
33 | OPTPROTOCOLO=$4 |
---|
34 | REPOIP=$(ogGetRepoIp) |
---|
35 | echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO |
---|
36 | # Si el repositorio local CACHE no existe salimos. |
---|
37 | if ! $(ogFindCache >/dev/null); then |
---|
38 | ogRaiseError $OG_ERR_NOTCACHE "CACHE" |
---|
39 | exit $? |
---|
40 | fi |
---|
41 | |
---|
42 | #Comprobamos si Actualizacion - existe una imagen con igual nombre pero distinto sum- |
---|
43 | #TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum- |
---|
44 | ogUpdateCacheIsNecesary $1 $2; RETVAL=$? |
---|
45 | # si RETVAL=0 => actualizamos si RETVAL=1 no actaulizasmo-exit 0 || si RETVAL>2 exit 1 |
---|
46 | [ "$RETVAL" == "1" ] && exit 0 |
---|
47 | [ "$RETVAL" -gt "1" ] && exit 1 |
---|
48 | |
---|
49 | |
---|
50 | CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`) |
---|
51 | FILESIZE=$(ls -sk $(ogGetPath $1 $2) | cut -f1 -d" ") |
---|
52 | |
---|
53 | if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] |
---|
54 | then |
---|
55 | echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE" |
---|
56 | ogRaiseError $OG_ERR_CACHESIZE "CACHE" |
---|
57 | exit $? |
---|
58 | fi |
---|
59 | |
---|
60 | ogUpdateCacheIsNecesary $1 $2; RETVAL=$? |
---|
61 | # si RETVAL=0 => actualizamos si RETVAL=1 no actaulizasmo-exit 0 || si RETVAL>2 exit 1 |
---|
62 | [ "$RETVAL" == "1" ] && exit 0 |
---|
63 | [ "$RETVAL" -gt "1" ] && exit 1 |
---|
64 | |
---|
65 | ogMountCache |
---|
66 | |
---|
67 | ## Si no existe, crear subdirectorio para el fichero en la cache. |
---|
68 | IMGDIR=$(ogGetParentPath "$1" "/$2") |
---|
69 | if [ $? != 0 ]; then |
---|
70 | echo "[5] Crear subdirectorio del fichero \"$2 $(dirname "$2")." |
---|
71 | ogMakeDir "CACHE" $(dirname "/$2") |
---|
72 | IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $? |
---|
73 | fi |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | case "$PROTOCOLO" in |
---|
79 | torrent | TORRENT ) |
---|
80 | echo "ogCopyFile $1 $2.torrent absolute $OGCAC$OGIMG" |
---|
81 | ogCopyFile $1 $2.torrent $OGCAC$OGIMG |
---|
82 | #TODO: comprobar que el tracker definido en el fichero es correcto. |
---|
83 | #TODO comprobar que el fichero torrent está en cache |
---|
84 | echo "ogTorrentStart CACHE $2.torrent $4" |
---|
85 | ogTorrentStart CACHE $2.torrent $4 |
---|
86 | ;; |
---|
87 | multicast | MULTICAST ) |
---|
88 | echo "determinando puerto principal y auxiliar." |
---|
89 | PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":") |
---|
90 | let PORTAUX=$PORT+1 |
---|
91 | #TODO: ticket 379 |
---|
92 | NUMBER=$[ ( $RANDOM % 30 ) + 1 ] |
---|
93 | sleep $NUMBER |
---|
94 | #FIN TODO |
---|
95 | echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) " |
---|
96 | if (nmap -n -sU -p $PORTAUX $REPOIP | grep open) |
---|
97 | then |
---|
98 | ogMcastReceiverFile $PORT CACHE $2 |
---|
99 | else |
---|
100 | # TODO ticket 379 Realizar la petición basada en identificador de operacion |
---|
101 | echo "solicita la apertura: hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"" |
---|
102 | hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO" |
---|
103 | #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2" |
---|
104 | sleep 10 |
---|
105 | if (nmap -n -sU -p $PORTAUX $REPOIP | grep open) |
---|
106 | then |
---|
107 | ogMcastReceiverFile $PORT CACHE $2 |
---|
108 | else |
---|
109 | echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO" |
---|
110 | exit 1 |
---|
111 | fi |
---|
112 | fi |
---|
113 | ;; |
---|
114 | unicast | UNICAST ) |
---|
115 | echo "unicast" |
---|
116 | ogCopyFile $1 $2 $OGCAC$OGIMG |
---|
117 | ;; |
---|
118 | esac |
---|
119 | |
---|
120 | |
---|
121 | ogUpdateCacheIsNecesary $1 $2; RETVAL=$? |
---|
122 | # si RETVAL=0 => actualizamos si RETVAL=1 no actaulizasmo-exit 0 || si RETVAL>2 exit 1 |
---|
123 | [ "$RETVAL" == "0" ] && exit 1 |
---|
124 | [ "$RETVAL" == "1" ] && exit 0 |
---|
125 | [ "$RETVAL" -gt "1" ] && exit 1 |
---|