[715bedc] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file Image.lib |
---|
| 4 | #@brief Librería o clase Image |
---|
| 5 | #@class Image |
---|
| 6 | #@brief Funciones para creación, restauración y clonación de imágenes de sistemas. |
---|
| 7 | #@version 0.9 |
---|
| 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | #/** |
---|
[ebf06c7] | 13 | # ogCreateImage int_ndisk int_npartition str_repo path_image |
---|
[715bedc] | 14 | #@brief Crea una imagen a partir de una partición. |
---|
[42669ebf] | 15 | #@param int_ndisk nº de orden del disco |
---|
| 16 | #@param int_npartition nº de orden de la partición |
---|
| 17 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
| 18 | #@param path_image camino de la imagen (sin extensión) |
---|
[715bedc] | 19 | #@return (nada, por determinar) |
---|
[ebf06c7] | 20 | #@note repo = { REPO, CACHE } |
---|
[cfeabbf] | 21 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 22 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
| 23 | #@exception OG_ERR_PARTITION partición no accesible o no soportada. |
---|
| 24 | #@exception OG_ERR_LOCKED particion bloqueada por otra operación. |
---|
| 25 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
[715bedc] | 26 | #@warning En pruebas iniciales |
---|
[3458879] | 27 | #@todo Comprobaciones, control de errores, definir parámetros, etc. |
---|
[985bef0] | 28 | #@version 0.1 - Integracion para Opengnsys - HIDRA:CrearImagen{EXT3, NTFS}.sh; EAC: CreateImageFromPartition () en Deploy.lib |
---|
| 29 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 30 | #@Date 2008/05/13 |
---|
| 31 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 32 | #@date 2008/10/27 |
---|
[0fbc05e] | 33 | #@version 0.9 - Versión en pruebas para OpenGnSys |
---|
[715bedc] | 34 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[cfeabbf] | 35 | #@date 2009/10/07 |
---|
[1e7eaab] | 36 | #*/ ## |
---|
[42669ebf] | 37 | function ogCreateImage () |
---|
| 38 | { |
---|
[59f9ad2] | 39 | # Variables locales |
---|
[08b941f] | 40 | local PART PROGRAM IMGDIR IMGFILE IMGTYPE ERRCODE |
---|
[59f9ad2] | 41 | |
---|
[42669ebf] | 42 | # Si se solicita, mostrar ayuda. |
---|
[59f9ad2] | 43 | if [ "$*" == "help" ]; then |
---|
| 44 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart path_dir str_image" \ |
---|
[3543b3e] | 45 | "$FUNCNAME 1 1 REPO /aula1/winxp" |
---|
[59f9ad2] | 46 | return |
---|
| 47 | fi |
---|
[c136ae7] | 48 | # Error si no se reciben 4 parámetros. |
---|
[0fbc05e] | 49 | [ $# -ne 4 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[59f9ad2] | 50 | |
---|
[08b941f] | 51 | # Comprobar que no está bloqueada ni la partición, ni la imagen. |
---|
[715bedc] | 52 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
[a79dd508] | 53 | if ogIsLocked $1 $2; then |
---|
[08b941f] | 54 | ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $1, $2" |
---|
[a79dd508] | 55 | return $? |
---|
| 56 | fi |
---|
[08b941f] | 57 | IMGTYPE="pgz" # Partclone / GZip |
---|
[cfeabbf] | 58 | IMGDIR=$(ogGetParentPath "$3" "$4") |
---|
| 59 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$3 $(dirname $4)" || return $? |
---|
[08b941f] | 60 | IMGFILE="$IMGDIR/$(basename "$4").$IMGTYPE" |
---|
| 61 | if ogIsImageLocked "$IMGFILE"; then |
---|
| 62 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $3, $4" |
---|
| 63 | return $? |
---|
| 64 | fi |
---|
| 65 | # Desmontar partición, bloquear partición e imagen. |
---|
[cfeabbf] | 66 | ogUnmount $1 $2 2>/dev/null |
---|
[a79dd508] | 67 | ogLock $1 $2 || return $? |
---|
[08b941f] | 68 | ogLockImage "$3" "$4.$IMGTYPE" || return $? |
---|
[715bedc] | 69 | |
---|
[08b941f] | 70 | # Crear Imagen. |
---|
| 71 | trap "ogUnlock $1 $2; ogUnlockImage "$3" "$4.$IMGTYPE"; rm -f $IMGFILE" 1 2 3 6 9 |
---|
[715bedc] | 72 | TYPE="$(ogGetFsType $1 $2)" |
---|
| 73 | case "$TYPE" in |
---|
[5919303] | 74 | EXT[234]) |
---|
| 75 | PROGRAM=partclone.extfs ;; |
---|
[0fbc05e] | 76 | REISERFS|XFS|JFS) |
---|
[5919303] | 77 | PROGRAM=partclone.dd ;; |
---|
[715bedc] | 78 | NTFS|HNTFS) |
---|
[5919303] | 79 | PROGRAM=partclone.ntfs ;; |
---|
[59f9ad2] | 80 | FAT16|FAT32|HFAT16|HFAT32) |
---|
[5919303] | 81 | PROGRAM=partclone.fat ;; |
---|
[0fbc05e] | 82 | HFS|HFS+) |
---|
[5919303] | 83 | PROGRAM=partclone.hfsp ;; |
---|
[cfeabbf] | 84 | *) ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE" |
---|
[715bedc] | 85 | return $? ;; |
---|
| 86 | esac |
---|
[5919303] | 87 | $PROGRAM -c -C -F -s $PART | mbuffer -q -m 70% | gzip -c > "$IMGFILE" |
---|
[08b941f] | 88 | |
---|
[42669ebf] | 89 | # Controlar salida de error y desbloquear partición. |
---|
[cfeabbf] | 90 | ERRCODE=$? |
---|
[f5432db7] | 91 | if [ $ERRCODE != 0 ]; then |
---|
[cfeabbf] | 92 | ogRaiseError $OG_ERR_IMAGE "$1 $2 $IMGFILE" |
---|
[f5432db7] | 93 | rm -f "$IMGFILE" |
---|
[cfeabbf] | 94 | fi |
---|
[08b941f] | 95 | # Desbloquear partición e imagen. |
---|
[715bedc] | 96 | ogUnlock $1 $2 |
---|
[08b941f] | 97 | ogUnlockImage "$3" "$4.$IMGTYPE" |
---|
[cfeabbf] | 98 | return $ERRCODE |
---|
[715bedc] | 99 | } |
---|
| 100 | |
---|
[b094c59] | 101 | |
---|
| 102 | #/** |
---|
[0fbc05e] | 103 | # ogGetImageFs str_repo path_image |
---|
| 104 | #@brief Devuelve el tipo de sistema de archivos almacenado en un fichero de imagen. |
---|
| 105 | #@param str_repo repositorio de imágenes o caché local |
---|
| 106 | #@param path_image camino de la imagen |
---|
| 107 | #@return str_imgtype - mnemónico del tipo de sistema de archivos |
---|
| 108 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 109 | #@exception OG_ERR_NOTFOUND fichero de imagen no encontrado. |
---|
| 110 | #@todo Comprobar salidas para todos los tipos de sistemas de archivos. |
---|
| 111 | #/** |
---|
| 112 | function ogGetImageFs () |
---|
| 113 | { |
---|
| 114 | local IMGFILE IMGTYPE |
---|
| 115 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 116 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") || return $? |
---|
| 117 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 118 | case "$IMGTYPE" in |
---|
| 119 | img) # Partimage. |
---|
| 120 | partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 121 | awk '/^Filesystem/ {sub(/\.\.+/," "); if ($2=="ntfs") print NTFS; |
---|
| 122 | else { sub(/fs$/,""); print toupper($2);} }' |
---|
| 123 | ;; |
---|
| 124 | pgz) # Partclone / GZip |
---|
| 125 | gzip -dc "$IMGFILE" | partclone.chkimg -C -s - 2>&1 | \ |
---|
| 126 | awk '/^File system/ {if ($2=="EXTFS") print "EXT3"; else print $3;}' |
---|
| 127 | ;; |
---|
| 128 | *) # Error si el fichero de imagen no es accesible. |
---|
| 129 | ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" |
---|
| 130 | return $? ;; |
---|
| 131 | esac |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
[39277f4] | 135 | # ogGetImageSize str_repo path_image |
---|
[b094c59] | 136 | #@brief Devuelve el tamaño del sistema de archivos almacenado en un fichero de imagen. |
---|
[42669ebf] | 137 | #@param str_repo repositorio de imágenes o caché local |
---|
| 138 | #@param path_image camino de la imagen |
---|
[0fbc05e] | 139 | #@return int_size - tamaño (en KB) |
---|
[b094c59] | 140 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 141 | #@exception OG_ERR_NOTFOUND fichero de imagen no encontrado. |
---|
| 142 | #*/ |
---|
| 143 | #@warning En pruebas iniciales |
---|
| 144 | #@todo Definición de parámetros y salidas. |
---|
| 145 | #@version 0.1 - Primera versión muy en pruebas para OpenGNSys |
---|
| 146 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 147 | #@date 2009/09/11 |
---|
[1e7eaab] | 148 | #*/ ## |
---|
[42669ebf] | 149 | function ogGetImageSize () |
---|
| 150 | { |
---|
[b094c59] | 151 | # Variables locales |
---|
[0fbc05e] | 152 | local IMGFILE IMGTYPE |
---|
[b094c59] | 153 | |
---|
[42669ebf] | 154 | # Si se solicita, mostrar ayuda. |
---|
[b094c59] | 155 | if [ "$*" == "help" ]; then |
---|
| 156 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk int_npart" \ |
---|
[3543b3e] | 157 | "$FUNCNAME 1 1 REPO /aula1/winxp ==> 5642158" |
---|
[b094c59] | 158 | return |
---|
| 159 | fi |
---|
[42669ebf] | 160 | # Error si no se reciben menos de 2 parámetros. |
---|
[0fbc05e] | 161 | [ $# -ne 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[42669ebf] | 162 | # Devuelve el tamaño de la imagen en KB. |
---|
[0fbc05e] | 163 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 164 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
| 165 | case "$IMGTYPE" in |
---|
| 166 | img) # Partimage. |
---|
| 167 | partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 168 | awk '/Partition size/ {sub(/\.\.+/," "); ps=$3} END {print ps*1024*1024;}' |
---|
| 169 | ;; |
---|
| 170 | pgz) # Partclone / GZip |
---|
| 171 | gzip -dc "$IMGFILE" | partclone.chkimg -C -s - 2>&1 | \ |
---|
| 172 | awk -F: '/Block size/ {bs=$2} /Used block/ {ub=$2} END {print bs*ub/1024}' |
---|
| 173 | ;; |
---|
| 174 | *) # Error si el fichero de imagen no es accesible. |
---|
| 175 | ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" |
---|
| 176 | return $? ;; |
---|
| 177 | esac |
---|
[b094c59] | 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
[39277f4] | 181 | #### PRUEBAS |
---|
| 182 | # Obtener tipo de imagen |
---|
[42669ebf] | 183 | function ogGetImageType () |
---|
| 184 | { |
---|
[0fbc05e] | 185 | local IMGFILE IMGTYPE EXT |
---|
| 186 | for EXT in img pgz; do |
---|
| 187 | IMGFILE=$(ogGetPath "$1" "$2.$EXT") |
---|
| 188 | [ -r "$IMGFILE" ] && IMGTYPE="$EXT" |
---|
| 189 | done |
---|
| 190 | echo $IMGTYPE |
---|
[39277f4] | 191 | } |
---|
| 192 | |
---|
[08b941f] | 193 | # Comprobar si el fichero de bloqueo para una imagen. |
---|
| 194 | function ogIsImageLocked () |
---|
| 195 | { |
---|
| 196 | # Variables locales |
---|
| 197 | local IMGDIR |
---|
| 198 | |
---|
| 199 | # Si se solicita, mostrar ayuda. |
---|
| 200 | if [ "$*" == "help" ]; then |
---|
| 201 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 202 | "if $FUNCNAME /opt/opengnsys/images/aula1/winxp.img; then ...; fi" \ |
---|
| 203 | "if $FUNCNAME REPO /aula1/winxp.img; then ...; fi" |
---|
| 204 | return |
---|
| 205 | fi |
---|
| 206 | # Comprobar si existe el fichero de bloqueo. |
---|
| 207 | test -n "$(ogGetPath $@.lock)" |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | # Bloquear imagen para creación. |
---|
| 211 | function ogLockImage () |
---|
| 212 | { |
---|
| 213 | # Variables locales |
---|
| 214 | local IMGDIR |
---|
| 215 | |
---|
| 216 | # Si se solicita, mostrar ayuda. |
---|
| 217 | if [ "$*" == "help" ]; then |
---|
| 218 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 219 | "$FUNCNAME /opt/opengnsys/images/aula1/winxp.img" \ |
---|
| 220 | "$FUNCNAME REPO /aula1/winxp.img" |
---|
| 221 | return |
---|
| 222 | fi |
---|
| 223 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 224 | [ $# -lt 1 -o $# -gt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 225 | # Comprobar que existe directorio de imagen |
---|
| 226 | IMGDIR=$(ogGetParentPath $@) || return $? |
---|
| 227 | # Crear fichero de bloqueo. |
---|
| 228 | touch $IMGDIR/$(basename "${!#}").lock |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | # Desbloquear imagen (borrar fichero de bloqueo). |
---|
| 232 | function ogUnlockImage () |
---|
| 233 | { |
---|
| 234 | # Variables locales |
---|
| 235 | local IMGDIR |
---|
| 236 | |
---|
| 237 | # Si se solicita, mostrar ayuda. |
---|
| 238 | if [ "$*" == "help" ]; then |
---|
| 239 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 240 | "$FUNCNAME /opt/opengnsys/images/aula1/winxp.img" \ |
---|
| 241 | "$FUNCNAME REPO /aula1/winxp.img" |
---|
| 242 | return |
---|
| 243 | fi |
---|
| 244 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 245 | [ $# -lt 1 -o $# -gt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 246 | # Borrar fichero de bloqueo para la imagen. |
---|
| 247 | rm -f $(ogGetPath $@.lock) |
---|
| 248 | } |
---|
| 249 | |
---|
[b094c59] | 250 | #/** |
---|
[39277f4] | 251 | # ogRestoreImage str_repo path_image int_ndisk int_npartition |
---|
[b094c59] | 252 | #@brief Restaura una imagen de sistema de archivos en una partición. |
---|
[42669ebf] | 253 | #@param str_repo repositorio de imágenes o caché local |
---|
| 254 | #@param path_image camino de la imagen |
---|
| 255 | #@param int_ndisk nº de orden del disco |
---|
| 256 | #@param int_npartition nº de orden de la partición |
---|
[b094c59] | 257 | #@return (por determinar) |
---|
| 258 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 259 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
| 260 | #@exception OG_ERR_LOCKED partición bloqueada por otra operación. |
---|
| 261 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
[39277f4] | 262 | #@todo Comprobar incongruencias partición-imagen, control de errores, definir parámetros, caché/repositorio, etc. |
---|
[0fbc05e] | 263 | #@version 0.1 - Integracion para Opengnsys - HIDRA:RestaurarImagen{EXT3, NTFS}.sh; EAC: RestorePartitionFromImage() en Deploy.lib |
---|
[985bef0] | 264 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 265 | #@Date 2008/05/13 |
---|
| 266 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 267 | #@date 2008/10/27 |
---|
[0fbc05e] | 268 | #@version 0.9 - Primera version muy en pruebas para OpenGnSys |
---|
[b094c59] | 269 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 270 | #@date 2009/09/10 |
---|
[1e7eaab] | 271 | #*/ ## |
---|
[42669ebf] | 272 | function ogRestoreImage () |
---|
| 273 | { |
---|
[b094c59] | 274 | # Variables locales |
---|
[0fbc05e] | 275 | local PART PARTSIZE IMGFILE IMGTYPE IMGSIZE FSTYPE |
---|
[b094c59] | 276 | |
---|
[42669ebf] | 277 | # Si se solicita, mostrar ayuda. |
---|
[b094c59] | 278 | if [ "$*" == "help" ]; then |
---|
| 279 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk int_npart" \ |
---|
[3543b3e] | 280 | "$FUNCNAME REPO /aula1/winxp 1 1" |
---|
[b094c59] | 281 | return |
---|
| 282 | fi |
---|
[42669ebf] | 283 | # Error si no se reciben 4 parámetros. |
---|
[b094c59] | 284 | [ $# -lt 4 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[3458879] | 285 | # Procesar parámetros. |
---|
| 286 | PART="$(ogDiskToDev "$3" "$4")" || return $? |
---|
[0fbc05e] | 287 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 288 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
[b094c59] | 289 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
[42669ebf] | 290 | # Error si la imagen no cabe en la particion. |
---|
[3458879] | 291 | IMGSIZE=$(ogGetImageSize "$1" "$2") |
---|
| 292 | PARTSIZE=$(ogGetPartitionSize $3 $4) |
---|
| 293 | if [ $IMGSIZE -gt $PARTSIZE ]; then |
---|
| 294 | ogRaiseError $OG_ERR_PARTITION "$IMGSIZE > $PARTSIZE" |
---|
| 295 | return $? |
---|
| 296 | fi |
---|
[b094c59] | 297 | |
---|
[08b941f] | 298 | # Comprobar el bloqueo de la imagen y de la partición. |
---|
| 299 | if ogIsImageLocked "$IMGFILE"; then |
---|
| 300 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $1, $2.$IMGTYPE" |
---|
| 301 | return $? |
---|
| 302 | fi |
---|
[39277f4] | 303 | if ogIsLocked $3 $4; then |
---|
[08b941f] | 304 | ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $3, $4" |
---|
[39277f4] | 305 | return $? |
---|
| 306 | fi |
---|
[08b941f] | 307 | # Desmontar y bloquear partición. |
---|
[f5432db7] | 308 | ogUnmount $3 $4 2>/dev/null || return $? |
---|
[39277f4] | 309 | ogLock $3 $4 || return $? |
---|
[b094c59] | 310 | trap "ogUnlock $3 $4" 1 2 3 6 9 |
---|
| 311 | |
---|
[0fbc05e] | 312 | # Restaurar según el tipo de imagen. |
---|
| 313 | # Atención: no se comprueba el tipo de sistema de archivos. |
---|
[42669ebf] | 314 | # Atención: no se comprueba incongruencia entre partición e imagen. |
---|
[0fbc05e] | 315 | #FSTYPE="$(ogGetFsType $3 $4)" |
---|
| 316 | case "$IMGTYPE" in |
---|
| 317 | img) # Partimage |
---|
| 318 | partimage -M -f3 -o -d -V0 -B gui=no -c -z1 --volume=0 restore $PART "$IMGFILE" |
---|
| 319 | ;; |
---|
| 320 | pgz) # Partclone / GZip |
---|
[5919303] | 321 | gzip -dc "$IMGFILE" | mbuffer -q -m 70% | partclone.restore -C -F -o "$PART" |
---|
[0fbc05e] | 322 | ;; |
---|
| 323 | *) # Error si imagen no accesible o de tipo desconocido. |
---|
| 324 | ogRaiseError $OG_ERR_FORMAT |
---|
| 325 | return $? ;; |
---|
[b094c59] | 326 | esac |
---|
[f5432db7] | 327 | ERRCODE=$? |
---|
| 328 | if [ $ERRCODE != 0 ]; then |
---|
| 329 | ogRaiseError $OG_ERR_IMAGE "$IMGFILE, $3, $4" |
---|
| 330 | fi |
---|
[b094c59] | 331 | ogUnlock $3 $4 |
---|
[f5432db7] | 332 | return $ERRCODE |
---|
[b094c59] | 333 | } |
---|
| 334 | |
---|
[8f4c506] | 335 | |
---|
| 336 | function ogCreateImageFromPartition () { |
---|
| 337 | #/** @function CreateImageFromPartition: @brief Crea una imagen de la particion indicada, utilizando el programa definido en las variable $CloneImageNTFS y $CloneImageEXT23 |
---|
| 338 | #@param $1 int DiskEAC |
---|
| 339 | #@param $2 int_PartitionEAC |
---|
| 340 | #@param $3 str_Repositorio ......... parametro pasado a ConectToRepo, admite $REPO $CACHE str_IP_servidorAlterno |
---|
| 341 | #@param $4 str_pathbase .............. Pathbase, directorio relativo, de la imagen, en EAC, se ha definido que todo repositorio comience por hdimages, pero puede variar, para adaparse a usb, o cualquier otro almacenamiento. |
---|
| 342 | #@param $5 str_NameImage.str_compresion .......... (como compresion admite gzip y lzop) |
---|
| 343 | #@param ejemplo: CreateImageFromPartition 1 1 $IP hdimages/pruebas/ base.gzip |
---|
| 344 | #@return la propia de la herramienta de clonacion partimage o ntfsclone |
---|
| 345 | #@return genera la imagen con el nombre (imagen.compresion), y se le a?ade un guion y el numero de particion(parametro $2). |
---|
| 346 | #@return Tambien se solicita al servidor EAC, la creaci?n del fichero meta torrent, que tendra el nombre tal base.gzip-1.torrent, |
---|
| 347 | #@return Tambien se crea el fichero base.gzip-1.mcast con informacion para su uso con multicast, tal base.gzip-1.mcast |
---|
| 348 | #@warning Salidas de errores no determinada |
---|
| 349 | #@attention |
---|
| 350 | #@note Pendiente: que admita como segundo parametro el valor 0 (para que identifique el MBR del disco) |
---|
| 351 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 352 | #*/ |
---|
| 353 | if [ $# != 5 ] |
---|
| 354 | then |
---|
[8f20481] | 355 | echo "sintaxis: CreateImageFromPartition <ndisco> <nparticion> <iprespositorio> <pathbase> <nombreimagen.compresion>" |
---|
| 356 | echo "ejemplo: CreateImageFromPartition 1 1 \$IP images/pruebas/ base.gzip" |
---|
| 357 | echo " en iprepositorio admite cualquier ip de un servdior EAC, se llama a la funcion MountRepo ip" |
---|
[8f4c506] | 358 | fi |
---|
| 359 | if [ $# = 5 ] |
---|
| 360 | then |
---|
[8f20481] | 361 | CloneImageNTFS="${CLONETOOLSNTFS:-partimage}" |
---|
| 362 | CloneImageEXT23="${CLONETOOLSEXT:-partimage}" |
---|
| 363 | CompresionImage="${CLONETOOLSCOMPRESSOR:-gzip}" |
---|
| 364 | |
---|
[8f4c506] | 365 | disco=`ogDiskToDev $1 $2` |
---|
| 366 | ogUnmountPartition $1 $2 |
---|
| 367 | fs=`ogGetFsType $1 $2` |
---|
[8f20481] | 368 | |
---|
[8f4c506] | 369 | echo determinando tipo de Sistema Operativo y consulando la variable global CloneImageNTFS: $fs |
---|
| 370 | case $fs in |
---|
| 371 | "NTFS") |
---|
| 372 | case $CloneImageNTFS in |
---|
| 373 | "ntfsclone") |
---|
| 374 | #imaged="ntfsclone --force --save-image -O - $disco | " |
---|
| 375 | imaged="ntfsclone --force --save-image -O - $disco" |
---|
| 376 | program=ntfsclone |
---|
| 377 | ;; |
---|
| 378 | "partimage") |
---|
| 379 | #imaged="partimage -M -f3 -o -d -B gui=no -c -z0 --volume=0 save $disco stdout |" |
---|
| 380 | imaged="partimage -M -f3 -o -d -B gui=no -c -z0 --volume=0 save $disco stdout" |
---|
| 381 | program=partimage |
---|
| 382 | ;; |
---|
| 383 | "partimage-ng") |
---|
| 384 | #echo "partimage-ng" |
---|
| 385 | #imaged="partimage-ng save $disco stdout" |
---|
| 386 | program=partimage-ng |
---|
| 387 | ;; |
---|
| 388 | "partclone") |
---|
| 389 | #echo "partclone" |
---|
| 390 | #imaged="partclone.ntfs -c -F -s $disco | " |
---|
| 391 | imaged="partclone.ntfs -c -F -s $disco" |
---|
| 392 | program=partclone.ntfs |
---|
| 393 | #zcat ~/image_sda1.pcl.gz | partclone.ext4 -r -o /dev/sda1 |
---|
| 394 | ;; |
---|
| 395 | esac |
---|
| 396 | ;; |
---|
| 397 | EXT[234]|REISERFS) |
---|
| 398 | case $CloneImageEXT23 in |
---|
| 399 | "partimage") |
---|
| 400 | imaged="partimage -M -f3 -o -d -B gui=no -c -z0 --volume=0 save $disco stdout" |
---|
| 401 | program=partimage |
---|
| 402 | ;; |
---|
| 403 | "partimage-ng") |
---|
| 404 | #echo "partimage-ng" |
---|
| 405 | imaged="partimage-ng save $disco stdout" |
---|
| 406 | program=partimage-ng |
---|
| 407 | ;; |
---|
| 408 | "partclone") |
---|
| 409 | echo "partclone" |
---|
| 410 | imaged="partclone.ext3 -c -F -C -s $disco" |
---|
| 411 | program=partclone.ext3 |
---|
| 412 | #zcat ~/image_sda1.pcl.gz | partclone.ext4 -r -o /dev/sda1 |
---|
| 413 | ;; |
---|
| 414 | esac |
---|
| 415 | ;; |
---|
| 416 | esac |
---|
| 417 | |
---|
| 418 | # utilizando mbuffer para reducir posibles errores de acceso a discos |
---|
| 419 | imaged="$imaged | mbuffer -m 70%" |
---|
| 420 | #metodo de compresion. |
---|
[8f20481] | 421 | case $CompresionImage in |
---|
| 422 | "gzip") |
---|
| 423 | comando="$imaged | gzip -c >" |
---|
| 424 | ;; |
---|
| 425 | "lzop") |
---|
| 426 | comando="$imaged | lzop >" |
---|
| 427 | ;; |
---|
| 428 | esac |
---|
| 429 | |
---|
[8f4c506] | 430 | #. determnamos el fichero donde se almacenar? la image |
---|
| 431 | #camino=`ConnectToRepo $3 $4 $5` |
---|
| 432 | #MkdirPath $camino |
---|
| 433 | firstcamino=`ogNewPath $3 $4` |
---|
| 434 | camino=$firstcamino$5 |
---|
| 435 | echo $camino |
---|
| 436 | sleep 1 |
---|
[8f20481] | 437 | |
---|
[8f4c506] | 438 | #preparamos y ejecutamos el comanod a realizar |
---|
| 439 | echo "Creando imagen particion $disco programa $program compresion $CompresionImage en el repositorio $3 como $4 $5 - $2" |
---|
| 440 | comando="$comando ${camino}-$2" |
---|
| 441 | echo "comando: $comando" |
---|
| 442 | echo $comando > /tmp/run.sh |
---|
| 443 | sh /tmp/run.sh |
---|
| 444 | unset comando |
---|
[8f20481] | 445 | |
---|
[8f4c506] | 446 | #iniciamos la creacion del torrent |
---|
| 447 | echo "Iniciando la creacion del punto torrent con CreateTorrentFromImage ip=$3 path=$4 image=$5-$2" echo |
---|
[8f20481] | 448 | #CreateTorrentFromImage $3 $4 $5-$2 |
---|
[8f4c506] | 449 | # iniciacmos el putno mcast |
---|
| 450 | echo "creando un punto mcast ${camino}-$2.mcast" |
---|
| 451 | echo "program;$program" > ${camino}.mcast |
---|
| 452 | echo "compresion;$CompresionImage" >> ${camino}.mcast |
---|
| 453 | echo "fsimage;$fs" >> ${camino}.mcast |
---|
| 454 | |
---|
| 455 | #UmountRepo $3 |
---|
| 456 | fi |
---|
| 457 | } |
---|