source: client/shared/scripts/updateCache @ cd95622

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

version1.0.1 #396 modificacion temporal para detectar FALSE en ogIs...

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

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