source: client/shared/scripts/createImage @ 811d00e

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 811d00e was b9797f2, checked in by ramon <ramongomez@…>, 11 years ago

versión 1.0.6: Corregidas erratas leves en script createImage al comparar el parámetro repositorio y al personalizar la extensión del fichero de imagen.

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

  • Property mode set to 100755
File size: 6.7 KB
RevLine 
[f8f4dfa]1#!/bin/bash
[eb9424f]2
3#/**
[d2f28cf]4#@file    createImage
[eb9424f]5#@brief   Scirpt de ejemplo para crear una imagen de un sistema de archivos.
[d2f28cf]6#@brief   (puede usarse como base para el programa de creación de imágenes usado por OpenGnSys Admin).
[eb9424f]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
[f311787]29 #@version 1.0.2 - Separacion de log
30#@author  Antonio J.Doblas Viso
31#@date   2011-08-4
[eb9424f]32#*/ ##
33
[2d40ba26]34# Test 1.  crear una imagen en un REPO sin espacio libre.
35# test 2.  crear una imagen en un REPO en modo solo lectura.
36# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
37# test 4.  crear una imagen en la Cache sin espacio sufiente.
38# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
[f8f4dfa]39
[f311787]40
[f8f4dfa]41PROG="$(basename $0)"
42if [ $# -ne 4 ]; then
[be85bb2]43    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
[f8f4dfa]44    exit $?
45fi
46
[d2f28cf]47TIME1=$SECONDS
48
49#Load engine configurator from engine.cfg file.
50#Carga el configurador del engine desde el fichero engine.cfg
51[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
52
[b92b4bb]53# Valores por defecto en etc/engine.cfg
54#IMGPROG="partclone"
55#IMGCOMP="lzop"
[b9797f2]56IMGEXT=${IMGEXT:-"img"}
[b92b4bb]57#IMGREDUCE="TRUE"
[95b340a]58
[d2f28cf]59# Clear temporary file used as log track by httpdlog
60# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
61echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp
[f311787]62
[e7e3140]63ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
[f311787]64
[defcdab]65# Si el repositorio es CACHE comprobamos que exista
[b9797f2]66if [ "${3^^}" == "CACHE" ]; then
[2d40ba26]67    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
[3aaf91d]68fi
[defcdab]69
[c40a6b4]70# Obtener información de los parámetros de entrada.
[2d40ba26]71PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
72
73#Comprobamos acceso de escritura.
74DIRTEMP=$(date +%Y%m%d-%H%M%S)
75ogMakeDir $3 /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3"; echo $?) && ogDeleteTree $3 /$4$DIRTEMP
76
[a3fb8b2]77IMGDIR=$(ogGetParentPath "$3" "/$4")
[180a07dd]78# Si no existe, crear subdirectorio de la imagen.
79if [ $? != 0 ]; then
[e7e3140]80    ogEcho log session "[5] $MSG_HELP_ogMakeDir \"$3 $(dirname "$4")."
[2d40ba26]81    ogMakeDir "$3" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
82    IMGDIR=$(ogGetParentPath "$3" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$3 /$4"; echo $?)
[180a07dd]83fi
[95b340a]84IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
[d2f28cf]85
[f8f4dfa]86# Renombrar el fichero de imagen si ya existe.
87if [ -f "$IMGFILE" ]; then
[e7e3140]88    ogEcho log session "[10] $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"."
[d2f28cf]89    mv "$IMGFILE" "$IMGFILE.ant"
[0fbc05e]90    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
[d2f28cf]91    mv "$IMGFILE.sum" "$IMGFILE.sum.ant" 2>/dev/null
[f8f4dfa]92fi
[2d40ba26]93
94#Comprobar espacio que requerira la imagen para ser almacenada
[e272d9e]95echo " " > $OGLOGCOMMAND
[2d40ba26]96if ogMount $1 $2 &>/dev/null
97then
[d2f28cf]98    SIZEDATA=$(df -k | grep $PART | awk '{print $3}')
99    #Aplicar factor de compresion
100    FACTORGZIP=55/100
101    FACTORLZOP=65/100
102    let SIZEREQUIRED=$SIZEDATA*$FACTORLZOP
103    #Comprobar espacio libre en el contenedor.
[b9797f2]104    [ "${3^^}" == "CACHE" ] && SIZEFREE=$(ogGetFreeSize `ogFindCache`)
105    [ "${3^^}" == "REPO" ] && SIZEFREE=$(df -k | grep $OGIMG | awk '{print $4}')
[2d40ba26]106else
[d2f28cf]107    ogRaiseError $OG_ERR_PARTITION "$1 $2"
[2d40ba26]108    exit $?
[d2f28cf]109fi
110
[e7e3140]111ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE  $SIZEREQUIRED $SIZEFREE"
[2d40ba26]112[ "$SIZEREQUIRED" -gt "$SIZEFREE" ] && exit $(ogRaiseError $OG_ERR_CACHESIZE "$3" || echo $?)
113
[d2f28cf]114# Ejecuta script personalizado de preconfiguración del sistema operativo modelo.
115if which createImageCustomPre &>/dev/null; then
116    createImageCustomPre "$1" "$2" "$3" "$4"
117fi
[e272d9e]118
[3aaf91d]119# Comprobar consistencia del sistema de archivos.
[e272d9e]120echo " " > $OGLOGCOMMAND
121SIZEFS=$(ogGetFsSize  $1 $2)
[e7e3140]122ogEcho log session "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB)"
[d2f28cf]123ogUnmount $1 $2 2>/dev/null
[2d40ba26]124ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
[914d834]125
[d2f28cf]126# Evaluar variable de engine.cfg para reducir el sistema de archivos en la creacion
127if [ "$IMGREDUCE" == "TRUE" ]
[b92b4bb]128then
[e7e3140]129    ogEcho log session "[30]: $MSG_HELP_ogReduceFs"
[d2f28cf]130    ogReduceFs $1 $2 &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
131    NEWSIZEFS=$(ogGetFsSize  $1 $2)
132    TIMEAUX=$[SECONDS-TIME1]
[e7e3140]133    ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL ( $NEWSIZEFS KB ) : $[TIMEAUX/60]m $[TIMEAUX%60]s"
[b92b4bb]134fi
[914d834]135
[6d3f526]136# Crear la imagen.
[e272d9e]137echo " " > $OGLOGCOMMAND
138TIME2=$SECONDS
[e7e3140]139ogEcho log session "[40] $MSG_HELP_ogCreateImage : ogCreateImage $1 $2 $3 $4 $IMGPROG $IMGCOMP"
[d2f28cf]140ogCreateImage "$1" "$2" "$3" "/$4" "$IMGPROG" "$IMGCOMP" &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
141RESUMECREATEIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
[e272d9e]142TIMEAUX2=$[SECONDS-TIME2]
[e7e3140]143ogEcho log session "      $RESUMECREATEIMAGE "
144ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s"
[e272d9e]145
[d2f28cf]146# Extender sistema de archivos
[e272d9e]147TIME3=$SECONDS
[e7e3140]148ogEcho log session "[90] Extender sistema de archivos."
[2d40ba26]149ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
[e272d9e]150SIZEFS2=$(ogGetFsSize  $1 $2)
151TIMEAUX3=$[SECONDS-TIME3]
[e7e3140]152ogEcho log session "      $MSG_HELP_ogExtendFs  $NEWSIZEFS ->  $SIZEFS = $SIZEFS2: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
[e272d9e]153
154#TODO que hacer si error al extender sistemade archivos
[eb9424f]155
[e272d9e]156#resumen de la operacion
[b9797f2]157IMGSIZE=$(ls -s `ogGetPath $3 /$4.$IMGEXT`| cut -f1 -d" ")
158IMGOS=$(ogGetImageInfo `ogGetPath $3 /$4.$IMGEXT`)
[e272d9e]159
160TIME=$[SECONDS-TIME1]
[e7e3140]161ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
162ogEcho log session "      FileSystem $PART with $NEWSIZEFS KB data created onto file-image as $4 and used $IMGSIZE KB across DFS $ogprotocol"
163ogEcho log session "      Image-file $4 metada: $IMGOS"
[d2f28cf]164
165# Ejecuta scripts personalizado de postconfiguracion del sistema operativo modelo.
166if which createImageCustomPost &>/dev/null; then
167    createImageCustomPost "$1" "$2" "$3" "$4"
168fi
169
Note: See TracBrowser for help on using the repository browser.