source: client/engine/Rsync.lib @ e79df1d

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 e79df1d was e27c4f4, checked in by irina <irinagomez@…>, 12 years ago

#565 Imagenes sincronizadas: control de errores

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

  • Property mode set to 100755
File size: 17.5 KB
Line 
1#!/bin/bash
2#/**
3# ogCreateFileImage  [ REPO | CACHE ] image_name extension size
4#@brief   Crear el archivo
5#@param 1 Repositorio  [ REPO | CACHE ]
6#@param 2 Nombre Imagen
7#@param 3 Extensión [ img |diff ]
8#@param 4 Tamaño de la imagen
9#@return  instrucción para ser ejecutada.
10#*/
11
12function ogCreateFileImage () {
13local SIZEREQUIRED IMGDIR IMGFILE DIRMOUNT LOOPDEVICE  IMGSIZE
14
15if [ "$*" == "help" ]; then
16    ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name extension  size(K)" \
17           "$FUNCNAME REPO Ubuntu12 img 300000" \
18           "$FUNCNAME CACHE Windows7 diff 20000000"
19    return
20fi
21
22
23if [ $# -lt 4 ]; then
24    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME  [ REPO|CACHE ] image_name extension  size(k)"
25    return $?
26fi
27
28SIZEREQUIRED=$4
29[ $SIZEREQUIRED -lt 300000 ] && SIZEREQUIRED=300000
30
31if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
32        IMGDIR=$(ogGetParentPath "$1" "/$2")
33        IMGFILE=${IMGDIR}/$(basename "/$2").$3
34        ## Si no existe, crear subdirectorio de la imagen.
35        if [ $? != 0 ]; then
36            echo "      $MSG_HELP_ogMakeDir \"$1 $(dirname "$2")." | tee -a $OGLOGSESSION $OGLOGFILE
37            ogMakeDir "$1" $(dirname "/$2") || return $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
38            IMGDIR=$(ogGetParentPath "$1" "/$2") || return $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
39        fi
40        DIRMOUNT=/tmp/$(ogGetMountDir "$2" "$3")
41        mkdir -p "$DIRMOUNT"
42        LOOPDEVICE=$(losetup -f)
43        # Si existe el fichero de la imagen se hace copia de seguridad, si  no existe se crea.
44        if [ -f "$IMGFILE" ]; then
45                if [ "$BACKUP" == "true" ]; then
46                    # Copia seguridad
47                    echo "     $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"." | tee -a $OGLOGSESSION $OGLOGFILE
48                    cp -f  "$IMGFILE" "$IMGFILE.ant"  &> $OGLOGCOMMAND
49                    mv -f "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
50                    rm -f "$IMGFILE.sum"
51                fi
52
53                IMGSIZE=$(ls -lk $IMGFILE | awk '{print $5}')
54                if [ $IMGSIZE -lt $SIZEREQUIRED ];then
55                   echo "      $MSG_SYNC_RESIZE" | tee -a $OGLOGSESSION $OGLOGFILE
56                   echo "      truncate --size=>$SIZEREQUIRED k $IMGFILE" | tee -a $OGLOGSESSION $OGLOGFILE
57                   truncate --size=">$SIZEREQUIRED"k $IMGFILE &> $OGLOGCOMMAND
58                   echo "      mount -o compress=lzo $IMGFILE $DIRMOUNT"
59                   mount -o compress=lzo "$IMGFILE" "$DIRMOUNT" &> $OGLOGCOMMAND
60                   echo "      btrfs filesystem resize max $DIRMOUNT"
61                   btrfs filesystem resize max "$DIRMOUNT" &> $OGLOGCOMMAND
62                fi
63        else
64                echo "      dd if=/dev/zero of=$IMGFILE bs=1024 count=$SIZEREQUIRED"
65                dd if=/dev/zero of="$IMGFILE" bs=1024 count=$SIZEREQUIRED &> $OGLOGCOMMAND
66                #Formateamos imagen
67                losetup $LOOPDEVICE $IMGFILE
68                echo "      mkfs.btrfs  -L ${2##*\/} $LOOPDEVICE "
69                mkfs.btrfs  -L "${2##*\/}" $LOOPDEVICE &> $OGLOGCOMMAND
70        fi
71                echo "      mount -o compress=lzo $IMGFILE $DIRMOUNT"
72                mount -o compress=lzo "$IMGFILE" "$DIRMOUNT" &> $OGLOGCOMMAND
73                # si ya esta montado  $? = 32
74                [ $? -eq 0 -o $? -eq 32 ] || ogRaiseError $OG_ERR_IMAGE "$3 $4"
75                touch "$DIRMOUNT/ogimg.info"
76
77        #fi
78        losetup -d $LOOPDEVICE 2>&1 &>/dev/null
79
80else
81        [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
82        echo "      hose $REPOIP 2009 --out sh -c \"echo -ne CREATE_IMAGE $2 $3 $SIZEREQUIRED \"" | tee -a $OGLOGSESSION $OGLOGFILE
83        hose $REPOIP 2009 --out sh -c "echo -ne CREATE_IMAGE \"$2\" $3 $SIZEREQUIRED"
84fi
85
86}
87
88#/**
89# ogSetSizeInfo [REPO|CACHE] nombre_imagen extension tamaño
90#@brief Configuramos la informacion del tamaño de los datos, para diferenciales
91#@param 1 Repositorio  [ REPO | CACHE ] (opcional en las completas)
92#@param 2 Nombre Imagen Basica (opcional en las completas)
93#@param 3 Extensión [ img | diff ]
94#@param 4 Tamaño de los datos.
95function ogSetSizeInfo () {
96local DIRMOUNT UMOUNT
97
98if [ "$*" == "help" ]; then
99        ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name  extension size_data  " \
100               "base image -> $FUNCNAME REPO Ubuntu12 img 34000000" \
101               "diff image -> $FUNCNAME CACHE Windows7 diff 500000"
102        return
103fi
104
105if [ $# -lt 4 ]; then
106    ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  [ REPO|CACHE ] image_name  extension size_data "
107    return $?
108fi
109
110DIRMOUNT=$(ogGetMountDir  "$2" $3)
111[ "$1" == "CACHE" -o "$1" == "cache" ] && DIRMOUNT="/tmp/$DIRMOUNT" || DIRMOUNT="$OGIMG/$DIRMOUNT"
112
113# Si no esta montada la imagen se monta.
114[ -r $DIRMOUNT/ogimg.info ] && UMOUNT=false || ogMountImage $1 "$2" $3
115# se configura el tamaño
116echo sed -i s/SIZEDATA/"$4"/g $DIRMOUNT/ogimg.info
117sed -i s/SIZEDATA/"$4"/g $DIRMOUNT/ogimg.info
118# se desmonta, si no estaba montada.
119[ "$UMOUNT" == false ] || ogUnmountImage $1 "$2" $3
120
121
122}
123
124function ogCreateInfoImage () {
125#/**
126#  ogCreateInfoImage
127#@brief   Crear listados con la informacion de la imagen, los situa en /tmp.
128#@param 1 num_disk
129#@param 2 num_part
130#@param 3 Repositorio  [ REPO | CACHE ] (opcional en las completas)
131#@param 4 Nombre Imagen Basica (opcional en las completas)
132#@param 5 Extensión [ img | diff ]
133#*/
134local  IMGEXT IMGDIRAUX DIRMOUNT DESTRSYNC OPTRSYNC USERRSYNC ORIG FSTYPE PART DIREMPTY IMGLIST IMGINFO IMGACL
135
136# Ayuda o menos de 5 parametros y la imagen no es basica
137if [ "$*" == "help" -o   $# -lt 5 -a "$3" != "img"  ]; then
138        ogHelp "$FUNCNAME" "$FUNCNAME num_disk num_part [ REPO|CACHE ] [ base_image_name ] extension  " \
139               "base image -> $FUNCNAME 1 2 img" \
140               "diff image -> $FUNCNAME 1 1 CACHE Windows7 diff "
141        return
142fi
143
144if [ $# -lt 3 ]; then
145    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME  num_disk num_part [ REPO|CACHE ] [ base_image_name]  extension  "
146    return $?
147fi
148
149if [ $3 == "img" ]; then
150   IMGEXT="img"
151else
152   # Comprobamos que las extension sea valida
153   ogCheckStringInGroup $5 "img diff" || ogRaiseError  $OG_ERR_FORMAT $MSG_SYNC_EXTENSION
154   IMGEXT=$5
155   if [ "$IMGEXT" == "diff" ]; then
156        # Imagen completa con la que comparo la particion.
157        IMGDIRAUX=$(ogGetMountDir "$4" "img")
158        if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
159           DIRMOUNT="/tmp/$IMGDIRAUX"
160           DESTRSYNC=$DIRMOUNT
161           OPTRSYNC=""
162        else
163           [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
164           DIRMOUNT="$OGIMG/$IMGDIRAUX"
165           USERRSYNC="opengnsys"
166           OPTRSYNC="$OPTRSYNC --password-file=/scripts/passrsync"
167           DESTRSYNC="$USERRSYNC@$REPOIP::ogimages/$IMGDIRAUX"
168        fi
169   fi
170fi
171
172
173ORIG=$(ogMount $1 $2)
174FSTYPE=$(ogGetFsType $1 $2)
175PART=$(ogDiskToDev "$1" "$2" 2>/dev/null)
176
177# Creamos la lista del contenido y lo situamos en la particion a copiar.
178DIREMPTY="/tmp/empty$$"
179IMGLIST="/tmp/ogimg.list"
180IMGINFO="/tmp/ogimg.info"
181IMGACL="/tmp/ogimg.acl"
182
183# Borramos archivos antiguos.
184rm /tmp/ogimg.* 2>/dev/null
185rm $ORIG/ogimg.* 2>/dev/null
186
187# En las diferenciales no sabemos el tamaño -> ponemos una constante.
188SIZEDATA=${SIZEDATA:-"SIZEDATA"}
189
190echo "#BRTFS:LZO:$FSTYPE:$SIZEDATA" > $IMGINFO
191if [ "$IMGEXT" == "img" ]; then
192        # Imagen Basica
193        echo "      rsync -aHAXvn --delete $ORIG/ $DIREMPTY >> $IMGINFO" | tee -a $OGLOGSESSION $OGLOGFILE
194        rsync -aHAXvn --delete $ORIG/ $DIREMPTY>> $IMGINFO
195        sed -i -e s/"^sent.*.bytes\/sec"//g -e s/^total.*.speedup.*.$//g -e s/"sending.*.list"//g $IMGINFO
196        sed -i  '/^\.\//d' $IMGINFO
197
198else
199        # Imagen Diferencial
200        # TODO en el echo quitar la $OPTRSYNC  para que no se vea el fichero de claves
201        echo "      rsync -aHAXvn$OPTRSYNC  --delete  $ORIG/ $DESTRSYNC a $IMGLIST" | tee -a $OGLOGSESSION $OGLOGFILE
202        rsync -aHAXvn$OPTRSYNC   --delete  "$ORIG/" "$DESTRSYNC" >> $IMGLIST
203        sed -i -e s/"^sent.*.bytes\/sec"//g -e s/^total.*.speedup.*.$//g -e s/"sending.*.list"//g $IMGLIST
204        sed -i  '/^\.\//d' $IMGLIST
205
206        # Creamos informacion de la imagen
207        grep -e '\->' -e  '\=>' $IMGLIST > /tmp/ogimg.ln
208        grep -e  ^deleting  $IMGLIST | sed s/^deleting\ //g | grep -v ^ogimg  > /tmp/ogimg.rm
209        #grep -v -e '\->' -e  '\=>'  -e ^deleting  $IMGLIST >> $IMGINFO
210        grep -v -e '\->' -e  '\=>'  -e ^deleting -e ^created  $IMGLIST >> $IMGINFO
211
212        rm $IMGLIST
213
214fi
215
216# Imagenes basicas  y diferenciales
217# Guardamos el contenido de las acl (Solo win) Necesario particion desmontada (esta asi)
218ogUnmount $1 $2
219if [ $FSTYPE == "NTFS" ]; then
220        echo "     ntfs-3g.secaudit -b $PART /" |tee -a $OGLOGSESSION $OGLOGFILE
221        ntfs-3g.secaudit -b $PART / > $IMGACL
222fi
223
224}
225
226#/**
227#  ogRestoreInfoImage
228#@brief Restaurar las ACL y en las diferenciales crear enlaces y borrar ficheros sobrantes.
229#@param 1 num_disk
230#@param 2 num_part
231#*/
232function ogRestoreInfoImage () {
233local 
234
235# Ayuda o menos de 5 parametros y la imagen no es basica
236if [ "$*" == "help" ]; then
237        ogHelp "$FUNCNAME" "$FUNCNAME num_disk num_part" \
238               "base image -> $FUNCNAME 1 2 " \
239               "diff image -> $FUNCNAME 1 1 "
240        return
241fi
242
243if [ $# -lt 2 ]; then
244    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part  "
245    return $?
246fi
247
248
249
250DEST=$(ogMount $1 $2)
251PART=$(ogDiskToDev "$1" "$2" 2>/dev/null)
252
253# Informacion del contenido.
254IMGACL="ogimg.acl"
255
256if [ -r $DEST/ogimg.ln ]; then
257        while read dest enlace orig
258        do
259           if [ "$enlace" == "->" ]
260           then
261                OPTLN='-s'
262           else
263                OPTLN=''
264           fi
265           cd $DEST/$(dirname $dest)
266           ln $OPTLN $orig $(basename $dest) 2>/dev/null
267           echo -n "."
268        done < $DEST/ogimg.ln  2>/dev/null
269        echo ""
270
271fi
272
273# Imagen basica y diferencial.
274   if [ "$(ogGetFsType $1 $2)" == "NTFS" ] ; then
275        cd /
276        cp $DEST/$IMGACL /tmp
277        ogUnmount "$1" "$2"
278        echo "      ntfs-3g.secaudit -se $PART" |tee -a $OGLOGSESSION $OGLOGFILE
279        ntfs-3g.secaudit -se $PART /tmp/$IMGACL
280   fi
281
282}
283
284function ogSyncCreate () {
285#/**
286# ogSyncCreate
287#@brief   sincroniza los datos de la partición a la imagen para crearla.
288#@param 1 num_disk
289#@param 2 num_part
290#@param 3 Repositorio  [ REPO | CACHE ]
291#@param 4 Nombre Imagen
292#@param 5 Extensión [ img | diff ]
293#*/
294local ORIG DIRAUX DIRMOUNT DESTRSYNC USERRSYNC OPTRSYNC
295
296if [ "$*" == "help" ]; then
297        ogHelp "$FUNCNAME" "$FUNCNAME num_disk num_part [ REPO|CACHE ] image_name extension  " \
298               "$FUNCNAME 1 2 REPO Ubuntu12 img" \
299               "$FUNCNAME 1 1 CACHE Windows7 diff "
300        return
301fi
302
303
304if [ $# -lt 4 ]; then
305    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME  num_disk num_part [ REPO|CACHE ] image_name extension  "
306    return $?
307fi
308
309ORIG=$(ogMount $1 $2)
310DIRMOUNT=$(ogGetMountDir "$4" $5)
311[ "$5" == "diff" ] && FILESFROM=" --files-from=/tmp/ogimg.info" || FILESFROM=""
312
313if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
314        DESTRSYNC="/tmp/$DIRMOUNT"
315else
316        [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
317        OPTRSYNC=" --password-file=/scripts/passrsync"
318        [ "$ogcompress" ==  "true" ] && OPTRSYNC="z $OPTRSYNC"
319        USERRSYNC="opengnsys"
320        DESTRSYNC="$USERRSYNC@$REPOIP::ogimages/$DIRMOUNT"
321fi
322# Sincronizamos los datos de la partición a la imagen
323echo "      rsync -aHAX$OPTRSYNC --inplace --delete $FILESFROM  $ORIG/ $DESTRSYNC" | tee -a $OGLOGSESSION $OGLOGFILE
324rsync -aHAXq$OPTRSYNC --inplace --delete $FILESFROM  "$ORIG/" "$DESTRSYNC"
325echo "      rsync -aHAX$OPTRSYNC --inplace /tmp/ogimg* $DESTRSYNC" | tee -a $OGLOGSESSION $OGLOGFILE
326rsync -aHAXq$OPTRSYNC --inplace /tmp/ogimg* $DESTRSYNC
327
328}
329
330
331#/**
332# ogSyncRestore
333#@brief   sincroniza los datos de la imagen a la partición para restaurarla.
334#@param 1 Repositorio  [ REPO | CACHE ]
335#@param 2 Nombre Imagen
336#@param 3 Extensión [ img | diff ]
337#@param 4 num_disk
338#@param 5 num_part
339#*/
340function ogSyncRestore () {
341local DIRMOUNT ORIG DESTRSYNC OPTRSYNC USERRSYNC IMGINFO FILESFROM
342
343if [ "$*" == "help" ]; then
344        ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name extension  num_disk num_part  " \
345               "$FUNCNAME REPO Ubuntu12 img 1 2" \
346               "$FUNCNAME CACHE Windows7 diff 1 1"
347        return
348fi
349
350
351if [ $# -lt 5 ]; then
352    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME  [ REPO|CACHE ] image_name extension   num_disk num_part "
353    return $?
354fi
355
356
357DIRMOUNT=$(ogGetMountDir "$2" "$3")
358DESTRSYNC=$(ogGetMountPoint $4 $5)
359
360# Borramos ficheros de informacion de restauraciones antiguas
361rm -rf $DESTRSYNC/ogimg.*
362
363# Origen y destino de la sincronizacion y en REPO opciones rsync
364if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
365        ORIG="/tmp/$DIRMOUNT"
366else
367        [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
368        OPTRSYNC=" --password-file=/scripts/passrsync"
369        [ "$ogcompress" ==  "true" ] && OPTRSYNC="z $OPTRSYNC"
370        USERRSYNC="opengnsys"
371        ORIG="$USERRSYNC@$REPOIP::ogimages/$DIRMOUNT"
372fi
373
374# Opciones rsync en cache y repo
375[ "$3" == "img" ] && [ "$ogrsyncdel" != "false" ] && OPTRSYNC="$OPTRSYNC --delete"
376
377# Nos traemos listado ficheros y bajamos la imagen
378
379echo "      $MSG_SYNC_RESTORE" |tee -a  $OGLOGSESSION   $OGLOGFILE
380
381# Si la imagen es diferencial nos traemos los archivos de informacion de la imagen.
382if [ "$3" == "diff" ]; then
383        # Lista de archivos a copiar:
384        IMGINFO="ogimg.info"
385        FILESFROM=" --files-from=$DESTRSYNC/$IMGINFO"
386
387        echo "      rsync -aHAXq$OPTRSYNC  $ORIG/ogimg* $DESTRSYNC" |tee -a  $OGLOGFILE
388        rsync -aHAXq$OPTRSYNC  $ORIG/ogimg* $DESTRSYNC
389        # Borramos linea de información de la imagen, sino busca un fichero con ese nombre
390        sed -i   '/^\#/d' $DESTRSYNC/$IMGINFO
391
392        cd $DESTRSYNC
393        # Diferencial: Borramos archivos sobrantes.
394        echo "      $MSG_SYNC_DELETE"  |tee -a  $OGLOGFILE
395        cat $DESTRSYNC/ogimg.rm 2>/dev/null | xargs rm -rf
396
397fi
398
399echo "      rsync -aHAX$OPTRSYNC  $FILESFROM  $ORIG/ $DESTRSYNC" | tee -a $OGLOGSESSION $OGLOGFILE
400rsync -aHAXq$OPTRSYNC  $FILESFROM  "$ORIG/" "$DESTRSYNC"
401
402
403}
404
405function ogMountImage () {
406#/**
407# ogMountImage
408#@brief   Monta la imagen para sincronizar.
409#@param 1 Repositorio  [ REPO | CACHE ]
410#@param 2 Nombre Imagen
411#@param 3 Extensión [ img |diff ]
412#@return punto de montaje
413#*/
414local IMGEXT IMGFILE DIRMOUNT
415
416if [ "$*" == "help" ]; then
417    ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name [ extension ]" \
418           "$FUNCNAME REPO Ubuntu12" \
419           "$FUNCNAME CACHE Windows7 diff"
420    return
421fi
422
423
424if [ $# -lt 2 ]; then
425    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME image_name [ extension ]"
426    return $?
427fi
428
429[ "$3" == "" ] && IMGEXT="img" || IMGEXT="$3"
430
431DIRMOUNT=$(ogGetMountDir "$2" $IMGEXT)
432
433if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
434        IMGFILE=$(ogGetPath "$1" /"$2.$IMGEXT")
435        mkdir -p "/tmp/$DIRMOUNT"
436        mount -o compress=lzo  "$IMGFILE" "/tmp/$DIRMOUNT" 1>/dev/null
437        echo "/tmp/$DIRMOUNT"
438
439else
440        [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
441        hose $REPOIP 2009 --out sh -c "echo -ne MOUNT_IMAGE \"$2\" $IMGEXT"
442        echo "$OGIMG/$DIRMOUNT"
443
444fi
445
446}
447
448
449function ogUnmountImage () {
450#/**
451# ogUnmountImage  [ REPO | CACHE ] Image_name [ extension ]
452#@brief   Desmonta la imagen para sincronizar.
453#@param 1 Repositorio  [ REPO | CACHE ]
454#@param 2 Nombre Imagen
455#@param 3 Extensión [ img |diff ]
456#*/
457local IMGEXT DIRMOUNT
458
459if [ "$*" == "help" ]; then
460    ogHelp "$FUNCNAME" "$FUNCNAME [ REPO|CACHE ] image_name [ extension ]" \
461           "$FUNCNAME REPO Ubuntu12" \
462           "$FUNCNAME CACHE Windows7 diff"
463    return
464fi
465
466if [ $# -lt 2 ]; then
467    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME image_name [ extension ]"
468    return $?
469fi
470
471[ "$3" == "" ] && IMGEXT="img" || IMGEXT="$3"
472
473if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
474        DIRMOUNT=/tmp/$(ogGetMountDir "$2" $IMGEXT)
475        umount "$DIRMOUNT"
476else
477        [ -z $REPOIP ] && REPOIP=$(ogGetRepoIp)
478        echo "      hose $REPOIP 2009 --out sh -c echo -ne UMOUNT_IMAGE \"$2\" $IMGEXT" |tee -a  $OGLOGFILE
479        hose $REPOIP 2009 --out sh -c "echo -ne UMOUNT_IMAGE \"$2\" $IMGEXT"
480fi
481
482}
483
484function ogGetMountDir () {
485#/**
486# ogGetMountDir
487#@brief   Devuelve el directorio de montaje de la imagen.
488#@param 1 Nombre Imagen
489#@param 2 Extensión [ img |diff ]
490#*/
491local DIRMOUNT
492if [ "$*" == "help" ]; then
493    ogHelp "$FUNCNAME" "$FUNCNAME image_name [ extension ]" \
494           "$FUNCNAME Ubuntu12" \
495           "$FUNCNAME Windows7 diff"
496    return
497fi
498
499
500if [ $# -lt 1 ]; then
501    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME image_name [ extension ]"
502    return $?
503fi
504
505
506DIRMOUNT="mount/$1"
507[ "$2" == "diff" ] && DIRMOUNT="$DIRMOUNT.diff"
508echo $DIRMOUNT
509
510
511}
512
513
514#/**
515#  ogWaitMountImage image_name extension imagen_size
516#@brief Se espera un tiempo a que se monte la imagen en el servidor.
517#@brief Cuando se esta creando la imagen hay que dar el tamaño, para que espere el tiempo de creación. 
518#@param 1 Respositorio [ REPO | CACHE ]
519#@param 2 Nombre Imagen
520#@param 3 Extensión [ img | diff ]
521#@param 4 Tamaño imagen (opcional)
522#*/
523function ogWaitMountImage () {
524local SIZE TIME DIRMOUNT TIMEOUT TIMEAUX
525
526TIME=$SECONDS
527
528# Ayuda o menos de 5 parametros y la imagen no es basica
529if [ "$*" == "help" ]; then
530        ogHelp "$FUNCNAME" "$FUNCNAME [ REPO | CACHE ] image_name extension [ image_size ] " \
531               "$FUNCNAME REPO Ubuntu12 img 30000000" \
532               "$FUNCNAME CACHE Windows7 diff "
533        return
534fi
535
536if [ $# -lt 2 ]; then
537    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME [ REPO | CACHE ]  image_name extension [ image_size ] "
538    return $?
539fi
540
541
542SIZE=${4:-"300000"}
543
544if [ "$1" == "CACHE" -o "$1" == "cache" ]; then
545        DIRMOUNT="/tmp/$(ogGetMountDir "$2" $3)"
546else
547        DIRMOUNT="$OGIMG/$(ogGetMountDir "$2" $3)"
548fi
549
550echo -n -e "      $MSG_SYNC_SLEEP: $DIRMOUNT\n      #"
551
552# time-out segun el tamaño de la imagen. por defecto: 100000k -> 3s
553let TIMEOUT=$SIZE/$CREATESPEED
554[ $TIMEOUT -lt 60 ] && TIMEOUT=60
555until [ -f "$DIRMOUNT/ogimg.info" ] ; do
556        TIMEAUX=$[SECONDS-TIME]
557        #[  "$TIMEAUX" -gt "$TIMEOUT" ] && return $(ogRaiseError "$MSG_ERR_DONTMOUNT_IMAGE $1 $2 $3: time_out $TIMEAUX seg."; echo $?)
558        # TODO definir el error
559        [  "$TIMEAUX" -gt "$TIMEOUT" ] &&  return 2
560        echo -n "#"
561        sleep 5
562done
563echo  ""
564
565}
Note: See TracBrowser for help on using the repository browser.