1 | #!/bin/bash |
---|
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 | |
---|
24 | |
---|
25 | TIME1=$SECONDS |
---|
26 | PROG="$(basename $0)" |
---|
27 | if [ $# -ne 4 ]; then |
---|
28 | ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen" |
---|
29 | exit $? |
---|
30 | fi |
---|
31 | |
---|
32 | # Valores por defecto |
---|
33 | IMGPROG="partclone" |
---|
34 | IMGCOMP="lzop" |
---|
35 | IMGEXT="img" |
---|
36 | |
---|
37 | # Si el repositorio es CACHE comprobamos que exista |
---|
38 | if [ "$3" == "CACHE" -o "$3" == "cache" ]; then |
---|
39 | if ! $(ogFindCache >/dev/null); then |
---|
40 | ogRaiseError $OG_ERR_NOTCACHE "$MSG_ERR_NOTCACHE" |
---|
41 | exit $? |
---|
42 | fi |
---|
43 | fi |
---|
44 | |
---|
45 | # Obtener información de los parámetros de entrada. |
---|
46 | PART=$(ogDiskToDev "$1" "$2") || exit $? |
---|
47 | IMGDIR=$(ogGetParentPath "$3" "/$4") |
---|
48 | # Si no existe, crear subdirectorio de la imagen. |
---|
49 | if [ $? != 0 ]; then |
---|
50 | echo "[5] Crear subdirectorio de la imagen \"$3 $(dirname "$4")." |
---|
51 | ogMakeDir "$3" $(dirname "/$4") |
---|
52 | IMGDIR=$(ogGetParentPath "$3" "/$4") || exit $? |
---|
53 | fi |
---|
54 | IMGFILE=$IMGDIR/$(basename "/$4").$IMGEXT |
---|
55 | # Renombrar el fichero de imagen si ya existe. |
---|
56 | if [ -f "$IMGFILE" ]; then |
---|
57 | echo "[10] Renombrar \"$IMGFILE\" por \"$IMGFILE.ant\"." |
---|
58 | mv "$IMGFILE" "$IMGFILE.ant" |
---|
59 | mv "$IMGFILE.torrent" "$IMGFILE.torrent.ant" 2>/dev/null |
---|
60 | fi |
---|
61 | # Mostrar información. |
---|
62 | echo "[15] $PROG: Origen=$PART, Destino=$IMGFILE" |
---|
63 | |
---|
64 | # Comprobar consistencia del sistema de archivos. |
---|
65 | echo "[20] Comprobar sistema de archivos." |
---|
66 | ogUnmount $1 $2 |
---|
67 | ogCheckFs $1 $2 |
---|
68 | |
---|
69 | echo "[30]: Reducir sistema de archivos." |
---|
70 | ogReduceFs $1 $2 || $(ogRaiseError $OG_ERR_REDUCEFS "$1 $2"; exit $?) |
---|
71 | |
---|
72 | # Crear la imagen. |
---|
73 | echo "[40] Crear imagen." |
---|
74 | ogCreateImage $1 "$2" $3 $4 "$IMGPROG" "$IMGCOMP" || exit $? |
---|
75 | #ogCreateImage $1 "$2" $3 $4 || exit $? |
---|
76 | |
---|
77 | echo "[90] Extender sistema de archivos." |
---|
78 | ogExtendFs $1 $2 || $(ogRaiseError $OG_ERR_EXTENDFS "$1 $2"; exit $?) |
---|
79 | |
---|
80 | |
---|
81 | TIME=$[SECONDS-TIME1] |
---|
82 | echo "[100] Duracion de la operacion $[TIME/60]m $[TIME%60]s" |
---|
83 | |
---|