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

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 3f73876 was a323383, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: Usar camino relativo al repositorio para restaurar fichero por Multicast; entrecomillado de parámetros para permitir espacios en la interfaz de restauración (modifica #448).

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

  • Property mode set to 100755
File size: 4.2 KB
Line 
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   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#@version 1.0.1 - Control de espacio requerido
24#@author  Antonio J.Doblas Viso
25#@date   2011-05-10
26#*/ ##
27
28PROG="$(basename $0)"
29if [ $# -lt 3 ]; then
30    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE"
31    exit $?
32fi
33
34REPOSITORIO="$1"
35PROTOCOLO="$3"
36OPTPROTOCOLO="$4"
37REPOIP=$(ogGetRepoIp)
38echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
39# Si el repositorio local CACHE no existe salimos.
40if ! $(ogFindCache >/dev/null); then
41        ogRaiseError $OG_ERR_NOTCACHE "CACHE"
42        exit $?
43fi
44
45#Comprobamos si Actualizacion - existe una imagen con igual nombre pero distinto sum-
46#TODO: ogUpdateCacheIsNecesary debe borrar la imagen que tenga igual nombre pero distinto sum-
47ogUpdateCacheIsNecesary $1 $2; RETVAL=$?
48# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
49[ "$RETVAL" == "1" ] && exit 0
50[ "$RETVAL" -gt  "1" ] && exit 1
51
52
53CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`)
54FILESIZE=$(ls -sk $(ogGetPath $REPOSITORIO "$2") | cut -f1 -d" ")
55
56if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] 
57then
58        echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE"
59        ogRaiseError $OG_ERR_CACHESIZE "CACHE"
60    exit $?
61fi
62
63ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
64# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
65[ "$RETVAL" == "1" ] && exit 0
66[ "$RETVAL" -gt  "1" ] && exit 1
67
68ogMountCache >/dev/null
69
70## Si no existe, crear subdirectorio para el fichero en la cache.
71IMGDIR=$(ogGetParentPath CACHE "/$2")
72if [ $? != 0 ]; then
73    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
74    ogMakeDir CACHE $(dirname "/$2")
75    IMGDIR=$(ogGetParentPath CACHE "/$2") || exit $?
76fi
77
78
79case "$PROTOCOLO" in
80        torrent | TORRENT )
81                echo "ogCopyFile $1 $2.torrent absolute $OGCAC/$OGIMG"
82                ogCopyFile $REPOSITORIO "$2.torrent" "$IMGDIR"
83                #TODO: comprobar que el tracker definido en el fichero es correcto.
84        #TODO comprobar que el fichero torrent está en cache
85                echo "ogTorrentStart CACHE $2.torrent $4"
86                ogTorrentStart CACHE "$2.torrent" $4
87        ;;
88        multicast | MULTICAST )
89                echo "determinando puerto principal y auxiliar."
90                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
91                let PORTAUX=$PORT+1
92        #TODO: ticket 379
93                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
94                sleep $NUMBER
95                #FIN TODO
96                echo "comprobando puerto $PORTAUX en $REPOIP (sesion multicast en puerto $PORT) "
97                if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
98                then
99                        ogMcastReceiverFile $PORT CACHE "$2"
100                else
101                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
102                        echo "solicita la apertura:  hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO""
103                        hose $REPOIP 2009 --out sh -c "echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
104                        #echo "espero y llamo a: ogMcastReceiverFile $PORT CACHE $2"
105                        sleep 10
106                        if (nmap -n -sU -p $PORTAUX $REPOIP | grep open)
107                        then
108                                ogMcastReceiverFile $PORT CACHE "$2"
109                        else
110                            echo "la peticion ha fallado: hose $REPOIP 2009 --out sh -c echo -ne START_MULTICAST $2 $OPTPROTOCOLO"
111                            exit 1
112                        fi
113                fi     
114        ;;
115        unicast | UNICAST )
116                echo "unicast"
117                ogCopyFile $REPOSITORIO "$2" "$IMGDIR"
118        ;;
119esac
120
121
122ogUpdateCacheIsNecesary $REPOSITORIO "$2"; RETVAL=$?
123# si RETVAL=0 => actualizamos  si RETVAL=1 no actaulizasmo-exit 0  || si RETVAL>2 exit 1
124[ "$RETVAL" == "0" ] && exit 1
125[ "$RETVAL" == "1" ] && exit 0
126[ "$RETVAL" -gt  "1" ] && exit 1
127
Note: See TracBrowser for help on using the repository browser.