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
Line | |
---|
1 | #!/bin/bash |
---|
2 | # create-image.sh - Scirpt de ejemplo para crear una imagen de un sistema de archivos. |
---|
3 | # (puede usarse como base para el programa de creación de imágenes usado por OpenGNSys Admin). |
---|
4 | |
---|
5 | TIME1=$SECONDS |
---|
6 | PROG="$(basename $0)" |
---|
7 | if [ $# -ne 4 ]; then |
---|
8 | ogRaiseError $OG_ERR_FORMAT "Formato: $PROG ndisco nparticion REPO|CACHE imagen" |
---|
9 | exit $? |
---|
10 | fi |
---|
11 | |
---|
12 | # Obtener información de los parámetros de entrada. |
---|
13 | PART=$(ogDiskToDev "$1" "$2") || exit $? |
---|
14 | IMGDIR=$(ogGetParentPath "$3" "$4") || exit $? |
---|
15 | IMGFILE="$IMGDIR/$(basename $4).img" |
---|
16 | # Renombrar el fichero de imagen si ya existe. |
---|
17 | if [ -f "$IMGFILE" ]; then |
---|
18 | mv "$IMGFILE" "$IMGFILE.ant" |
---|
19 | fi |
---|
20 | # Mostrar información. |
---|
21 | ogEcho info "$PROG: Origen=$PART, Destino=$IMGFILE" |
---|
22 | |
---|
23 | # Obtener tamaño de la partición. |
---|
24 | SIZE=$(ogGetPartitionSize "$1" "$2") |
---|
25 | # Reducir el sistema de archvios. |
---|
26 | ogEcho info "$PROG: reducir sistema de archivos." |
---|
27 | REDSIZE=$(ogReduceFs $1 $2) || REDSIZE=$[SIZE+1] |
---|
28 | if [ $REDSIZE -lt $SIZE ]; then |
---|
29 | ogEcho info "$PROG: redimensionar partición a $REDSIZE KB." |
---|
30 | ogSetPartitionSize $1 $2 $REDSIZE |
---|
31 | fi |
---|
32 | # Crear la imagen. |
---|
33 | ogEcho info "$PROG: Crear imagen." |
---|
34 | ogCreateImage "$@" |
---|
35 | EXITCODE=$? |
---|
36 | # Restaurar tamaño. |
---|
37 | if [ $REDSIZE -lt $SIZE ]; then |
---|
38 | ogEcho info "$PROG: redimensionar partición a $SIZE KB." |
---|
39 | ogSetPartitionSize $1 $2 $SIZE |
---|
40 | ogEcho info "$PROG: extender sistema de archivos." |
---|
41 | ogExtendFs $1 $2 |
---|
42 | fi |
---|
43 | TIME=$[SECONDS-TIME1] |
---|
44 | ogEcho info "$PROG: Duración de la operación $[TIME/60]m $[TIME%60]s" |
---|
45 | exit $EXITCODE |
---|
46 | |
---|
Note: See
TracBrowser
for help on using the repository browser.