source: client/shared/scripts/updateCache @ b0d505f6

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 b0d505f6 was 841ce50, checked in by adv <adv@…>, 14 years ago

version 1.0.2 boot-tools #404 #420 id.version instalador

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

  • Property mode set to 100755
File size: 4.1 KB
RevLine 
[914d834]1#!/bin/bash
2
3
[841ce50]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#*/ ##
[914d834]24
25PROG="$(basename $0)"
[cea6d44]26if [ $# -lt 3 ]; then
[914d834]27    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE"
28    exit $?
29fi
30
31REPOSITORIO=$1
32PROTOCOLO=$3
33OPTPROTOCOLO=$4
[9b6e62c]34REPOIP=$(ogGetRepoIp)
35echo $REPOSITORIO $REPOIP $PROTOCOLO $OPTPROTOCOLO
[914d834]36# Si el repositorio local CACHE no existe salimos.
37if ! $(ogFindCache >/dev/null); then
[5c44f86]38        ogRaiseError $OG_ERR_NOTCACHE "CACHE"
[914d834]39        exit $?
40fi
41
[9b6e62c]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-
[db8fdd2]44ogUpdateCacheIsNecesary $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
[914d834]49
50CACHESIZEFREE=$(ogGetFreeSize `ogFindCache`)
51FILESIZE=$(ls -sk $(ogGetPath $1 $2) | cut -f1 -d" ")
52
53if [ "$FILESIZE" -ge "$CACHESIZEFREE" ] 
54then
55        echo "el tamanio del fichero $2 = $FILESIZE es mayor que el espacio dispinible en la cache = $CACHESIZEFREE"
[5c44f86]56        ogRaiseError $OG_ERR_CACHESIZE "CACHE"
57    exit $?
[914d834]58fi
59
[db8fdd2]60ogUpdateCacheIsNecesary $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
[914d834]64
65ogMountCache
66
67## Si no existe, crear subdirectorio para el fichero en la cache.
68IMGDIR=$(ogGetParentPath "$1" "/$2")
69if [ $? != 0 ]; then
70    echo "[5] Crear subdirectorio del fichero  \"$2 $(dirname "$2")."
71   ogMakeDir "CACHE" $(dirname "/$2")
72   IMGDIR=$(ogGetParentPath "$1" "/$2") || exit $?
73fi
74
75
[9b6e62c]76
77
[914d834]78case "$PROTOCOLO" in
79        torrent | TORRENT )
[9b6e62c]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
[914d834]86        ;;
87        multicast | MULTICAST )
[9b6e62c]88                echo "determinando puerto principal y auxiliar."
89                PORT=$(echo $OPTPROTOCOLO | cut -f1 -d":")
90                let PORTAUX=$PORT+1
[e8460d2]91        #TODO: ticket 379
92                NUMBER=$[ ( $RANDOM % 30 )  + 1 ]
93                sleep $NUMBER
94                #FIN TODO
[9b6e62c]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
[e8460d2]100                    # TODO ticket 379 Realizar la petición basada en identificador de operacion
[9b6e62c]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"
[e8460d2]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     
[914d834]113        ;;
114        unicast | UNICAST )
[9b6e62c]115                echo "unicast"
[5c44f86]116                ogCopyFile $1 $2 $OGCAC$OGIMG
[914d834]117        ;;
118esac
119
120
[db8fdd2]121ogUpdateCacheIsNecesary $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
Note: See TracBrowser for help on using the repository browser.