source: client/shared/scripts/createImage @ 12ff50f

918-git-images-111dconfigure-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-instalacion
Last change on this file since 12ff50f was 093ebcd, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #889 createImage script don't use 'ogSaveImageInfo' for Windows. 'ogSaveImageInfo' function is removed.

  • Property mode set to 100755
File size: 7.5 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.
[5b825b50]6#@brief   Se usa como base para el programa de creación de imágenes de 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
[79a4175]29#@version 1.0.2 - Separacion de log
[f311787]30#@author  Antonio J.Doblas Viso
31#@date   2011-08-4
[a6d6d6f]32#@version 1.1.0 - La copia de seguridad de la imagen antigua se hace después de las comprobaciones.
33#@author  Irina Gomez - ETSII Universidad de Sevilla
34#@date    2016-10-14
[e784187]35#@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771)
36#@author  Irina Gomez - ETSII Universidad de Sevilla
37#@date    2017-03-28
[30238ab]38#@version 1.1.1 - #802 Equipos EFI: se guarda el cargador de arranque y UUID de las particiones
39#@author  Irina Gomez - ETSII Universidad de Sevilla
40#@date    2019-01-08
[eb9424f]41#*/ ##
42
[2d40ba26]43# Test 1.  crear una imagen en un REPO sin espacio libre.
44# test 2.  crear una imagen en un REPO en modo solo lectura.
45# test 3.  intentar crear una imagen en la cache de un equipo que no la disponga.
46# test 4.  crear una imagen en la Cache sin espacio sufiente.
47# test 5.  intentar crear una imagen, en la que no se puede reducir el FS.
[f8f4dfa]48
[f311787]49
[f8f4dfa]50PROG="$(basename $0)"
51if [ $# -ne 4 ]; then
[be85bb2]52    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen"
[f8f4dfa]53    exit $?
54fi
55
[d2f28cf]56TIME1=$SECONDS
57
58#Load engine configurator from engine.cfg file.
59#Carga el configurador del engine desde el fichero engine.cfg
60[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
61
[b92b4bb]62# Valores por defecto en etc/engine.cfg
63#IMGPROG="partclone"
64#IMGCOMP="lzop"
[b9797f2]65IMGEXT=${IMGEXT:-"img"}
[b92b4bb]66#IMGREDUCE="TRUE"
[4ceafc1]67REPO="${3^^}"
[95b340a]68
[79a4175]69# Unidad organizativa
70[ "$ogunit" != "" ] && OGUNIT="$ogunit"
71
[d2f28cf]72# Clear temporary file used as log track by httpdlog
73# Limpia los ficheros temporales usados como log de seguimiento para httpdlog
[adbfa2a]74# salvo si es llamado desde createImageCustom
75if [ "$(ogGetCaller)" != "createImageCustom" ]; then
76    echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp
77fi
[f311787]78
[e7e3140]79ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
[f311787]80
[4ceafc1]81# Si es una ip y es igual a la del equipo restaura desde cache
82[ "$REPO" == "$(ogGetIpAddress)" ] && REPO="CACHE"
83# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
84ogCheckIpAddress $REPO
85if [ $? == 0 -o $REPO == "REPO" ] ; then
86        # Si falla el cambio -> salimos con error repositorio no valido
[79a4175]87        ogChangeRepo $REPO $OGUNIT || exit $(ogRaiseError $OG_ERR_NOTFOUND '$REPO'; echo $?)
[4ceafc1]88        REPO="REPO"
89fi
90
[defcdab]91# Si el repositorio es CACHE comprobamos que exista
[4ceafc1]92if [ "$REPO" == "CACHE" ]; then
[2d40ba26]93    ! ogFindCache >/dev/null && exit $(ogRaiseError $OG_ERR_NOTCACHE "CACHE "; echo $?)
[3aaf91d]94fi
[defcdab]95
[c40a6b4]96# Obtener información de los parámetros de entrada.
[2d40ba26]97PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError $OG_ERR_PARTITION "$1 $2"; echo $?)
98
99#Comprobamos acceso de escritura.
100DIRTEMP=$(date +%Y%m%d-%H%M%S)
[4ceafc1]101ogMakeDir $REPO /$4$DIRTEMP 2>/dev/null || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO"; echo $?) && ogDeleteTree $REPO /$4$DIRTEMP
[2d40ba26]102
[4ceafc1]103IMGDIR=$(ogGetParentPath "$REPO" "/$4")
[180a07dd]104# Si no existe, crear subdirectorio de la imagen.
105if [ $? != 0 ]; then
[4ceafc1]106    ogEcho log session "[5] $MSG_HELP_ogMakeDir \"$REPO $(dirname "$4")."
107    ogMakeDir "$REPO" $(dirname "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
108    IMGDIR=$(ogGetParentPath "$REPO" "/$4") || exit $(ogRaiseError $OG_ERR_NOTWRITE "$REPO /$4"; echo $?)
[180a07dd]109fi
[95b340a]110IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT
[d2f28cf]111
[e272d9e]112echo " " > $OGLOGCOMMAND
[d3dc88d]113# Borramos ficheros de paginacion y configuracion
114ogCleanOs $1 $2
115
116#Comprobar espacio que requerira la imagen para ser almacenada
[31d4f1a5]117read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$REPO" "$4")
[d2f28cf]118
[e784187]119ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE"
[4ceafc1]120[ "$ISENOUGHSPACE" == "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$REPO"; echo $?)
[2d40ba26]121
[3aaf91d]122# Comprobar consistencia del sistema de archivos.
[e272d9e]123echo " " > $OGLOGCOMMAND
124SIZEFS=$(ogGetFsSize  $1 $2)
[e7e3140]125ogEcho log session "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB)"
[d2f28cf]126ogUnmount $1 $2 2>/dev/null
[2d40ba26]127ogCheckFs $1 $2 || exit $(ogRaiseError $OG_ERR_PARTITION "ogCheckFs $1 $2" && echo $?)
[914d834]128
[30238ab]129# Si es UEFI copio el cargador de arranque a la partición
130OSTYPE="$(ogGetOsType $1 $2)"
[47d8ae8]131if ogIsEfiActive && [ "$OSTYPE" == "Windows" ]; then
[30238ab]132    ogEcho log session "[25] $MSG_HELP_ogCopyEfiBootLoader"
133    ogCopyEfiBootLoader $1 $2
134fi
135
[d2f28cf]136# Evaluar variable de engine.cfg para reducir el sistema de archivos en la creacion
137if [ "$IMGREDUCE" == "TRUE" ]
[b92b4bb]138then
[30238ab]139    ogEcho log session "[30] $MSG_HELP_ogReduceFs"
[d2f28cf]140    ogReduceFs $1 $2 &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; echo $?)
141    NEWSIZEFS=$(ogGetFsSize  $1 $2)
142    TIMEAUX=$[SECONDS-TIME1]
[e7e3140]143    ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL ( $NEWSIZEFS KB ) : $[TIMEAUX/60]m $[TIMEAUX%60]s"
[b92b4bb]144fi
[914d834]145
[a6d6d6f]146# Renombrar el fichero de imagen si ya existe.
147if [ -f "$IMGFILE" ]; then
[30238ab]148    ogEcho log session "[35] $MSG_SCRIPTS_FILE_RENAME \"$IMGFILE\" ->  \"$IMGFILE.ant\"."
[a6d6d6f]149    mv "$IMGFILE" "$IMGFILE.ant"
150    mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null
151    mv "$IMGFILE.sum" "$IMGFILE.sum.ant" 2>/dev/null
152    mv "$IMGFILE.full.sum" "$IMGFILE.full.sum.ant" 2>/dev/null
153fi
154
[6d3f526]155# Crear la imagen.
[e272d9e]156echo " " > $OGLOGCOMMAND
157TIME2=$SECONDS
[4ceafc1]158ogEcho log session "[40] $MSG_HELP_ogCreateImage : ogCreateImage $1 $2 $REPO $4 $IMGPROG $IMGCOMP"
159ogCreateImage "$1" "$2" "$REPO" "/$4" "$IMGPROG" "$IMGCOMP" &>> $OGLOGCOMMAND || exit $(ogRaiseError $OG_ERR_IMAGE "ogCreteImage"; echo $?)
[d2f28cf]160RESUMECREATEIMAGE=$(grep "Total Time:" $OGLOGCOMMAND)
[e272d9e]161TIMEAUX2=$[SECONDS-TIME2]
[e7e3140]162ogEcho log session "      $RESUMECREATEIMAGE "
163ogEcho log session "      $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX2/60]m $[TIMEAUX2%60]s"
[e272d9e]164
[d2f28cf]165# Extender sistema de archivos
[e272d9e]166TIME3=$SECONDS
[e7e3140]167ogEcho log session "[90] Extender sistema de archivos."
[2d40ba26]168ogExtendFs $1 $2 || exit $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; echo $?)
[e272d9e]169SIZEFS2=$(ogGetFsSize  $1 $2)
170TIMEAUX3=$[SECONDS-TIME3]
[e7e3140]171ogEcho log session "      $MSG_HELP_ogExtendFs  $NEWSIZEFS ->  $SIZEFS = $SIZEFS2: $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
[e272d9e]172
173#TODO que hacer si error al extender sistemade archivos
[eb9424f]174
[e272d9e]175#resumen de la operacion
[4ceafc1]176IMGSIZE=$(ls -s `ogGetPath $REPO /$4.$IMGEXT`| cut -f1 -d" ")
177IMGOS=$(ogGetImageInfo `ogGetPath $REPO /$4.$IMGEXT`)
[e272d9e]178
179TIME=$[SECONDS-TIME1]
[e7e3140]180ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
181ogEcho log session "      FileSystem $PART with $NEWSIZEFS KB data created onto file-image as $4 and used $IMGSIZE KB across DFS $ogprotocol"
182ogEcho log session "      Image-file $4 metada: $IMGOS"
Note: See TracBrowser for help on using the repository browser.