source: client/shared/scripts/updateCache @ bb30a50

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 bb30a50 was cea6d44, checked in by adv <adv@…>, 14 years ago

version 1.0.1 #381 errores en deployImage y updateCache

git-svn-id: https://opengnsys.es/svn/branches/version1.0@1967 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 3 ]; 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_NOTCACHE "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        ogRaiseError $OG_ERR_CACHESIZE "CACHE"
44    exit $?
45fi
46
47ogUpdateCacheIsNecesary $1 $2 || exit 0
48
49ogMountCache
50
51## Si no existe, crear subdirectorio para el fichero en la cache.
52IMGDIR=$(ogGetParentPath "$1" "/$2")
53if [ $? != 0 ]; then
54    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
55   ogMakeDir "CACHE" $(dirname "/$2")
56   IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $?
57fi
58
59
60
61
62case "$PROTOCOLO" in
63        torrent | TORRENT )
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
70        ;;
71        multicast | MULTICAST )
72                echo "determinando puerto principal y auxiliar."
73                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
74                let PORTAUX=$PORT+1
75        #TODO: ticket 379
76                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
77                sleep $NUMBER
78                #FIN TODO
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
84                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
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"
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     
97        ;;
98        unicast | UNICAST )
99                echo "unicast"
100                ogCopyFile $1 $2 $OGCAC$OGIMG
101        ;;
102esac
103
104if ogUpdateCacheIsNecesary $1 $2
105then
106        echo "algo ha fallado"
107        exit 1
108else
109        echo "updateCache ok"
110        exit 0
111fi
112
113
114
115#
Note: See TracBrowser for help on using the repository browser.