[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 |
---|
| 12 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 13 | #@exception OG_ERR_NOTCACHE #si cache no existe. |
---|
| 14 | #@exception OG_ERR_REDUCEFS #error al reducir sistema de archivos. |
---|
| 15 | #@exception OG_ERR_EXTENDFS #errror al expandir el sistema de archivos. |
---|
| 16 | #@note |
---|
| 17 | #@todo: |
---|
| 18 | #@version 1.0 - control de errores para el ogAdmServer |
---|
| 19 | #@author |
---|
| 20 | #@date |
---|
| 21 | #*/ ## |
---|
| 22 | |
---|
| 23 | |
---|
[f8f4dfa] | 24 | |
---|
[f5432db7] | 25 | TIME1=$SECONDS |
---|
[f8f4dfa] | 26 | PROG="$(basename $0)" |
---|
| 27 | if [ $# -ne 4 ]; then |
---|
[be85bb2] | 28 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen" |
---|
[f8f4dfa] | 29 | exit $? |
---|
| 30 | fi |
---|
| 31 | |
---|
[95b340a] | 32 | # Valores por defecto |
---|
| 33 | IMGPROG="partclone" |
---|
| 34 | IMGCOMP="lzop" |
---|
| 35 | IMGEXT="img" |
---|
| 36 | |
---|
[defcdab] | 37 | # Si el repositorio es CACHE comprobamos que exista |
---|
[3aaf91d] | 38 | if [ "$3" == "CACHE" -o "$3" == "cache" ]; then |
---|
| 39 | if ! $(ogFindCache >/dev/null); then |
---|
[eb9424f] | 40 | ogRaiseError $OG_ERR_NOTCACHE "$MSG_ERR_NOTCACHE" |
---|
[3aaf91d] | 41 | exit $? |
---|
| 42 | fi |
---|
| 43 | fi |
---|
[defcdab] | 44 | |
---|
[c40a6b4] | 45 | # Obtener información de los parámetros de entrada. |
---|
[f8f4dfa] | 46 | PART=$(ogDiskToDev "$1" "$2") || exit $? |
---|
[a3fb8b2] | 47 | IMGDIR=$(ogGetParentPath "$3" "/$4") |
---|
[180a07dd] | 48 | # Si no existe, crear subdirectorio de la imagen. |
---|
| 49 | if [ $? != 0 ]; then |
---|
| 50 | echo "[5] Crear subdirectorio de la imagen \"$3 $(dirname "$4")." |
---|
[a3fb8b2] | 51 | ogMakeDir "$3" $(dirname "/$4") |
---|
| 52 | IMGDIR=$(ogGetParentPath "$3" "/$4") || exit $? |
---|
[180a07dd] | 53 | fi |
---|
[95b340a] | 54 | IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT |
---|
[f8f4dfa] | 55 | # Renombrar el fichero de imagen si ya existe. |
---|
| 56 | if [ -f "$IMGFILE" ]; then |
---|
[180a07dd] | 57 | echo "[10] Renombrar \"$IMGFILE\" por \"$IMGFILE.ant\"." |
---|
[f8f4dfa] | 58 | mv "$IMGFILE" "$IMGFILE.ant" |
---|
[0fbc05e] | 59 | mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null |
---|
[f8f4dfa] | 60 | fi |
---|
[41d9755] | 61 | # Mostrar información. |
---|
| 62 | echo "[15] $PROG: Origen=$PART, Destino=$IMGFILE" |
---|
[f8f4dfa] | 63 | |
---|
[3aaf91d] | 64 | # Comprobar consistencia del sistema de archivos. |
---|
[6d3f526] | 65 | echo "[20] Comprobar sistema de archivos." |
---|
[914d834] | 66 | ogUnmount $1 $2 |
---|
[95b340a] | 67 | ogCheckFs $1 $2 |
---|
[914d834] | 68 | |
---|
[95b340a] | 69 | echo "[30]: Reducir sistema de archivos." |
---|
[eb9424f] | 70 | ogReduceFs $1 $2 || $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; exit $?) |
---|
[914d834] | 71 | |
---|
[6d3f526] | 72 | # Crear la imagen. |
---|
[95b340a] | 73 | echo "[40] Crear imagen." |
---|
| 74 | ogCreateImage $1 "$2" $3 $4 "$IMGPROG" "$IMGCOMP" || exit $? |
---|
[e69c224] | 75 | #ogCreateImage $1 "$2" $3 $4 || exit $? |
---|
[6d3f526] | 76 | |
---|
[914d834] | 77 | echo "[90] Extender sistema de archivos." |
---|
[eb9424f] | 78 | ogExtendFs $1 $2 || $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; exit $?) |
---|
| 79 | |
---|
[914d834] | 80 | |
---|
[f5432db7] | 81 | TIME=$[SECONDS-TIME1] |
---|
[bfeb89a] | 82 | echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" |
---|
[f8f4dfa] | 83 | |
---|