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 1.1.0 |
---|
8 | #@warning License: GNU GPLv3+ |
---|
9 | #*/ |
---|
10 | |
---|
11 | |
---|
12 | #/** |
---|
13 | # ogCreateImageSyntax path_device path_filename [str_tool] [str_compressionlevel] |
---|
14 | #@brief Genera una cadena de texto con la instrucción para crear un fichero imagen |
---|
15 | #@param path_device dispositivo Linux del sistema de archivos |
---|
16 | #@param path_fileneme path absoluto del fichero imagen |
---|
17 | #@param [opcional] str_tool herrmaienta de clonacion [partimage, partclone, ntfsclone] |
---|
18 | #@param [opcional] str_compressionlevel nivel de compresion. [0 -none-, 1-lzop-, 2-gzip] |
---|
19 | #@return str_command - cadena con el comando que se debe ejecutar. |
---|
20 | #@warning Salida nula si se producen errores. |
---|
21 | #@TODO introducir las herramientas fsarchiver, dd |
---|
22 | #@version 1.0 - Primeras pruebas |
---|
23 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
24 | #@date 2010/02/08 |
---|
25 | #@version 1.0.5 - Incrustar códico de antigua función ogPartcloneSyntax |
---|
26 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
27 | #@date 2012/09/14 |
---|
28 | #*/ ## |
---|
29 | function ogCreateImageSyntax() |
---|
30 | { |
---|
31 | local FS TOOL LEVEL DEV IMGFILE BUFFER PARAM1 PARAM2 PARAM3 |
---|
32 | |
---|
33 | # Si se solicita, mostrar ayuda. |
---|
34 | if [ "$*" == "help" ]; then |
---|
35 | ogHelp "$FUNCNAME" "$FUNCNAME path_device path_imagefile [str_tool] [str_compressionlevel]" \ |
---|
36 | "$FUNCNAME /dev/sda1 /opt/opengnsys/images/prueba.img partclone lzop" \ |
---|
37 | "$FUNCNAME /dev/sda1 /opt/opengnsys/images/prueba.img" |
---|
38 | return |
---|
39 | fi |
---|
40 | # Error si no se reciben entre 2 y 4 parámetros. |
---|
41 | [ $# -ge 2 -a $# -le 4 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $? |
---|
42 | |
---|
43 | # Asignación de parámetros. |
---|
44 | DEV="$1" |
---|
45 | IMGFILE="$2" |
---|
46 | case "$#" in |
---|
47 | 2) # Sintaxis por defecto OG DEV IMGFILE |
---|
48 | TOOL="partclone" |
---|
49 | LEVEL="gzip" |
---|
50 | ;; |
---|
51 | 4) # Sintaxis condicionada. |
---|
52 | TOOL="${3,,}" |
---|
53 | LEVEL="${4,,}" |
---|
54 | ;; |
---|
55 | esac |
---|
56 | |
---|
57 | case "$TOOL" in |
---|
58 | ntfsclone) |
---|
59 | PARAM1="ntfsclone --force --save-image -O - $DEV" |
---|
60 | ;; |
---|
61 | partimage|default) |
---|
62 | PARAM1="partimage -M -f3 -o -d -B gui=no -c -z0 --volume=0 save $DEV stdout" |
---|
63 | ;; |
---|
64 | partclone) |
---|
65 | FS="$(ogGetFsType $(ogDevToDisk $DEV 2>/dev/null) 2>/dev/null)" |
---|
66 | case "$FS" in |
---|
67 | EXT[234]) PARAM1="partclone.extfs" ;; |
---|
68 | BTRFS) PARAM1="partclone.btrfs" ;; |
---|
69 | REISERFS) PARAM1="partclone.reiserfs" ;; |
---|
70 | REISER4) PARAM1="partclone.reiser4" ;; |
---|
71 | JFS) PARAM1="partclone.jfs" ;; |
---|
72 | XFS) PARAM1="partclone.xfs" ;; |
---|
73 | F2FS) PARAM1="partclone.f2fs" ;; |
---|
74 | NILFS2) PARAM1="partclone.nilfs2" ;; |
---|
75 | NTFS) PARAM1="partclone.ntfs" ;; |
---|
76 | EXFAT) PARAM1="partclone.exfat" ;; |
---|
77 | FAT16|FAT32) PARAM1="partclone.fat" ;; |
---|
78 | HFS|HFSPLUS) PARAM1="partclone.hfsp" ;; |
---|
79 | UFS) PARAM1="partclone.ufs" ;; |
---|
80 | VMFS) PARAM1="partclone.vmfs" ;; |
---|
81 | *) PARAM1="partclone.imager" ;; |
---|
82 | esac |
---|
83 | # Por compatibilidad, si no existe el ejecutable usar por defecto "parclone.dd". |
---|
84 | which $PARAM1 &>/dev/null || PARAM1="partclone.dd" |
---|
85 | PARAM1="$PARAM1 -d0 -F -c -s $DEV" |
---|
86 | # Algunas versiones de partclone.dd no tienen opción "-c". |
---|
87 | [ -z "$(eval ${PARAM1%% *} --help 2>&1 | grep -- -c)" ] && PARAM1="${PARAM1/ -c / }" |
---|
88 | ;; |
---|
89 | esac |
---|
90 | # Comprobar que existe mbuffer. |
---|
91 | which mbuffer &>/dev/null && PARAM2="| mbuffer -q -m 40M " || PARAM2=" " |
---|
92 | |
---|
93 | # Nivel de compresion. |
---|
94 | case "$LEVEL" in |
---|
95 | 0|none) PARAM3=" > " ;; |
---|
96 | 1|lzop) PARAM3=" | lzop > " ;; |
---|
97 | 2|gzip) PARAM3=" | gzip -c > " ;; |
---|
98 | 3|bzip) PARAM3=" | bzip -c > " ;; |
---|
99 | esac |
---|
100 | |
---|
101 | # Sintaxis final. |
---|
102 | [ -n "$PARAM1" ] && echo "$PARAM1 $PARAM2 $PARAM3 $IMGFILE" |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | #/** |
---|
107 | # ogRestoreImageSyntax path_filename path_device [str_tools] [str_compressionlevel] |
---|
108 | #@brief Genera una cadena de texto con la instrucción para crear un fichero imagen |
---|
109 | #@param path_device dispositivo Linux del sistema de archivos |
---|
110 | #@param path_fileneme path absoluto del fichero imagen |
---|
111 | #@param [opcional] str_tools herrmaienta de clonacion [partimage, partclone, ntfsclone] |
---|
112 | #@param [opcional] str_compressionlevel nivel de compresion. [0 -none-, 1-lzop-, 2-gzip] |
---|
113 | #@return cadena con el comando que se debe ejecutar. |
---|
114 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
115 | #@warning En pruebas iniciales |
---|
116 | #@TODO introducir las herramientas fsarchiver, dd |
---|
117 | #@TODO introducir el nivel de compresion gzip |
---|
118 | #@version 1.0 - Primeras pruebas |
---|
119 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
120 | #@date 2010/02/08 |
---|
121 | #*/ ## |
---|
122 | function ogRestoreImageSyntax () |
---|
123 | { |
---|
124 | local TOOL COMPRESSOR LEVEL PART IMGFILE FILEHEAD INFOIMG |
---|
125 | |
---|
126 | |
---|
127 | # Si se solicita, mostrar ayuda. |
---|
128 | if [ "$*" == "help" ]; then |
---|
129 | ogHelp "$FUNCNAME" "$FUNCNAME filename partition [tool] [levelcompresor]" \ |
---|
130 | "$FUNCNAME /opt/opengnsys/images/prueba.img /dev/sda1 [partclone] [lzop]" |
---|
131 | return |
---|
132 | fi |
---|
133 | |
---|
134 | # Error si no se reciben entre 2 y 4 parámetros. |
---|
135 | [ $# -ge 2 -a $# -le 4 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $? |
---|
136 | |
---|
137 | # controlamos que el parametro 1 (imagen) es tipo file. |
---|
138 | [ -f $1 ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
139 | |
---|
140 | # Si 2 parametros (file-origen-, device-destino-) = ogGetImageFull($1) |
---|
141 | if [ "$#" -eq 2 ]; then |
---|
142 | IMGFILE=$1 |
---|
143 | PART=$2 |
---|
144 | INFOIMG=$(ogGetImageInfo $IMGFILE) || ogRaiseError $OG_ERR_NOTFOUND "No Image $1" || return $? |
---|
145 | TOOL=`echo $INFOIMG | cut -f1 -d:` |
---|
146 | COMPRESSOR=`echo $INFOIMG | cut -f2 -d:` |
---|
147 | ogRestoreImageSyntax $IMGFILE $PART $TOOL $COMPRESSOR |
---|
148 | fi |
---|
149 | |
---|
150 | |
---|
151 | # Si cuatro parametros genera sintaxis |
---|
152 | if [ "$#" -eq 4 ]; then |
---|
153 | IMGFILE=$1 |
---|
154 | PART=$2 |
---|
155 | # comprobamos parametro herramienta compresion. |
---|
156 | TOOL=$(echo $3 | tr [A-Z] [a-z]) |
---|
157 | #ogCheckProgram $TOOL |
---|
158 | #comprobar parámetro compresor. |
---|
159 | LEVEL=$(echo $4 | tr [A-Z] [a-z]) |
---|
160 | #ogCheckProgram $LEVEL |
---|
161 | |
---|
162 | case "$LEVEL" in |
---|
163 | "0"|"none") |
---|
164 | COMPRESSOR=" " |
---|
165 | ;; |
---|
166 | "1"|"lzop" | "LZOP") |
---|
167 | COMPRESSOR=" lzop -dc " |
---|
168 | ;; |
---|
169 | "2"|"gzip" | "GZIP") |
---|
170 | COMPRESSOR=" gzip -dc " |
---|
171 | ;; |
---|
172 | "3"|"bzip" | "BZIP" ) |
---|
173 | COMPRESSOR=" bzip -dc " |
---|
174 | ;; |
---|
175 | *) |
---|
176 | ogRaiseError $OG_ERR_NOTFOUND "Compressor no valid $TOOL" || return $? |
---|
177 | ;; |
---|
178 | esac |
---|
179 | #comprobar mbuffer |
---|
180 | which mbuffer > /dev/null && MBUFFER="| mbuffer -q -m 40M " || MBUFFER=" " |
---|
181 | |
---|
182 | case "${TOOL,,}" in |
---|
183 | ntfsclone) |
---|
184 | TOOL="| ntfsclone --restore-image --overwrite $PART -" |
---|
185 | ;; |
---|
186 | partimage) |
---|
187 | TOOL="| partimage -f3 -B gui=no restore $PART stdin" |
---|
188 | ;; |
---|
189 | partclone*) |
---|
190 | # -C para que no compruebe tamaños |
---|
191 | TOOL="| partclone.restore -d0 -C -I -o $PART" |
---|
192 | ;; |
---|
193 | dd) |
---|
194 | TOOL="| pv | dd conv=sync,noerror bs=1M of=$PART" |
---|
195 | ;; |
---|
196 | *) |
---|
197 | ogRaiseError $OG_ERR_NOTFOUND "Tools imaging no valid $TOOL" || return $? |
---|
198 | ;; |
---|
199 | esac |
---|
200 | |
---|
201 | echo "$COMPRESSOR $IMGFILE $MBUFFER $TOOL" |
---|
202 | fi |
---|
203 | |
---|
204 | } |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | #/** |
---|
210 | # ogCreateDiskImage int_ndisk str_repo path_image [str_tools] [str_compressionlevel] |
---|
211 | #@brief Crea una imagen (copia de seguridad) de un disco completo. |
---|
212 | #@param int_ndisk nº de orden del disco |
---|
213 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
214 | #@param path_image camino de la imagen (sin extensión) |
---|
215 | #@return (nada, por determinar) |
---|
216 | #@note repo = { REPO, CACHE } |
---|
217 | #@note Esta primera versión crea imágenes con dd comprimidas con gzip. |
---|
218 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
219 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
220 | #@exception OG_ERR_LOCKED particion bloqueada por otra operación. |
---|
221 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
222 | #@warning En pruebas iniciales |
---|
223 | #@todo Gestión de bloqueos de disco |
---|
224 | #@todo Comprobar si debe desmontarse la caché local |
---|
225 | #@todo Comprobar que no se crea la imagen en el propio disco |
---|
226 | #@version 1.1.0 - Primera versión para OpenGnsys con herramientas prefijadas. |
---|
227 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
228 | #@Date 2016/04/08 |
---|
229 | #*/ ## |
---|
230 | function ogCreateDiskImage () |
---|
231 | { |
---|
232 | # Variables locales |
---|
233 | local DISK PROGRAM IMGDIR IMGFILE IMGTYPE ERRCODE |
---|
234 | |
---|
235 | # Si se solicita, mostrar ayuda. |
---|
236 | if [ "$*" == "help" ]; then |
---|
237 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_repo path_image" \ |
---|
238 | "$FUNCNAME 1 REPO /disk1" |
---|
239 | return |
---|
240 | fi |
---|
241 | # Error si no se reciben entre 3 y 5 parámetros. |
---|
242 | [ $# -ge 3 -a $# -le 5 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $? |
---|
243 | |
---|
244 | # Comprobar que no está bloqueada ni la partición, ni la imagen. |
---|
245 | DISK="$(ogDiskToDev $1)" || return $? |
---|
246 | if ogIsDiskLocked $1; then |
---|
247 | ogRaiseError $OG_ERR_LOCKED "$MSG_LOCKED $1" |
---|
248 | return $? |
---|
249 | fi |
---|
250 | IMGTYPE="dsk" # Extensión genérica de imágenes de disco. |
---|
251 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
252 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
253 | IMGFILE="$IMGDIR/$(basename "$3").$IMGTYPE" |
---|
254 | if ogIsImageLocked "$IMGFILE"; then |
---|
255 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $3, $4" |
---|
256 | return $? |
---|
257 | fi |
---|
258 | |
---|
259 | # No guardar imagen en el propio disco (disco no incluido en el camino del repositorio). |
---|
260 | if [[ $(ogGetPath "$2" /) =~ ^$DISK ]]; then |
---|
261 | ogRaiseError $OG_ERR_IMAGE "$2 = $DISK" |
---|
262 | return $? |
---|
263 | fi |
---|
264 | |
---|
265 | # Generar la instruccion a ejecutar antes de aplicar los bloqueos. |
---|
266 | PROGRAM=$(ogCreateImageSyntax $DISK $IMGFILE) |
---|
267 | # Desmontar todos los sistemas de archivos del disco, bloquear disco e imagen. |
---|
268 | ogUnmountAll $1 2>/dev/null |
---|
269 | ogLockDisk $1 || return $? |
---|
270 | ogLockImage "$2" "$3.$IMGTYPE" || return $? |
---|
271 | |
---|
272 | # Crear Imagen. |
---|
273 | trap "ogUnlockDisk $1; ogUnlockImage "$3" "$4.$IMGTYPE"; rm -f $IMGFILE" 1 2 3 6 9 |
---|
274 | eval $PROGRAM |
---|
275 | |
---|
276 | # Controlar salida de error, crear fichero de información y desbloquear partición. |
---|
277 | ERRCODE=$? |
---|
278 | if [ $ERRCODE == 0 ]; then |
---|
279 | echo "$(ogGetImageInfo $IMGFILE):$(ogGetHostname)" > $IMGFILE.info |
---|
280 | else |
---|
281 | ogRaiseError $OG_ERR_IMAGE "$1 $2 $IMGFILE" |
---|
282 | rm -f "$IMGFILE" |
---|
283 | fi |
---|
284 | # Desbloquear disco e imagen. |
---|
285 | ogUnlockDisk $1 |
---|
286 | ogUnlockImage "$2" "$3.$IMGTYPE" |
---|
287 | return $ERRCODE |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | #/** |
---|
292 | # ogCreateImage int_ndisk int_npartition str_repo path_image [str_tools] [str_compressionlevel] |
---|
293 | #@brief Crea una imagen a partir de una partición. |
---|
294 | #@param int_ndisk nº de orden del disco |
---|
295 | #@param int_npartition nº de orden de la partición |
---|
296 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
297 | #@param path_image camino de la imagen (sin extensión) |
---|
298 | #@param [opcional] str_tools herrmaienta de clonacion [partimage, partclone, ntfsclone] |
---|
299 | #@param [opcional] str_compressionlevel nivel de compresion. [0 -none-, 1-lzop-, 2-gzip] |
---|
300 | #@return (nada, por determinar) |
---|
301 | #@note repo = { REPO, CACHE } |
---|
302 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
303 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
304 | #@exception OG_ERR_PARTITION partición no accesible o no soportada. |
---|
305 | #@exception OG_ERR_LOCKED particion bloqueada por otra operación. |
---|
306 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
307 | #@todo Comprobaciones, control de errores, definir parámetros, etc. |
---|
308 | #@version 0.1 - Integracion para Opengnsys - HIDRA:CrearImagen{EXT3, NTFS}.sh; EAC: CreateImageFromPartition () en Deploy.lib |
---|
309 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
310 | #@Date 2008/05/13 |
---|
311 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
312 | #@date 2008/10/27 |
---|
313 | #@version 0.9 - Versión en pruebas para OpenGnSys |
---|
314 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
315 | #@date 2009/10/07 |
---|
316 | #@version 1.0 - Llama a función ogCreateImageSyntax para generar la llamada al comando. |
---|
317 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
318 | #@date 2010/02/08 |
---|
319 | #*/ ## |
---|
320 | function ogCreateImage () |
---|
321 | { |
---|
322 | # Variables locales |
---|
323 | local PART PROGRAM IMGDIR IMGFILE IMGTYPE ERRCODE |
---|
324 | |
---|
325 | # Si se solicita, mostrar ayuda. |
---|
326 | if [ "$*" == "help" ]; then |
---|
327 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart str_repo path_image" \ |
---|
328 | "$FUNCNAME 1 1 REPO /aula1/win7" |
---|
329 | return |
---|
330 | fi |
---|
331 | # Error si no se reciben entre 4 y 6 parámetros. |
---|
332 | [ $# -ge 4 -a $# -le 6 ] || ogRaiseError $OG_ERR_FORMAT "$*" || return $? |
---|
333 | |
---|
334 | # Comprobar que no está bloqueada ni la partición, ni la imagen. |
---|
335 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
336 | if ogIsLocked $1 $2; then |
---|
337 | ogRaiseError $OG_ERR_LOCKED "$MSG_LOCKED $1, $2" |
---|
338 | return $? |
---|
339 | fi |
---|
340 | |
---|
341 | IMGTYPE="img" # Extensión genérica de imágenes. |
---|
342 | IMGDIR=$(ogGetParentPath "$3" "$4") |
---|
343 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$3 $(dirname $4)" || return $? |
---|
344 | |
---|
345 | IMGFILE="$IMGDIR/$(basename "$4").$IMGTYPE" |
---|
346 | if ogIsImageLocked "$IMGFILE"; then |
---|
347 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $3, $4" |
---|
348 | return $? |
---|
349 | fi |
---|
350 | # Generar la instruccion a ejecutar antes de aplicar los bloqueos. |
---|
351 | PROGRAM=$(ogCreateImageSyntax $PART $IMGFILE $5 $6) |
---|
352 | # Desmontar partición, bloquear partición e imagen. |
---|
353 | ogUnmount $1 $2 2>/dev/null |
---|
354 | ogLock $1 $2 || return $? |
---|
355 | ogLockImage "$3" "$4.$IMGTYPE" || return $? |
---|
356 | |
---|
357 | # Crear Imagen. |
---|
358 | trap "ogUnlock $1 $2; ogUnlockImage "$3" "$4.$IMGTYPE"; rm -f $IMGFILE" 1 2 3 6 9 |
---|
359 | eval $PROGRAM |
---|
360 | |
---|
361 | # Controlar salida de error, crear fichero de información y desbloquear partición. |
---|
362 | ERRCODE=$? |
---|
363 | if [ $ERRCODE == 0 ]; then |
---|
364 | echo "$(ogGetImageInfo $IMGFILE):$(ogGetHostname)" > $IMGFILE.info |
---|
365 | else |
---|
366 | ogRaiseError $OG_ERR_IMAGE "$1 $2 $IMGFILE" |
---|
367 | rm -f "$IMGFILE" |
---|
368 | fi |
---|
369 | # Desbloquear partición e imagen. |
---|
370 | ogUnlock $1 $2 |
---|
371 | ogUnlockImage "$3" "$4.$IMGTYPE" |
---|
372 | return $ERRCODE |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | #/** |
---|
377 | # ogCreateMbrImage int_ndisk str_repo path_image |
---|
378 | #@brief Crea una imagen a partir del sector de arranque de un disco. |
---|
379 | #@param int_ndisk nº de orden del disco |
---|
380 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
381 | #@param path_image camino de la imagen (sin extensión) |
---|
382 | #@return (nada, por determinar) |
---|
383 | #@note repo = { REPO, CACHE } |
---|
384 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
385 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
386 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
387 | #@version 0.9 - Versión en pruebas para OpenGNSys |
---|
388 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
389 | #@date 2010/01/12 |
---|
390 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
391 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
392 | #@date 2011/03/10 |
---|
393 | #*/ ## |
---|
394 | function ogCreateMbrImage () |
---|
395 | { |
---|
396 | # Variables locales |
---|
397 | local DISK IMGDIR IMGFILE |
---|
398 | # Si se solicita, mostrar ayuda. |
---|
399 | if [ "$*" == "help" ]; then |
---|
400 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_repo path_image" \ |
---|
401 | "$FUNCNAME 1 REPO /aula1/mbr" |
---|
402 | return |
---|
403 | fi |
---|
404 | # Error si no se reciben 3 parámetros. |
---|
405 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
406 | |
---|
407 | DISK=$(ogDiskToDev "$1") || return $? |
---|
408 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
409 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
410 | IMGFILE="$IMGDIR/$(basename "$3").mbr" |
---|
411 | |
---|
412 | # Crear imagen del MBR. |
---|
413 | dd if="$DISK" of="$IMGFILE" bs=512 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
414 | } |
---|
415 | |
---|
416 | |
---|
417 | #/** |
---|
418 | # ogCreateBootLoaderImage int_ndisk str_repo path_image |
---|
419 | #@brief Crea una imagen del boot loader a partir del sector de arranque de un disco. |
---|
420 | #@param int_ndisk nº de orden del disco |
---|
421 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
422 | #@param path_image camino de la imagen (sin extensión) |
---|
423 | #@return (nada, por determinar) |
---|
424 | #@note repo = { REPO, CACHE } |
---|
425 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
426 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
427 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
428 | #@version 1.0 - Adaptacion de ogCreateMbrImage para guardar solo el Boot Loader |
---|
429 | #@author Juan Carlos Xifre, SICUZ Universidad de Zaragoza |
---|
430 | #@date 2011/03/21 |
---|
431 | #*/ ## |
---|
432 | function ogCreateBootLoaderImage () |
---|
433 | { |
---|
434 | # Variables locales |
---|
435 | local DISK IMGDIR IMGFILE |
---|
436 | # Si se solicita, mostrar ayuda. |
---|
437 | if [ "$*" == "help" ]; then |
---|
438 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_repo path_image" \ |
---|
439 | "$FUNCNAME 1 REPO /aula1/mbr" |
---|
440 | return |
---|
441 | fi |
---|
442 | # Error si no se reciben 3 parámetros. |
---|
443 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
444 | |
---|
445 | DISK=$(ogDiskToDev "$1") || return $? |
---|
446 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
447 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
448 | IMGFILE="$IMGDIR/$(basename "$3").mbr" |
---|
449 | |
---|
450 | # Crear imagen del Boot Loader dentro del MBR. |
---|
451 | dd if="$DISK" of="$IMGFILE" bs=446 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
452 | } |
---|
453 | |
---|
454 | #/** |
---|
455 | # ogGetSizeParameters int_num_disk int_num_part str_repo [monolit|sync|diff] |
---|
456 | #@brief Devuelve el tamaño de los datos de un sistema de ficheros, el espacio necesario para la imagen y si cabe en el repositorio elegido. |
---|
457 | #@param int_disk numero de disco |
---|
458 | #@param int_part numero de particion |
---|
459 | #@param str_repo repositorio de imágenes { REPO, CACHE } |
---|
460 | #@param str_imageName Nombre de la imagen |
---|
461 | #@param str_imageType Tipo de imagen: monolit (por defecto), sync o diff. (parametro opcional) |
---|
462 | #@return SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE |
---|
463 | #@note si str_imageType= diff necesario /tmp/ogimg.info, que es creado por ogCreateInfoImage. |
---|
464 | #@note para el tamaño de la imagen no sigue enlaces simbólicos. |
---|
465 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
466 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
467 | #@date 2014/10/24 |
---|
468 | #@version 1.1.0 - En la salida se incluye el espacio disponible en el repositorio (ticket #771) |
---|
469 | #@author Irina Gomez - ETSII Universidad de Sevilla |
---|
470 | #@date 2017-03-28 |
---|
471 | #@version 1.1.0 - Si la imagen ya existe en el REPO se suma su tamaño al espacio libre |
---|
472 | #@author Irina Gomez - ETSII Universidad de Sevilla |
---|
473 | #@date 2017-11-08 |
---|
474 | #*/ ## |
---|
475 | function ogGetSizeParameters () |
---|
476 | { |
---|
477 | local REPO MNTDIR SIZEDATA KERNELVERSION SIZEREQUIRED FACTORGZIP FACTORLZOP FACTORSYNC SIZEFREE |
---|
478 | local IMGTYPE IMGDIR IMGFILE IMGEXT IMGSIZE |
---|
479 | |
---|
480 | # Si se solicita, mostrar ayuda. |
---|
481 | if [ "$*" == "help" ]; then |
---|
482 | ogHelp "$FUNCNAME" "$FUNCNAME num_disk num_part str_repo path_imgname [monolit|sync|diff]" \ |
---|
483 | "if $FUNCNAME 1 2 REPO Windows10 sync ; then ...; fi" \ |
---|
484 | "if $FUNCNAME 1 6 Ubuntu16 CACHE ; then ...; fi" |
---|
485 | return |
---|
486 | fi |
---|
487 | # Error si no se reciben 1 o 2 parámetros. |
---|
488 | [ $# -lt 4 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imgname [monolit|sync|diff]" ; echo $?) |
---|
489 | |
---|
490 | # Recogemos parametros |
---|
491 | REPO=${3^^} |
---|
492 | IMGTYPE="_${5^^}_" |
---|
493 | |
---|
494 | MNTDIR=$(ogMount $1 $2) |
---|
495 | if [ "$MNTDIR" == "" ]; then |
---|
496 | ogRaiseError $OG_ERR_PARTITION "$1 $2" |
---|
497 | return $? |
---|
498 | fi |
---|
499 | |
---|
500 | # Datos contenidos en la particion o en la lista de archivos de contiene la diferencial. |
---|
501 | if [ "$IMGTYPE" == "_DIFF_" ]; then |
---|
502 | [ -r /tmp/ogimg.info ] || return $(ogRaiseError session $OG_ERR_NOTFOUND "/tmp/ogimg.info"; echo $?) |
---|
503 | cd $MNTDIR |
---|
504 | SIZEDATA=$(grep -v "\/$" /tmp/ogimg.info | tr '\n' '\0'| du -x -c --files0-from=- 2>/dev/null|tail -n1 |cut -f1) |
---|
505 | cd / |
---|
506 | else |
---|
507 | SIZEDATA=$(df -k | grep $MNTDIR\$ | awk '{print $3}') |
---|
508 | fi |
---|
509 | |
---|
510 | #Aplicar factor de compresion |
---|
511 | if [ "$IMGTYPE" == "_SYNC_" -o "$IMGTYPE" == "_DIFF_" ]; then |
---|
512 | |
---|
513 | # Sistema de fichero de la imagen según kernel, menor que 3.7 EXT4. comparamos revision |
---|
514 | KERNELVERSION=$(uname -r| awk '{printf("%d",$1);sub(/[0-9]*\./,"",$1);printf(".%02d",$1)}') |
---|
515 | [ $KERNELVERSION \< 3.07 ] && IMGFS="EXT4" || IMGFS=${IMGFS:-"BTRFS"} |
---|
516 | FACTORSYNC=${FACTORSYNC:-"130"} |
---|
517 | # Si IMGFS="BTRFS" la compresion es mayor. |
---|
518 | [ $IMGFS == "BTRFS" ] && let FACTORSYNC=$FACTORSYNC-20 |
---|
519 | |
---|
520 | let SIZEREQUIRED=$SIZEDATA*$FACTORSYNC/100 |
---|
521 | # El tamaño mínimo del sistema de ficheros btrfs es 250M, ponemos 300 |
---|
522 | [ $SIZEREQUIRED -lt 300000 ] && SIZEREQUIRED=300000 |
---|
523 | |
---|
524 | else |
---|
525 | FACTORGZIP=55/100 |
---|
526 | FACTORLZOP=65/100 |
---|
527 | let SIZEREQUIRED=$SIZEDATA*$FACTORLZOP |
---|
528 | fi |
---|
529 | |
---|
530 | #Comprobar espacio libre en el contenedor. |
---|
531 | [ "$REPO" == "CACHE" ] && SIZEFREE=$(ogGetFreeSize `ogFindCache`) |
---|
532 | [ "$REPO" == "REPO" ] && SIZEFREE=$(df -k | grep $OGIMG | awk '{print $4}') |
---|
533 | |
---|
534 | # Comprobamos si existe una imagen con el mismo nombre en $REPO |
---|
535 | # En sincronizadas restamos tamaño de la imagen y en monoloticas de la .ant |
---|
536 | case "${IMGTYPE}" in |
---|
537 | _DIFF_) IMGEXT="img.diff" |
---|
538 | ;; |
---|
539 | _SYNC_) IMGEXT="img" |
---|
540 | ;; |
---|
541 | *) IMGEXT="img.ant" |
---|
542 | ;; |
---|
543 | esac |
---|
544 | |
---|
545 | IMGDIR=$(ogGetParentPath "$REPO" "/$4") |
---|
546 | IMGFILE=$(ogGetPath "$IMGDIR/$(basename "/$4").$IMGEXT") |
---|
547 | if [ -z "$IMGFILE" ]; then |
---|
548 | IMGSIZE=0 |
---|
549 | else |
---|
550 | IMGSIZE=$(ls -s "$IMGFILE" | cut -f1 -d" ") |
---|
551 | fi |
---|
552 | |
---|
553 | let SIZEFREE=$SIZEFREE+$IMGSIZE |
---|
554 | |
---|
555 | [ "$SIZEREQUIRED" -lt "$SIZEFREE" ] && ISENOUGHSPACE=TRUE || ISENOUGHSPACE=FALSE |
---|
556 | |
---|
557 | echo $SIZEDATA $SIZEREQUIRED $SIZEFREE $ISENOUGHSPACE |
---|
558 | |
---|
559 | } |
---|
560 | |
---|
561 | #/** |
---|
562 | # ogIsImageLocked [str_repo] path_image |
---|
563 | #@brief Comprueba si una imagen está bloqueada para uso exclusivo. |
---|
564 | #@param str_repo repositorio de imágenes (opcional) |
---|
565 | #@param path_image camino de la imagen (sin extensión) |
---|
566 | #@return Código de salida: 0 - bloqueado, 1 - sin bloquear o error. |
---|
567 | #@note repo = { REPO, CACHE } |
---|
568 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
569 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
570 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
571 | #@date 2011/03/10 |
---|
572 | #@version 1.0.1 - Devolver falso en caso de error. |
---|
573 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
574 | #@date 2011-05-18 |
---|
575 | #*/ ## |
---|
576 | function ogIsImageLocked () |
---|
577 | { |
---|
578 | # Si se solicita, mostrar ayuda. |
---|
579 | if [ "$*" == "help" ]; then |
---|
580 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
581 | "if $FUNCNAME /opt/opengnsys/images/aula1/win7.img; then ...; fi" \ |
---|
582 | "if $FUNCNAME REPO /aula1/win7.img; then ...; fi" |
---|
583 | return |
---|
584 | fi |
---|
585 | # Error si no se reciben 1 o 2 parámetros. |
---|
586 | [ $# -lt 1 -o $# -gt 2 ] && return 1 |
---|
587 | |
---|
588 | # Comprobar si existe el fichero de bloqueo. |
---|
589 | test -n "$(ogGetPath $@.lock)" |
---|
590 | } |
---|
591 | |
---|
592 | |
---|
593 | #/** |
---|
594 | # ogLockImage [str_repo] path_image |
---|
595 | #@brief Bloquea una imagen para uso exclusivo. |
---|
596 | #@param str_repo repositorio de imágenes (opcional) |
---|
597 | #@param path_image camino de la imagen (sin extensión) |
---|
598 | #@return Nada. |
---|
599 | #@note Se genera un fichero con extensión .lock |
---|
600 | #@note repo = { REPO, CACHE } |
---|
601 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
602 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
603 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
604 | #@date 2011/03/10 |
---|
605 | #*/ ## |
---|
606 | function ogLockImage () |
---|
607 | { |
---|
608 | # Variables locales |
---|
609 | local IMGDIR |
---|
610 | |
---|
611 | # Si se solicita, mostrar ayuda. |
---|
612 | if [ "$*" == "help" ]; then |
---|
613 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
614 | "$FUNCNAME /opt/opengnsys/images/aula1/win7.img" \ |
---|
615 | "$FUNCNAME REPO /aula1/win7.img" |
---|
616 | return |
---|
617 | fi |
---|
618 | # Error si no se reciben 1 o 2 parámetros. |
---|
619 | [ $# == 1 -o $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
620 | # Comprobar que existe directorio de imagen |
---|
621 | IMGDIR=$(ogGetParentPath $@) || return $? |
---|
622 | # Crear fichero de bloqueo. |
---|
623 | touch $IMGDIR/$(basename "${!#}").lock 2>/dev/null || ogRaiseError $OG_ERR_NOTWRITE "$*" || return $? |
---|
624 | } |
---|
625 | |
---|
626 | |
---|
627 | #/** |
---|
628 | # ogRestoreDiskImage str_repo path_image int_npartition |
---|
629 | #@brief Restaura (recupera) una imagen de un disco completo. |
---|
630 | #@param str_repo repositorio de imágenes o caché local |
---|
631 | #@param path_image camino de la imagen |
---|
632 | #@param int_ndisk nº de orden del disco |
---|
633 | #@return (por determinar) |
---|
634 | #@warning Primera versión en pruebas |
---|
635 | #@todo Gestionar bloqueos de disco |
---|
636 | #@todo Comprobar que no se intenta restaurar de la caché sobre el mismo disco |
---|
637 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
638 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
639 | #@exception OG_ERR_LOCKED partición bloqueada por otra operación. |
---|
640 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
641 | #@exception OG_ERR_IMGSIZEPARTITION Tamaño de la particion es menor al tamaño de la imagen. |
---|
642 | #@version 1.1.0 - Primera versión para OpenGnsys. |
---|
643 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
644 | #@Date 2016/04/08 |
---|
645 | #*/ ## |
---|
646 | function ogRestoreDiskImage () |
---|
647 | { |
---|
648 | # Variables locales |
---|
649 | local DISK DISKSIZE IMGFILE IMGTYPE IMGSIZE PROGRAM ERRCODE |
---|
650 | |
---|
651 | # Si se solicita, mostrar ayuda. |
---|
652 | if [ "$*" == "help" ]; then |
---|
653 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image int_ndisk" \ |
---|
654 | "$FUNCNAME REPO /aula1/win7 1" |
---|
655 | return |
---|
656 | fi |
---|
657 | # Error si no se reciben 4 parámetros. |
---|
658 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
659 | # Procesar parámetros. |
---|
660 | DISK="$(ogDiskToDev $3)" || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
661 | IMGTYPE="dsk" |
---|
662 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
663 | [ -r "$IMGFILE" ] || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
664 | |
---|
665 | # comprobamos consistencia de la imagen |
---|
666 | ogGetImageInfo $IMGFILE >/dev/null || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
667 | |
---|
668 | #/* (Comienzo comentario Doxygen) |
---|
669 | # Error si la imagen no cabe en la particion. |
---|
670 | #IMGSIZE=$(ogGetImageSize "$1" "$2") || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
671 | #DISKSIZE=$(ogGetDiskSize $3) |
---|
672 | #if [ $IMGSIZE -gt $DISKSIZE ]; then |
---|
673 | # ogRaiseError $OG_ERR_IMGSIZEPARTITION "$DISKSIZE < $IMGSIZE" |
---|
674 | # return $? |
---|
675 | #fi |
---|
676 | #*/ (Fin comentario Doxygen) |
---|
677 | |
---|
678 | # Comprobar el bloqueo de la imagen y de la partición. |
---|
679 | if ogIsImageLocked "$IMGFILE"; then |
---|
680 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $1, $2.$IMGTYPE" |
---|
681 | return $? |
---|
682 | fi |
---|
683 | if ogIsDiskLocked $3; then |
---|
684 | ogRaiseError $OG_ERR_LOCKED "$MSG_DISK $3" |
---|
685 | return $? |
---|
686 | fi |
---|
687 | # Solicitamos la generación de la instruccion a ejecutar |
---|
688 | PROGRAM=$(ogRestoreImageSyntax $IMGFILE $DISK) |
---|
689 | |
---|
690 | # Bloquear el disco |
---|
691 | ogLockDisk $3 || return $? |
---|
692 | trap "ogUnlockDisk $3" 1 2 3 6 9 |
---|
693 | |
---|
694 | # Ejecutar restauración según el tipo de imagen. |
---|
695 | eval $PROGRAM |
---|
696 | |
---|
697 | ERRCODE=$? |
---|
698 | if [ $ERRCODE != 0 ]; then |
---|
699 | ogRaiseError $OG_ERR_IMAGE "$IMGFILE, $3, $4" |
---|
700 | fi |
---|
701 | ogUnlockDisk $3 $4 |
---|
702 | return $ERRCODE |
---|
703 | } |
---|
704 | |
---|
705 | |
---|
706 | #/** |
---|
707 | # ogRestoreImage str_repo path_image int_ndisk int_npartition |
---|
708 | #@brief Restaura una imagen de sistema de archivos en una partición. |
---|
709 | #@param str_repo repositorio de imágenes o caché local |
---|
710 | #@param path_image camino de la imagen |
---|
711 | #@param int_ndisk nº de orden del disco |
---|
712 | #@param int_npartition nº de orden de la partición |
---|
713 | #@return (por determinar) |
---|
714 | #@exception OG_ERR_FORMAT 1 formato incorrecto. |
---|
715 | #@exception OG_ERR_NOTFOUND 2 fichero de imagen o partición no detectados. |
---|
716 | #@exception OG_ERR_PARTITION 3 # Error en partición de disco. |
---|
717 | #@exception OG_ERR_LOCKED 4 partición bloqueada por otra operación. |
---|
718 | #@exception OG_ERR_IMAGE 5 error al restaurar la imagen del sistema. |
---|
719 | #@exception OG_ERR_IMGSIZEPARTITION 30 Tamaño de la particion es menor al tamaño de la imagen. |
---|
720 | #@todo Comprobar incongruencias partición-imagen, control de errores, definir parámetros, caché/repositorio, etc. |
---|
721 | #@version 0.1 - Integracion para Opengnsys - HIDRA:RestaurarImagen{EXT3, NTFS}.sh; EAC: RestorePartitionFromImage() en Deploy.lib |
---|
722 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
723 | #@Date 2008/05/13 |
---|
724 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
725 | #@date 2008/10/27 |
---|
726 | #@version 0.9 - Primera version muy en pruebas para OpenGnSys |
---|
727 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
728 | #@date 2009/09/10 |
---|
729 | #@version 1.0 - generacion sintaxis de restauracion |
---|
730 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
731 | #@date 2011/02/01 |
---|
732 | #@version 1.0.1 - Control errores, tamaño particion, fichero-imagen |
---|
733 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
734 | #@date 2011/05/11 |
---|
735 | #*/ ## |
---|
736 | function ogRestoreImage () |
---|
737 | { |
---|
738 | # Variables locales |
---|
739 | local PART PARTSIZE IMGFILE IMGTYPE IMGSIZE FSTYPE PROGRAM ERRCODE |
---|
740 | |
---|
741 | # Si se solicita, mostrar ayuda. |
---|
742 | if [ "$*" == "help" ]; then |
---|
743 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image int_ndisk int_npart" \ |
---|
744 | "$FUNCNAME REPO /aula1/win7 1 1" |
---|
745 | return |
---|
746 | fi |
---|
747 | # Error si no se reciben 4 parámetros. |
---|
748 | [ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
749 | # Procesar parámetros. |
---|
750 | PART="$(ogDiskToDev $3 $4)" || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
751 | #IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
752 | IMGTYPE=img |
---|
753 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
754 | [ -r "$IMGFILE" ] || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
755 | # comprobamos consistencia de la imagen |
---|
756 | ogGetImageInfo $IMGFILE >/dev/null || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
757 | |
---|
758 | # Error si la imagen no cabe en la particion. |
---|
759 | IMGSIZE=$(ogGetImageSize "$1" "$2") || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
760 | #TODO: |
---|
761 | #Si la particion no esta formateado o tiene problemas formateamos |
---|
762 | ogMount $3 $4 || ogFormat $3 $4 |
---|
763 | PARTSIZE=$(ogGetPartitionSize $3 $4) |
---|
764 | if [ $IMGSIZE -gt $PARTSIZE ]; then |
---|
765 | ogRaiseError $OG_ERR_IMGSIZEPARTITION " $PARTSIZE < $IMGSIZE" |
---|
766 | return $? |
---|
767 | fi |
---|
768 | # Comprobar el bloqueo de la imagen y de la partición. |
---|
769 | if ogIsImageLocked "$IMGFILE"; then |
---|
770 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $1, $2.$IMGTYPE" |
---|
771 | return $? |
---|
772 | fi |
---|
773 | if ogIsLocked $3 $4; then |
---|
774 | ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $3, $4" |
---|
775 | return $? |
---|
776 | fi |
---|
777 | |
---|
778 | # Solicitamos la generación de la instruccion a ejecutar |
---|
779 | # Atención: no se comprueba el tipo de sistema de archivos. |
---|
780 | # Atención: no se comprueba incongruencia entre partición e imagen. |
---|
781 | PROGRAM=`ogRestoreImageSyntax $IMGFILE $PART` |
---|
782 | |
---|
783 | # Desmontar y bloquear partición. |
---|
784 | ogUnmount $3 $4 2>/dev/null || return $(ogRaiseError $OG_ERR_PARTITION " $3 $4"; echo $?) |
---|
785 | ogLock $3 $4 || return $? |
---|
786 | trap "ogUnlock $3 $4" 1 2 3 6 9 |
---|
787 | |
---|
788 | # Ejecutar restauración según el tipo de imagen. |
---|
789 | eval $PROGRAM |
---|
790 | |
---|
791 | ERRCODE=$? |
---|
792 | if [ $ERRCODE != 0 ]; then |
---|
793 | ogRaiseError $OG_ERR_IMAGE "$IMGFILE, $3, $4" |
---|
794 | fi |
---|
795 | ogUnlock $3 $4 |
---|
796 | return $ERRCODE |
---|
797 | } |
---|
798 | |
---|
799 | |
---|
800 | #/** |
---|
801 | # ogRestoreMbrImage str_repo path_image int_ndisk |
---|
802 | #@brief Restaura la imagen del sector de arranque de un disco. |
---|
803 | #@param str_repo repositorio de imágenes o caché local |
---|
804 | #@param path_image camino de la imagen |
---|
805 | #@param int_ndisk nº de orden del disco |
---|
806 | #@return (por determinar) |
---|
807 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
808 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
809 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
810 | #@version 0.9 - Primera versión en pruebas. |
---|
811 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
812 | #@date 2010/01/12 |
---|
813 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
814 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
815 | #@date 2011/03/10 |
---|
816 | #*/ ## |
---|
817 | function ogRestoreMbrImage () |
---|
818 | { |
---|
819 | # Variables locales |
---|
820 | local DISK IMGFILE |
---|
821 | # Si se solicita, mostrar ayuda. |
---|
822 | if [ "$*" == "help" ]; then |
---|
823 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image int_ndisk" \ |
---|
824 | "$FUNCNAME REPO /aula1/mbr 1" |
---|
825 | return |
---|
826 | fi |
---|
827 | # Error si no se reciben 3 parámetros. |
---|
828 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
829 | # Procesar parámetros. |
---|
830 | DISK=$(ogDiskToDev "$3") || return $? |
---|
831 | IMGFILE=$(ogGetPath "$1" "$2.mbr") |
---|
832 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
833 | |
---|
834 | # Restaurar imagen del MBR. |
---|
835 | dd if="$IMGFILE" of="$DISK" bs=512 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
836 | } |
---|
837 | |
---|
838 | |
---|
839 | #/** |
---|
840 | # ogRestoreBootLoaderImage str_repo path_image int_ndisk |
---|
841 | #@brief Restaura la imagen del boot loader del sector de arranque de un disco. |
---|
842 | #@param str_repo repositorio de imágenes o caché local |
---|
843 | #@param path_image camino de la imagen |
---|
844 | #@param int_ndisk nº de orden del disco |
---|
845 | #@return (por determinar) |
---|
846 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
847 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
848 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
849 | #@version 1.0 - Adaptacion de ogRestoreMbrImage para restaurar solo el Boot Loader |
---|
850 | #@author Juan Carlos Xifre, SICUZ Universidad de Zaragoza |
---|
851 | #@date 2011/03/21 |
---|
852 | #*/ ## |
---|
853 | function ogRestoreBootLoaderImage () |
---|
854 | { |
---|
855 | # Variables locales |
---|
856 | local DISK IMGFILE |
---|
857 | # Si se solicita, mostrar ayuda. |
---|
858 | if [ "$*" == "help" ]; then |
---|
859 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image int_ndisk" \ |
---|
860 | "$FUNCNAME REPO /aula1/mbr 1" |
---|
861 | return |
---|
862 | fi |
---|
863 | # Error si no se reciben 3 parámetros. |
---|
864 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
865 | # Procesar parámetros. |
---|
866 | DISK=$(ogDiskToDev "$3") || return $? |
---|
867 | IMGFILE=$(ogGetPath "$1" "$2.mbr") |
---|
868 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
869 | |
---|
870 | # Restaurar imagen del MBR. |
---|
871 | dd if="$IMGFILE" of="$DISK" bs=446 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
872 | } |
---|
873 | |
---|
874 | #/** |
---|
875 | # ogUnlockImage [str_repo] path_image |
---|
876 | #@brief Desbloquea una imagen con uso exclusivo. |
---|
877 | #@param str_repo repositorio de imágenes (opcional) |
---|
878 | #@param path_image camino de la imagen (sin extensión) |
---|
879 | #@return Nada. |
---|
880 | #@note repo = { REPO, CACHE } |
---|
881 | #@note Se elimina el fichero de bloqueo con extensión .lock |
---|
882 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
883 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
884 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
885 | #@date 2011/03/10 |
---|
886 | #*/ ## |
---|
887 | function ogUnlockImage () |
---|
888 | { |
---|
889 | # Si se solicita, mostrar ayuda. |
---|
890 | if [ "$*" == "help" ]; then |
---|
891 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
892 | "$FUNCNAME /opt/opengnsys/images/aula1/win7.img" \ |
---|
893 | "$FUNCNAME REPO /aula1/win7.img" |
---|
894 | return |
---|
895 | fi |
---|
896 | # Error si no se reciben 1 o 2 parámetros. |
---|
897 | [ $# == 1 -o $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
898 | |
---|
899 | # Borrar fichero de bloqueo para la imagen. |
---|
900 | rm -f $(ogGetPath $@.lock) |
---|
901 | } |
---|
902 | |
---|
903 | |
---|
904 | #/** |
---|
905 | # ogGetImageInfo filename |
---|
906 | #@brief muestra información sobre la imagen monolitica. |
---|
907 | #@param 1 filename path absoluto del fichero imagen |
---|
908 | #@return cadena compuesta por clonacion:compresor:sistemaarchivos:tamañoKB |
---|
909 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
910 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
911 | #@exception OG_ERR_IMAGE "Image format is not valid $IMGFILE" |
---|
912 | #@warning En pruebas iniciales |
---|
913 | #@TODO Definir sintaxis de salida (herramienta y compresor en minuscula) |
---|
914 | #@TODO Arreglar loop para ntfsclone |
---|
915 | #@TODO insertar parametros entrada tipo OG |
---|
916 | #@version 1.0 - Primeras pruebas |
---|
917 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
918 | #@date 2010/02/08 |
---|
919 | #*/ ## |
---|
920 | |
---|
921 | function ogGetImageInfo () |
---|
922 | { |
---|
923 | # Si se solicita, mostrar ayuda. |
---|
924 | if [ "$*" == "help" ]; then |
---|
925 | ogHelp "$FUNCNAME" "$FUNCNAME path_filename" \ |
---|
926 | "$FUNCNAME /opt/opengnsys/images/prueba.img ==> PARTCLONE:LZOP:NTFS:5642158" |
---|
927 | return |
---|
928 | fi |
---|
929 | |
---|
930 | # Error si no se recibe 1 parámetro. |
---|
931 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
932 | |
---|
933 | #comprobando que el parametro uno es un file. |
---|
934 | [ -f $1 ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
935 | |
---|
936 | local TOOLS COMPRESSOR IMGFILE FILEHEAD FS FSPLUS SIZE SIZEFACTOR PARTIMAGEINFO PARTCLONEINFO NTFSCLONEINFO IMGDETECT |
---|
937 | IMGDETECT="FALSE" |
---|
938 | |
---|
939 | IMGFILE=$1 |
---|
940 | FILEHEAD=/tmp/`basename $IMGFILE`.infohead |
---|
941 | COMPRESSOR=`file $IMGFILE | awk '{print $2}'` |
---|
942 | ogCheckStringInGroup "$COMPRESSOR" "gzip lzop" || ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
943 | $($COMPRESSOR -dc $IMGFILE 2>/dev/null | head > $FILEHEAD) || ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
944 | |
---|
945 | ## buscando Primera opción. |
---|
946 | if [ "$IMGDETECT" == "FALSE" ] |
---|
947 | then |
---|
948 | PARTCLONEINFO=$(LC_ALL=C partclone.info $FILEHEAD 2>&1) |
---|
949 | if `echo $PARTCLONEINFO | grep size > /dev/null` |
---|
950 | then |
---|
951 | TOOLS=PARTCLONE |
---|
952 | FS=$(echo $PARTCLONEINFO | awk '{gsub(/\: /,"\n"); print toupper($8);}') |
---|
953 | if [[ "$FS" == "HFS" || "$FS" == "HFSPLUS" || "$FS" == "FAT32" ]]; then |
---|
954 | FSPLUS=$(echo $PARTCLONEINFO | awk '{gsub(/\: /,"\n"); print toupper($9);}') |
---|
955 | echo $PARTCLONEINFO | grep GB > /dev/null && SIZEFACTOR=1000000 || SIZEFACTOR=1024 |
---|
956 | if [ "$FSPLUS" == "PLUS" ]; then |
---|
957 | FS=$FS$FSPLUS |
---|
958 | SIZE=$(echo $PARTCLONEINFO | awk -v FACTOR=$SIZEFACTOR '{printf "%d\n", $17*FACTOR;}') |
---|
959 | else |
---|
960 | SIZE=$(echo $PARTCLONEINFO | awk -v FACTOR=$SIZEFACTOR '{printf "%d\n", $16*FACTOR;}') |
---|
961 | fi |
---|
962 | else |
---|
963 | echo $PARTCLONEINFO | grep GB > /dev/null && SIZEFACTOR=1000000 || SIZEFACTOR=1024 |
---|
964 | SIZE=$(echo $PARTCLONEINFO | awk -v FACTOR=$SIZEFACTOR '{gsub(/\: /,"\n"); printf "%d\n", $11*FACTOR;}') |
---|
965 | fi |
---|
966 | IMGDETECT="TRUE" |
---|
967 | fi |
---|
968 | fi |
---|
969 | #buscando segunda opcion. |
---|
970 | if [ "$IMGDETECT" == "FALSE" -a ! -f /dev/loop2 ] |
---|
971 | then |
---|
972 | cat $FILEHEAD | grep -w ntfsclone-image > /dev/null && NTFSCLONEINFO=$(cat $FILEHEAD | ntfsclone --restore --overwrite /dev/loop2 - 2>&1) |
---|
973 | if `echo $NTFSCLONEINFO | grep ntfsclone > /dev/null` |
---|
974 | then |
---|
975 | TOOLS=NTFSCLONE |
---|
976 | SIZE=$(echo $NTFSCLONEINFO | awk '{gsub(/\(|\)|\./,""); printf "%d\n",$17/1000;}') |
---|
977 | FS=NTFS |
---|
978 | IMGDETECT="TRUE" |
---|
979 | fi |
---|
980 | fi |
---|
981 | ## buscando Tercer opción. |
---|
982 | if [ "$IMGDETECT" == "FALSE" ] |
---|
983 | then |
---|
984 | PARTIMAGEINFO=$(partimage -B gui=no imginfo "$FILEHEAD" 2>&1) |
---|
985 | if `echo $PARTIMAGEINFO | grep Partition > /dev/null` |
---|
986 | then |
---|
987 | TOOLS=PARTIMAGE |
---|
988 | FS=$(echo $PARTIMAGEINFO | awk '{gsub(/ /,"\n"); print $17;}' | awk '{sub(/\.\.+/," "); print toupper($2)}') |
---|
989 | SIZE=$( echo $PARTIMAGEINFO | awk '{gsub(/ /,"\n"); print $36;}' | awk '{sub(/\.\.+/," "); printf "%d\n",$2*1024*1024;}') |
---|
990 | IMGDETECT="TRUE" |
---|
991 | fi |
---|
992 | if file $FILEHEAD 2> /dev/null | grep -q "boot sector"; then |
---|
993 | TOOLS="partclone.dd" |
---|
994 | FS= |
---|
995 | SIZE= |
---|
996 | IMGDETECT="TRUE" |
---|
997 | fi |
---|
998 | fi |
---|
999 | #comprobamos valores #Chequeamos los valores devueltos. |
---|
1000 | if [ -z "$TOOLS" -o -z "$COMPRESSOR" -o "$IMGDETECT" == "FALSE" ] |
---|
1001 | then |
---|
1002 | ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
1003 | else |
---|
1004 | COMPRESSOR=$(echo $COMPRESSOR | tr [a-z] [A-Z]) |
---|
1005 | echo $TOOLS:$COMPRESSOR:$FS:$SIZE |
---|
1006 | fi |
---|
1007 | } |
---|
1008 | |
---|
1009 | #/** |
---|
1010 | # ogGetImageProgram str_REPO str_imagen |
---|
1011 | #@brief muestra información sobre la imagen monolitica. |
---|
1012 | #@see ogGetImageInfo |
---|
1013 | #@param 1 REPO o CACHE contenedor de la imagen |
---|
1014 | #@param 2 filename nombre de la imagen sin extension |
---|
1015 | #@return nombre del programa usado para generar la imagen |
---|
1016 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1017 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
1018 | #@note ogGetImageProgram REPO imagenA -> partclone |
---|
1019 | #@version 1.0 - Primeras pruebas |
---|
1020 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
1021 | #@date 2010/02/08 |
---|
1022 | #*/ ## |
---|
1023 | |
---|
1024 | function ogGetImageProgram () |
---|
1025 | { |
---|
1026 | local IMGFILE |
---|
1027 | # Si se solicita, mostrar ayuda. |
---|
1028 | if [ "$*" == "help" ]; then |
---|
1029 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image" \ |
---|
1030 | "$FUNCNAME REPO prueba ==> PARTCLONE" |
---|
1031 | return |
---|
1032 | fi |
---|
1033 | # Error si no se reciben 2 parámetros. |
---|
1034 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1035 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
1036 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
1037 | ogGetImageInfo $IMGFILE | awk -F: '{print $1}' |
---|
1038 | } |
---|
1039 | |
---|
1040 | #/** |
---|
1041 | # ogGetImageCompressor str_REPO str_imagen |
---|
1042 | #@brief muestra información sobre la imagen monolitica. |
---|
1043 | #@see ogGetImageInfo |
---|
1044 | #@param 1 REPO o CACHE contenedor de la imagen |
---|
1045 | #@param 2 filename nombre de la imagen sin extension |
---|
1046 | #@return tipo de compresión usada al generar la imagen |
---|
1047 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1048 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
1049 | #@note ogGetImageCompressor REPO imagenA -> lzop |
---|
1050 | #@version 1.0 - Primeras pruebas |
---|
1051 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
1052 | #@date 2010/02/08 |
---|
1053 | #*/ ## |
---|
1054 | function ogGetImageCompressor () |
---|
1055 | { |
---|
1056 | local IMGFILE |
---|
1057 | # Si se solicita, mostrar ayuda. |
---|
1058 | if [ "$*" == "help" ]; then |
---|
1059 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image" \ |
---|
1060 | "$FUNCNAME REPO prueba ==> LZOP" |
---|
1061 | return |
---|
1062 | fi |
---|
1063 | # Error si no se reciben 2 parámetros. |
---|
1064 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1065 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
1066 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
1067 | ogGetImageInfo $IMGFILE | awk -F: '{print $2}' |
---|
1068 | } |
---|
1069 | |
---|
1070 | |
---|
1071 | #/** |
---|
1072 | # ogGetImageType str_REPO str_imagen |
---|
1073 | #@brief muestra información sobre el sistema de archivos de imagen monolitica. |
---|
1074 | #@see ogGetImageInfo |
---|
1075 | #@param 1 REPO o CACHE contenedor de la imagen |
---|
1076 | #@param 2 filename nombre de la imagen sin extension |
---|
1077 | #@return tipo de compresión usada al generar la imagen |
---|
1078 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1079 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
1080 | #@note ogGetImageType REPO imagenA -> NTFS |
---|
1081 | #@version 1.0 - Primeras pruebas |
---|
1082 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
1083 | #@date 2010/02/08 |
---|
1084 | #*/ ## |
---|
1085 | function ogGetImageType () |
---|
1086 | { |
---|
1087 | local IMGFILE |
---|
1088 | # Si se solicita, mostrar ayuda. |
---|
1089 | if [ "$*" == "help" ]; then |
---|
1090 | ogHelp "$FUNCNAME" "$FUNCNAME str_repo path_image" \ |
---|
1091 | "$FUNCNAME REPO prueba ==> NTFS" |
---|
1092 | return |
---|
1093 | fi |
---|
1094 | # Error si no se reciben 2 parámetros. |
---|
1095 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1096 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
1097 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
1098 | ogGetImageInfo $IMGFILE | awk -F: '{print $3}' |
---|
1099 | } |
---|
1100 | |
---|
1101 | |
---|
1102 | #/** |
---|
1103 | # ogGetImageSize str_REPO str_imagen |
---|
1104 | #@brief muestra información sobre el tamaño (KB) del sistema de archivos de imagen monolitica. |
---|
1105 | #@see ogGetImageInfo |
---|
1106 | #@param 1 REPO o CACHE contenedor de la imagen |
---|
1107 | #@param 2 filename nombre de la imagen sin extension |
---|
1108 | #@return tipo de compresión usada al generar la imagen |
---|
1109 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1110 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
1111 | #@note ogGetImagesize REPO imagenA -> 56432234 > Kb |
---|
1112 | #@version 1.0 - Primeras pruebas |
---|
1113 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
1114 | #@date 2010/02/08 |
---|
1115 | #*/ ## |
---|
1116 | function ogGetImageSize () |
---|
1117 | { |
---|
1118 | # Variables locales |
---|
1119 | local IMGFILE |
---|
1120 | |
---|
1121 | # Si se solicita, mostrar ayuda. |
---|
1122 | if [ "$*" == "help" ]; then |
---|
1123 | ogHelp "$FUNCNAME" "$FUNCNAME str repo path_image" \ |
---|
1124 | "$FUNCNAME REPO prueba ==> 5642158" |
---|
1125 | return |
---|
1126 | fi |
---|
1127 | # Error si no se reciben 2 parámetros. |
---|
1128 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1129 | # Error si el fichero de imagen no es accesible. |
---|
1130 | IMGFILE=$(ogGetPath "$1" "$2.img") |
---|
1131 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
1132 | |
---|
1133 | # Devuelve el tamaño de la imagen en KB. |
---|
1134 | ogGetImageInfo $IMGFILE | awk -F: '{print $4}' |
---|
1135 | } |
---|
1136 | |
---|
1137 | |
---|
1138 | #/** |
---|
1139 | # ogCreateGptImage int_ndisk str_repo path_image |
---|
1140 | #@brief Crea una imagen de la tabla de particiones GPT de un disco. |
---|
1141 | #@param int_ndisk nº de orden del disco |
---|
1142 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
1143 | #@param path_image camino de la imagen (sin extensión) |
---|
1144 | #@return (nada, por determinar) |
---|
1145 | #@note repo = { REPO, CACHE } |
---|
1146 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1147 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
1148 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
1149 | #@version 1.1 - Adaptación a OpenGnSys 1.1 |
---|
1150 | #@author Juan Carlos Garcia. Universidad de Zaragoza |
---|
1151 | #@date 2017/03/29 |
---|
1152 | #*/ ## |
---|
1153 | function ogCreateGptImage () |
---|
1154 | { |
---|
1155 | # Variables locales |
---|
1156 | local DISK IMGDIR IMGFILE |
---|
1157 | # Si se solicita, mostrar ayuda. |
---|
1158 | if [ "$*" == "help" ]; then |
---|
1159 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk path_dir str_image" \ |
---|
1160 | "$FUNCNAME 1 REPO /aula1/gpt" |
---|
1161 | return |
---|
1162 | fi |
---|
1163 | # Error si no se reciben 3 parámetros. |
---|
1164 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1165 | |
---|
1166 | DISK=$(ogDiskToDev "$1") || return $? |
---|
1167 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
1168 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
1169 | IMGFILE="$IMGDIR/$(basename "$3").gpt" |
---|
1170 | |
---|
1171 | # Crear imagen de la tabla GPT. |
---|
1172 | sgdisk -b="$IMGFILE" "$DISK" || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
1173 | } |
---|
1174 | |
---|
1175 | #/** |
---|
1176 | # ogRestoreGptImage str_repo path_image int_ndisk |
---|
1177 | #@brief Restaura la imagen de la tabla de particiones GPT de un disco. |
---|
1178 | #@param str_repo repositorio de imágenes o caché local |
---|
1179 | #@param path_image camino de la imagen |
---|
1180 | #@param int_ndisk nº de orden del disco |
---|
1181 | #@return (por determinar) |
---|
1182 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1183 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
1184 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
1185 | #@version 1.1 - Adaptación a OpenGnSys 1.1 |
---|
1186 | #@author Juan Carlos Garcia, Universidad de Zaragoza |
---|
1187 | #@date 2017/03/29 |
---|
1188 | #*/ ## |
---|
1189 | function ogRestoreGptImage () |
---|
1190 | { |
---|
1191 | # Variables locales |
---|
1192 | local DISK IMGFILE |
---|
1193 | # Si se solicita, mostrar ayuda. |
---|
1194 | if [ "$*" == "help" ]; then |
---|
1195 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk" \ |
---|
1196 | "$FUNCNAME REPO /aula1/gpt 1" |
---|
1197 | return |
---|
1198 | fi |
---|
1199 | # Error si no se reciben 3 parámetros. |
---|
1200 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1201 | # Procesar parámetros. |
---|
1202 | DISK=$(ogDiskToDev "$3") || return $? |
---|
1203 | IMGFILE=$(ogGetPath "$1" "$2.gpt") |
---|
1204 | [ -r "$IMGFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
1205 | |
---|
1206 | # Restaurar tabla GPT del disco. |
---|
1207 | sgdisk -l="$IMGFILE" "$DISK" || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
1208 | } |
---|
1209 | |
---|