source: client/shared/scripts/createImage @ 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 c3758e7, checked in by adv <adv@…>, 14 years ago

version 1.0.2 #394 crear imagen, detecta espacio necesario en el contenedor destiono REPO|CACHE

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

  • Property mode set to 100755
File size: 4.4 KB
RevLine 
[f8f4dfa]1#!/bin/bash
[eb9424f]2
3#/**
4#         createImage
5#@brief   Scirpt de ejemplo para crear una imagen de un sistema de archivos.
6#@brief (puede usarse como base para el programa de creación de imágenes usado por OpenGnSys Admin).
7#@param 1 disco
8#@param 2 particion
9#@param 3 REPO|CACHE
10#@param 4 imagen
11#@return 
[2d40ba26]12#@exception OG_ERR_FORMAT     # 1 formato incorrecto.
13#@exception OG_ERR_PARTITION  # 3 Error en partición de disco o en su sistema de archivos
14#@exception OG_ERR_IMAGE      # 5 Error en funcion ogCreateImage o ogRestoreImage.
15#@exception OG_ERR_NOTWRITE   # 14 error de escritura
16#@exception OG_ERR_NOTCACHE   # 15 si cache no existe 15
17#@exception OG_ERR_CACHESIZE  # 16 si espacio de la cache local o remota no tiene espacio 16
18#@exception OG_ERR_REDUCEFS   # 17 error al reducir sistema de archivos.
19#@exception OG_ERR_EXTENDFS   # 18 Errror al expandir el sistema de archivos.
[eb9424f]20#@note   
[2d40ba26]21#@todo: que hacer, si el tamaño de la cache es sufciente, pero no tiene espacio libre
22#@todo: que hacer, si hay una imagen con igual nombre en la cache
[eb9424f]23#@version 1.0 - control de errores para el ogAdmServer
24#@author 
[2d40ba26]25#@date   2011-04-10
[c3758e7]26#@version 1.0.1 - Control de espacio requerido
27#@author  Antonio J.Doblas Viso
[2d40ba26]28#@date   2011-05-10
29 
[eb9424f]30#*/ ##
31
[2d40ba26]32# Test 1.  crear una imagen en un REPO sin espacio libre.
33# test 2.  crear una imagen en un REPO en modo solo lectura.
34# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
35# test 4.  crear una imagen en la Cache sin espacio sufiente.
36# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
[f8f4dfa]37
[f5432db7]38TIME1=$SECONDS
[f8f4dfa]39PROG="$(basename $0)"
40if [ $# -ne 4 ]; then
[be85bb2]41    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
[f8f4dfa]42    exit $?
43fi
44
[95b340a]45# Valores por defecto
46IMGPROG="partclone"
47IMGCOMP="lzop"
48IMGEXT="img"
49
[defcdab]50# Si el repositorio es CACHE comprobamos que exista
[3aaf91d]51if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
[2d40ba26]52    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
[3aaf91d]53fi
[defcdab]54
[c40a6b4]55# Obtener información de los parámetros de entrada.
[2d40ba26]56PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
57
58#Comprobamos acceso de escritura.
59DIRTEMP=$(date +%Y%m%d-%H%M%S)
60ogMakeDir $3 /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3"; echo $?) && ogDeleteTree $3 /$4$DIRTEMP
61
[a3fb8b2]62IMGDIR=$(ogGetParentPath "$3" "/$4")
[180a07dd]63# Si no existe, crear subdirectorio de la imagen.
64if [ $? != 0 ]; then
65    echo "[5] Crear subdirectorio de la imagen \"$3 $(dirname "$4")."
[2d40ba26]66    ogMakeDir "$3" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
67    IMGDIR=$(ogGetParentPath "$3" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
[180a07dd]68fi
[95b340a]69IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
[f8f4dfa]70# Renombrar el fichero de imagen si ya existe.
71if [ -f "$IMGFILE" ]; then
[180a07dd]72    echo "[10] Renombrar \"$IMGFILE\" por \"$IMGFILE.ant\"."
[f8f4dfa]73    mv "$IMGFILE" "$IMGFILE.ant"
[0fbc05e]74    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
[f8f4dfa]75fi
[2d40ba26]76
77#Comprobar espacio que requerira la imagen para ser almacenada
78if ogMount $1 $2 &>/dev/null
79then
80        SIZEDATA=$(df -k | grep $PART | awk '{print $3}')
81        #Aplicar factor de compresion
82        FACTORGZIP=55/100
83        FACTORLZOP=65/100
84        let SIZEREQUIRED=$SIZEDATA*$FACTORLZOP
85        #Comprobar espacio libre en el contenedor.
86        [ "$3" == "CACHE" ] && SIZEFREE=$(ogGetFreeSize `ogFindCache`)
87        [ "$3" == "REPO" ] && SIZEFREE=$(df -k | grep $OGIMG | awk '{print $3}')
88else
89        ogRaiseError $OG_ERR_PARTITION "$1 $2"
90    exit $?
91fi     
92
[41d9755]93# Mostrar información.
94echo "[15] $PROG: Origen=$PART, Destino=$IMGFILE"
[2d40ba26]95echo "[16] $PROG: TamañoRequerido=$SIZEREQUIRED EspacioDisponible=$SIZEFREE"
96
97[ "$SIZEREQUIRED" -gt "$SIZEFREE" ] && exit $(ogRaiseError $OG_ERR_CACHESIZE "$3" || echo $?)
98
99
100# TODO: que hacer si la cache no tiene espacio libre.
[f8f4dfa]101
[3aaf91d]102# Comprobar consistencia del sistema de archivos.
[6d3f526]103echo "[20] Comprobar sistema de archivos."
[914d834]104ogUnmount $1 $2
[2d40ba26]105ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
[914d834]106
[95b340a]107echo "[30]: Reducir sistema de archivos."
[2d40ba26]108ogReduceFs $1 $2 || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
[914d834]109
[6d3f526]110# Crear la imagen.
[2d40ba26]111echo "[40] Crear imagen con: ogCreateImage $1 $2 $3 $4 $IMGPROG $IMGCOMP"
112ogCreateImage $1 "$2" $3 $4 "$IMGPROG" "$IMGCOMP" || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
[6d3f526]113
[914d834]114echo "[90] Extender sistema de archivos."
[2d40ba26]115ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
[eb9424f]116
[914d834]117
[f5432db7]118TIME=$[SECONDS-TIME1]
[bfeb89a]119echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s"
[f8f4dfa]120
Note: See TracBrowser for help on using the repository browser.