[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. |
---|
[a25cc03] | 7 | #@version 1.0 |
---|
[715bedc] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[914d834] | 11 | |
---|
| 12 | |
---|
| 13 | function ogPartcloneSyntax () |
---|
| 14 | { |
---|
| 15 | #TODO: comprobar como unico parametro particion /dev/sda1 |
---|
| 16 | #COMPAR="partclone.$FS --clone --force --source $PART" |
---|
[0084b42] | 17 | COMPAR=" -d0 -F -c -s " |
---|
[914d834] | 18 | TYPE="$(ogGetFsType `ogDevToDisk $1`)" |
---|
| 19 | case "$TYPE" in |
---|
| 20 | EXT[234]) |
---|
| 21 | echo "partclone.extfs $COMPAR $1" |
---|
| 22 | ;; |
---|
| 23 | REISERFS|XFS|JFS) |
---|
| 24 | echo "partclone.dd $COMPAR $1" |
---|
| 25 | ;; |
---|
| 26 | NTFS|HNTFS) |
---|
| 27 | echo "partclone.ntfs $COMPAR $1" |
---|
| 28 | ;; |
---|
| 29 | FAT16|FAT32|HFAT16|HFAT32) |
---|
| 30 | echo "partclone.fat $COMPAR $1" |
---|
| 31 | ;; |
---|
| 32 | HFS|HFS+) |
---|
| 33 | echo "partclone.hfsp $COMPAR $1" |
---|
| 34 | ;; |
---|
| 35 | *) ogRaiseError $OG_ERR_PARTITION "$1 $TYPE" |
---|
| 36 | return $? ;; |
---|
| 37 | esac |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | #/** |
---|
| 41 | # ogCreateImageSyntax partition filename [tools] [levelcompresor] |
---|
| 42 | #@brief Genera una cadena de texto con la instrucción para crear un fichero imagen |
---|
| 43 | #@param 1 partition identificador linux del dispositivo particion. |
---|
| 44 | #@param 2 filename path absoluto del fichero imagen |
---|
| 45 | #@param 3 [opcional] str_tools herrmaienta de clonacion [partimage, partclone, ntfsclone] |
---|
| 46 | #@param 4 [opcional] str_levelcompresor nivel de compresion. [0 -none-, 1-lzop-, 2-gzip] |
---|
| 47 | #@return cadena con el comando que se debe ejecutar. |
---|
| 48 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 49 | #@warning En pruebas iniciales |
---|
| 50 | #@TODO introducir las herramientas fsarchiver, dd |
---|
| 51 | #@TODO introducir el nivel de compresion gzip |
---|
| 52 | #@version 1.0 - Primeras pruebas |
---|
| 53 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 54 | #@date 2010/02/08 |
---|
| 55 | #*/ ## |
---|
| 56 | |
---|
| 57 | function ogCreateImageSyntax() |
---|
| 58 | { |
---|
| 59 | local FS TOOL LEVEL PART IMGFILE BUFFER |
---|
| 60 | |
---|
| 61 | # Si se solicita, mostrar ayuda. |
---|
| 62 | if [ "$*" == "help" ]; then |
---|
| 63 | ogHelp "$FUNCNAME" "$FUNCNAME partition filename [tool] [levelcompresor]" \ |
---|
| 64 | "$FUNCNAME /dev/sda1 /opt/opengnsys/images/prueba.img partclone lzop" |
---|
| 65 | return |
---|
| 66 | fi |
---|
| 67 | # Error si no se reciben al menos los 2 parámetros para obtener el valor default. |
---|
| 68 | [ $# -lt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | PART=`echo $1` |
---|
| 72 | IMGFILE=`echo $2` |
---|
| 73 | |
---|
| 74 | case "$#" in |
---|
| 75 | "2") |
---|
| 76 | # Sintaxis por defecto OG PART IMGFILE |
---|
| 77 | #echo "partimage -M -f3 -o -d -V0 -B gui=no -c -z1 save $PART $IMGFILE" |
---|
| 78 | # Se comenta la instruccion que debería ir aqui |
---|
| 79 | ogCreateImageSyntax $1 $2 partclone gzip |
---|
| 80 | ;; |
---|
| 81 | "4") |
---|
| 82 | # Sintaxis condicionada. |
---|
| 83 | # comprobamos parametro herramienta compresion. |
---|
| 84 | TOOL=$(echo $3 | tr [A-Z] [a-z]) |
---|
| 85 | #ogCheckProgram $TOOL |
---|
| 86 | #comprobar parámetro compresor. |
---|
| 87 | LEVEL=$(echo $4 | tr [A-Z] [a-z]) |
---|
| 88 | #ogCheckProgram $LEVEL |
---|
| 89 | |
---|
| 90 | # herramienta |
---|
| 91 | case "$TOOL" in |
---|
| 92 | "ntfsclone") |
---|
| 93 | PARAM1="ntfsclone --force --save-image -O - $PART" |
---|
| 94 | ;; |
---|
| 95 | "partimage"|DEFAULT) |
---|
| 96 | PARAM1="partimage -M -f3 -o -d -B gui=no -c -z0 --volume=0 save $PART stdout" |
---|
| 97 | ;; |
---|
| 98 | "partclone") |
---|
| 99 | PARAM1=`ogPartcloneSyntax $PART` || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 100 | ;; |
---|
| 101 | esac |
---|
| 102 | # mbuffer |
---|
| 103 | which mbuffer > /dev/null && PARAM2="| mbuffer -q -m 40M " || PARAM2=" " |
---|
| 104 | |
---|
| 105 | # nivel de compresion |
---|
| 106 | case "$LEVEL" in |
---|
| 107 | "0"|"none") |
---|
| 108 | PARAM3=" > " |
---|
| 109 | ;; |
---|
| 110 | "1"|"lzop") |
---|
| 111 | PARAM3=" | lzop > " |
---|
| 112 | ;; |
---|
| 113 | "2"|"gzip") |
---|
| 114 | PARAM3=" | gzip -c > " |
---|
| 115 | ;; |
---|
| 116 | "3"|"bzip") |
---|
| 117 | PARAM3=" | bzip -c > " |
---|
| 118 | ;; |
---|
| 119 | esac |
---|
| 120 | #sintaxis final. |
---|
| 121 | echo "$PARAM1 $PARAM2 $PARAM3 $IMGFILE" |
---|
| 122 | ;; |
---|
| 123 | esac |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | #/** |
---|
| 128 | # ogRestoreImageSyntax filename partition [tools] [levelcompresor] |
---|
| 129 | #@brief Genera una cadena de texto con la instrucción para crear un fichero imagen |
---|
| 130 | #@param 1 filename path absoluto del fichero imagen |
---|
| 131 | #@param 2 partition identificador linux del dispositivo particion. |
---|
| 132 | #@param 3 [opcional] str_tools herrmaienta de clonacion [partimage, partclone, ntfsclone] |
---|
| 133 | #@param 4 [opcional] str_levelcompresor nivel de compresion. [0 -none-, 1-lzop-, 2-gzip] |
---|
| 134 | #@return cadena con el comando que se debe ejecutar. |
---|
| 135 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 136 | #@warning En pruebas iniciales |
---|
| 137 | #@TODO introducir las herramientas fsarchiver, dd |
---|
| 138 | #@TODO introducir el nivel de compresion gzip |
---|
| 139 | #@version 1.0 - Primeras pruebas |
---|
| 140 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 141 | #@date 2010/02/08 |
---|
| 142 | #*/ ## |
---|
| 143 | |
---|
| 144 | ogRestoreImageSyntax () |
---|
| 145 | { |
---|
| 146 | local TOOL COMPRESSOR LEVEL PART IMGFILE FILEHEAD INFOIMG |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | # Si se solicita, mostrar ayuda. |
---|
| 150 | if [ "$*" == "help" ]; then |
---|
| 151 | ogHelp "$FUNCNAME" "$FUNCNAME filename partition [tool] [levelcompresor]" \ |
---|
| 152 | "$FUNCNAME /opt/opengnsys/images/prueba.img /dev/sda1 [partclone] [lzop]" |
---|
| 153 | return |
---|
| 154 | fi |
---|
| 155 | |
---|
| 156 | # Error si no se reciben al menos 2 parámetros. |
---|
| 157 | [ $# -lt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 158 | |
---|
| 159 | # controlamos que el parametro 1 (imagen) es tipo file. |
---|
| 160 | [ -f $1 ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 161 | |
---|
| 162 | # Si 2 parametros (file-origen-, device-destino-) = ogGetImageFull($1) |
---|
| 163 | if [ "$#" -eq 2 ]; then |
---|
| 164 | IMGFILE=$1 |
---|
| 165 | PART=$2 |
---|
| 166 | INFOIMG=$(ogGetImageInfo $IMGFILE) || ogRaiseError $OG_ERR_NOTFOUND "No Image $1" || return $? |
---|
| 167 | TOOL=`echo $INFOIMG | cut -f1 -d:` |
---|
| 168 | COMPRESSOR=`echo $INFOIMG | cut -f2 -d:` |
---|
| 169 | ogRestoreImageSyntax $IMGFILE $PART $TOOL $COMPRESSOR |
---|
| 170 | fi |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | # Si cuatro parametros genera sintaxis |
---|
| 174 | if [ "$#" -eq 4 ]; then |
---|
| 175 | IMGFILE=$1 |
---|
| 176 | PART=$2 |
---|
| 177 | # comprobamos parametro herramienta compresion. |
---|
| 178 | TOOL=$(echo $3 | tr [A-Z] [a-z]) |
---|
| 179 | #ogCheckProgram $TOOL |
---|
| 180 | #comprobar parámetro compresor. |
---|
| 181 | LEVEL=$(echo $4 | tr [A-Z] [a-z]) |
---|
| 182 | #ogCheckProgram $LEVEL |
---|
| 183 | |
---|
| 184 | case "$LEVEL" in |
---|
| 185 | "0"|"none") |
---|
| 186 | COMPRESSOR=" " |
---|
| 187 | ;; |
---|
| 188 | "1"|"lzop" | "LZOP") |
---|
| 189 | COMPRESSOR=" lzop -dc " |
---|
| 190 | ;; |
---|
| 191 | "2"|"gzip" | "GZIP") |
---|
| 192 | COMPRESSOR=" gzip -dc " |
---|
| 193 | ;; |
---|
| 194 | "3"|"bzip" | "BZIP" ) |
---|
| 195 | COMPRESSOR=" bzip -dc " |
---|
| 196 | ;; |
---|
| 197 | *) |
---|
| 198 | ogRaiseError $OG_ERR_NOTFOUND "Compressor no valid $TOOL" || return $? |
---|
| 199 | ;; |
---|
| 200 | esac |
---|
| 201 | #comprobar mbuffer |
---|
| 202 | which mbuffer > /dev/null && MBUFFER="| mbuffer -q -m 40M " || MBUFFER=" " |
---|
| 203 | |
---|
| 204 | case "$TOOL" in |
---|
| 205 | "ntfsclone" | "NTFSCLONE") |
---|
| 206 | TOOL="| ntfsclone --restore-image --overwrite $PART -" |
---|
| 207 | ;; |
---|
| 208 | "partimage"| "PARTIMAGE") |
---|
| 209 | TOOL="| partimage -f3 -B gui=no restore $PART stdin" |
---|
| 210 | ;; |
---|
| 211 | "partclone" | "PARTCLONE") |
---|
| 212 | # -C para que no compruebe tamaños |
---|
[0084b42] | 213 | TOOL="| partclone.restore -d0 -C -I -o $PART" |
---|
[914d834] | 214 | ;; |
---|
| 215 | *) |
---|
| 216 | ogRaiseError $OG_ERR_NOTFOUND "Tools imaging no valid $TOOL" || return $? |
---|
| 217 | ;; |
---|
| 218 | esac |
---|
| 219 | |
---|
| 220 | echo "$COMPRESSOR $IMGFILE $MBUFFER $TOOL" |
---|
| 221 | fi |
---|
| 222 | |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
[715bedc] | 227 | |
---|
| 228 | #/** |
---|
[ebf06c7] | 229 | # ogCreateImage int_ndisk int_npartition str_repo path_image |
---|
[715bedc] | 230 | #@brief Crea una imagen a partir de una partición. |
---|
[42669ebf] | 231 | #@param int_ndisk nº de orden del disco |
---|
| 232 | #@param int_npartition nº de orden de la partición |
---|
| 233 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
| 234 | #@param path_image camino de la imagen (sin extensión) |
---|
[715bedc] | 235 | #@return (nada, por determinar) |
---|
[ebf06c7] | 236 | #@note repo = { REPO, CACHE } |
---|
[cfeabbf] | 237 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 238 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
| 239 | #@exception OG_ERR_PARTITION partición no accesible o no soportada. |
---|
| 240 | #@exception OG_ERR_LOCKED particion bloqueada por otra operación. |
---|
| 241 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
[715bedc] | 242 | #@warning En pruebas iniciales |
---|
[3458879] | 243 | #@todo Comprobaciones, control de errores, definir parámetros, etc. |
---|
[985bef0] | 244 | #@version 0.1 - Integracion para Opengnsys - HIDRA:CrearImagen{EXT3, NTFS}.sh; EAC: CreateImageFromPartition () en Deploy.lib |
---|
| 245 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 246 | #@Date 2008/05/13 |
---|
| 247 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 248 | #@date 2008/10/27 |
---|
[0fbc05e] | 249 | #@version 0.9 - Versión en pruebas para OpenGnSys |
---|
[715bedc] | 250 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[cfeabbf] | 251 | #@date 2009/10/07 |
---|
[1e7eaab] | 252 | #*/ ## |
---|
[42669ebf] | 253 | function ogCreateImage () |
---|
| 254 | { |
---|
[59f9ad2] | 255 | # Variables locales |
---|
[08b941f] | 256 | local PART PROGRAM IMGDIR IMGFILE IMGTYPE ERRCODE |
---|
[59f9ad2] | 257 | |
---|
[42669ebf] | 258 | # Si se solicita, mostrar ayuda. |
---|
[59f9ad2] | 259 | if [ "$*" == "help" ]; then |
---|
| 260 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npart path_dir str_image" \ |
---|
[3543b3e] | 261 | "$FUNCNAME 1 1 REPO /aula1/winxp" |
---|
[59f9ad2] | 262 | return |
---|
| 263 | fi |
---|
[c136ae7] | 264 | # Error si no se reciben 4 parámetros. |
---|
[914d834] | 265 | [ $# -lt 4 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[59f9ad2] | 266 | |
---|
[08b941f] | 267 | # Comprobar que no está bloqueada ni la partición, ni la imagen. |
---|
[715bedc] | 268 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
[a79dd508] | 269 | if ogIsLocked $1 $2; then |
---|
[08b941f] | 270 | ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $1, $2" |
---|
[a79dd508] | 271 | return $? |
---|
| 272 | fi |
---|
[914d834] | 273 | IMGTYPE="img" # Extensión genérica de imágenes. |
---|
[cfeabbf] | 274 | IMGDIR=$(ogGetParentPath "$3" "$4") |
---|
[914d834] | 275 | |
---|
[cfeabbf] | 276 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$3 $(dirname $4)" || return $? |
---|
[08b941f] | 277 | IMGFILE="$IMGDIR/$(basename "$4").$IMGTYPE" |
---|
| 278 | if ogIsImageLocked "$IMGFILE"; then |
---|
| 279 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $3, $4" |
---|
| 280 | return $? |
---|
| 281 | fi |
---|
| 282 | # Desmontar partición, bloquear partición e imagen. |
---|
[cfeabbf] | 283 | ogUnmount $1 $2 2>/dev/null |
---|
[a79dd508] | 284 | ogLock $1 $2 || return $? |
---|
[08b941f] | 285 | ogLockImage "$3" "$4.$IMGTYPE" || return $? |
---|
[715bedc] | 286 | |
---|
[08b941f] | 287 | # Crear Imagen. |
---|
| 288 | trap "ogUnlock $1 $2; ogUnlockImage "$3" "$4.$IMGTYPE"; rm -f $IMGFILE" 1 2 3 6 9 |
---|
[914d834] | 289 | #Solicitamos la generación de la instruccion a ejecutar |
---|
| 290 | PROGRAM=`ogCreateImageSyntax $PART $IMGFILE $5 $6` |
---|
| 291 | echo $PROGRAM |
---|
| 292 | eval $PROGRAM |
---|
[08b941f] | 293 | |
---|
[42669ebf] | 294 | # Controlar salida de error y desbloquear partición. |
---|
[cfeabbf] | 295 | ERRCODE=$? |
---|
[f5432db7] | 296 | if [ $ERRCODE != 0 ]; then |
---|
[cfeabbf] | 297 | ogRaiseError $OG_ERR_IMAGE "$1 $2 $IMGFILE" |
---|
[f5432db7] | 298 | rm -f "$IMGFILE" |
---|
[cfeabbf] | 299 | fi |
---|
[08b941f] | 300 | # Desbloquear partición e imagen. |
---|
[715bedc] | 301 | ogUnlock $1 $2 |
---|
[08b941f] | 302 | ogUnlockImage "$3" "$4.$IMGTYPE" |
---|
[cfeabbf] | 303 | return $ERRCODE |
---|
[715bedc] | 304 | } |
---|
| 305 | |
---|
[b094c59] | 306 | |
---|
[a25cc03] | 307 | #/** |
---|
| 308 | # ogCreateMbrImage int_ndisk str_repo path_image |
---|
| 309 | #@brief Crea una imagen a partir del sector de arranque de un disco. |
---|
| 310 | #@param int_ndisk nº de orden del disco |
---|
| 311 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
| 312 | #@param path_image camino de la imagen (sin extensión) |
---|
| 313 | #@return (nada, por determinar) |
---|
| 314 | #@note repo = { REPO, CACHE } |
---|
| 315 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 316 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
| 317 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
| 318 | #@version 0.9 - Versión en pruebas para OpenGNSys |
---|
| 319 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 320 | #@date 2010/01/12 |
---|
| 321 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
| 322 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 323 | #@date 2011/03/10 |
---|
| 324 | #*/ ## |
---|
| 325 | function ogCreateMbrImage () |
---|
| 326 | { |
---|
| 327 | # Variables locales |
---|
| 328 | local DISK IMGDIR IMGFILE |
---|
| 329 | # Si se solicita, mostrar ayuda. |
---|
| 330 | if [ "$*" == "help" ]; then |
---|
| 331 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk path_dir str_image" \ |
---|
| 332 | "$FUNCNAME 1 REPO /aula1/mbr" |
---|
| 333 | return |
---|
| 334 | fi |
---|
| 335 | # Error si no se reciben 3 parámetros. |
---|
| 336 | [ $# -lt 3 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 337 | |
---|
| 338 | DISK=$(ogDiskToDev "$1") || return $? |
---|
| 339 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
| 340 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
| 341 | IMGFILE="$IMGDIR/$(basename "$3").mbr" |
---|
| 342 | |
---|
| 343 | # Crear imagen del MBR. |
---|
| 344 | dd if="$DISK" of="$IMGFILE" bs=512 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | |
---|
| 348 | #/** |
---|
[b52e658] | 349 | # ogCreateBootLoaderImage int_ndisk str_repo path_image |
---|
| 350 | #@brief Crea una imagen del boot loader a partir del sector de arranque de un disco. |
---|
| 351 | #@param int_ndisk nº de orden del disco |
---|
| 352 | #@param str_repo repositorio de imágenes (remoto o caché local) |
---|
| 353 | #@param path_image camino de la imagen (sin extensión) |
---|
| 354 | #@return (nada, por determinar) |
---|
| 355 | #@note repo = { REPO, CACHE } |
---|
| 356 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 357 | #@exception OG_ERR_NOTFOUND fichero o dispositivo no encontrado. |
---|
| 358 | #@exception OG_ERR_IMAGE error al crear la imagen del sistema. |
---|
| 359 | #@version 1.0 - Adaptacion de ogCreateMbrImage para guardar solo el Boot Loader |
---|
| 360 | #@author Juan Carlos Xifre, SICUZ Universidad de Zaragoza |
---|
| 361 | #@date 2011/03/21 |
---|
| 362 | #*/ ## |
---|
| 363 | function ogCreateBootLoaderImage () |
---|
| 364 | { |
---|
| 365 | # Variables locales |
---|
| 366 | local DISK IMGDIR IMGFILE |
---|
| 367 | # Si se solicita, mostrar ayuda. |
---|
| 368 | if [ "$*" == "help" ]; then |
---|
| 369 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk path_dir str_image" \ |
---|
| 370 | "$FUNCNAME 1 REPO /aula1/mbr" |
---|
| 371 | return |
---|
| 372 | fi |
---|
| 373 | # Error si no se reciben 3 parámetros. |
---|
| 374 | [ $# -lt 3 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 375 | |
---|
| 376 | DISK=$(ogDiskToDev "$1") || return $? |
---|
| 377 | IMGDIR=$(ogGetParentPath "$2" "$3") |
---|
| 378 | [ -n "$IMGDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$2 $(dirname $3)" || return $? |
---|
| 379 | IMGFILE="$IMGDIR/$(basename "$3").mbr" |
---|
| 380 | |
---|
| 381 | # Crear imagen del Boot Loader dentro del MBR. |
---|
| 382 | dd if="$DISK" of="$IMGFILE" bs=446 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
| 383 | } |
---|
| 384 | |
---|
[cbbb046] | 385 | |
---|
[b52e658] | 386 | #/** |
---|
[a25cc03] | 387 | # ogIsImageLocked [str_repo] path_image |
---|
| 388 | #@brief Comprueba si una imagen está bloqueada para uso exclusivo. |
---|
| 389 | #@param str_repo repositorio de imágenes (opcional) |
---|
| 390 | #@param path_image camino de la imagen (sin extensión) |
---|
[7685100] | 391 | #@return Código de salida: 0 - bloqueado, 1 - sin bloquear o error. |
---|
[a25cc03] | 392 | #@note repo = { REPO, CACHE } |
---|
| 393 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 394 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
| 395 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 396 | #@date 2011/03/10 |
---|
[7685100] | 397 | #@version 1.0.1 - Devolver falso en caso de error. |
---|
| 398 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 399 | #@date 2011-05-18 |
---|
[a25cc03] | 400 | #*/ ## |
---|
| 401 | function ogIsImageLocked () |
---|
| 402 | { |
---|
| 403 | # Si se solicita, mostrar ayuda. |
---|
| 404 | if [ "$*" == "help" ]; then |
---|
| 405 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 406 | "if $FUNCNAME /opt/opengnsys/images/aula1/winxp.img; then ...; fi" \ |
---|
| 407 | "if $FUNCNAME REPO /aula1/winxp.img; then ...; fi" |
---|
| 408 | return |
---|
| 409 | fi |
---|
| 410 | # Error si no se reciben 1 o 2 parámetros. |
---|
[7685100] | 411 | [ $# -lt 1 -o $# -gt 2 ] && return 1 |
---|
[914d834] | 412 | |
---|
[a25cc03] | 413 | # Comprobar si existe el fichero de bloqueo. |
---|
| 414 | test -n "$(ogGetPath $@.lock)" |
---|
| 415 | } |
---|
[914d834] | 416 | |
---|
| 417 | |
---|
[a25cc03] | 418 | #/** |
---|
| 419 | # ogLockImage [str_repo] path_image |
---|
| 420 | #@brief Bloquea una imagen para uso exclusivo. |
---|
| 421 | #@param str_repo repositorio de imágenes (opcional) |
---|
| 422 | #@param path_image camino de la imagen (sin extensión) |
---|
| 423 | #@return Nada. |
---|
| 424 | #@note Se genera un fichero con extensión .lock |
---|
| 425 | #@note repo = { REPO, CACHE } |
---|
| 426 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 427 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
| 428 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 429 | #@date 2011/03/10 |
---|
| 430 | #*/ ## |
---|
| 431 | function ogLockImage () |
---|
| 432 | { |
---|
| 433 | # Variables locales |
---|
| 434 | local IMGDIR |
---|
[914d834] | 435 | |
---|
[a25cc03] | 436 | # Si se solicita, mostrar ayuda. |
---|
| 437 | if [ "$*" == "help" ]; then |
---|
| 438 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 439 | "$FUNCNAME /opt/opengnsys/images/aula1/winxp.img" \ |
---|
| 440 | "$FUNCNAME REPO /aula1/winxp.img" |
---|
| 441 | return |
---|
| 442 | fi |
---|
| 443 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 444 | [ $# -lt 1 -o $# -gt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 445 | # Comprobar que existe directorio de imagen |
---|
| 446 | IMGDIR=$(ogGetParentPath $@) || return $? |
---|
| 447 | # Crear fichero de bloqueo. |
---|
| 448 | touch $IMGDIR/$(basename "${!#}").lock |
---|
| 449 | } |
---|
[914d834] | 450 | |
---|
| 451 | |
---|
| 452 | #/** |
---|
| 453 | # ogRestoreImage str_repo path_image int_ndisk int_npartition |
---|
| 454 | #@brief Restaura una imagen de sistema de archivos en una partición. |
---|
| 455 | #@param str_repo repositorio de imágenes o caché local |
---|
| 456 | #@param path_image camino de la imagen |
---|
| 457 | #@param int_ndisk nº de orden del disco |
---|
| 458 | #@param int_npartition nº de orden de la partición |
---|
| 459 | #@return (por determinar) |
---|
[8e83677] | 460 | #@exception OG_ERR_FORMAT 1 formato incorrecto. |
---|
| 461 | #@exception OG_ERR_NOTFOUND 2 fichero de imagen o partición no detectados. |
---|
| 462 | #@exception OG_ERR_PARTITION 3 # Error en partición de disco. |
---|
| 463 | #@exception OG_ERR_LOCKED 4 partición bloqueada por otra operación. |
---|
| 464 | #@exception OG_ERR_IMAGE 5 error al restaurar la imagen del sistema. |
---|
| 465 | #@exception OG_ERR_IMGSIZEPARTITION 30 Tamaño de la particion es menor al tamaño de la imagen. |
---|
[914d834] | 466 | #@todo Comprobar incongruencias partición-imagen, control de errores, definir parámetros, caché/repositorio, etc. |
---|
| 467 | #@version 0.1 - Integracion para Opengnsys - HIDRA:RestaurarImagen{EXT3, NTFS}.sh; EAC: RestorePartitionFromImage() en Deploy.lib |
---|
| 468 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 469 | #@Date 2008/05/13 |
---|
| 470 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 471 | #@date 2008/10/27 |
---|
| 472 | #@version 0.9 - Primera version muy en pruebas para OpenGnSys |
---|
| 473 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 474 | #@date 2009/09/10 |
---|
[8e83677] | 475 | #@version 1.0 - generacion sintaxis de restauracion |
---|
| 476 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 477 | #@date 2011/02/01 |
---|
| 478 | #@version 1.0.1 - Control errores, tamaño particion, fichero-imagen |
---|
| 479 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 480 | #@date 2011/05/11 |
---|
[914d834] | 481 | #*/ ## |
---|
| 482 | function ogRestoreImage () |
---|
| 483 | { |
---|
| 484 | # Variables locales |
---|
[cbbb046] | 485 | local PART PARTSIZE IMGFILE IMGTYPE IMGSIZE FSTYPE PROGRAM ERRCODE |
---|
[914d834] | 486 | |
---|
| 487 | # Si se solicita, mostrar ayuda. |
---|
| 488 | if [ "$*" == "help" ]; then |
---|
| 489 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk int_npart" \ |
---|
| 490 | "$FUNCNAME REPO /aula1/winxp 1 1" |
---|
| 491 | return |
---|
| 492 | fi |
---|
| 493 | # Error si no se reciben 4 parámetros. |
---|
[8e83677] | 494 | [ $# -lt 4 ] && return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
[914d834] | 495 | # Procesar parámetros. |
---|
[8e83677] | 496 | PART="$(ogDiskToDev $3 $4)" || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
[914d834] | 497 | #IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 498 | IMGTYPE=img |
---|
[8e83677] | 499 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
| 500 | [ -r "$IMGFILE" ] || return $(ogRaiseError $OG_ERR_NOTFOUND " $3 $4"; echo $?) |
---|
| 501 | # comprobamos consistencia de la imagen |
---|
| 502 | ogGetImageInfo $IMGFILE >/dev/null || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
| 503 | |
---|
[914d834] | 504 | # Error si la imagen no cabe en la particion. |
---|
[8e83677] | 505 | IMGSIZE=$(ogGetImageSize "$1" "$2") || return $(ogRaiseError $OG_ERR_IMAGE " $1 $2"; echo $?) |
---|
[be3b96a] | 506 | #TODO: |
---|
[8e83677] | 507 | #Si la particion no esta formateado o tiene problemas formateamos |
---|
| 508 | ogMount $3 $4 || ogFormat $3 $4 |
---|
[f8b1b41] | 509 | #PARTSIZE=$(parted -sm $DISK unit kB print | \ |
---|
| 510 | # awk -F: -v np=$4 '{if ($1==np) {gsub(/kB/,""); print $4} } ') |
---|
| 511 | PARTSIZE=$(ogGetPartitionSize $3 $4) |
---|
[914d834] | 512 | if [ $IMGSIZE -gt $PARTSIZE ]; then |
---|
[8e83677] | 513 | ogRaiseError $OG_ERR_IMGSIZEPARTITION " $PARTSIZE < $IMGSIZE" |
---|
[914d834] | 514 | return $? |
---|
| 515 | fi |
---|
| 516 | # Comprobar el bloqueo de la imagen y de la partición. |
---|
| 517 | if ogIsImageLocked "$IMGFILE"; then |
---|
| 518 | ogRaiseError $OG_ERR_LOCKED "$MSG_IMAGE $1, $2.$IMGTYPE" |
---|
| 519 | return $? |
---|
| 520 | fi |
---|
| 521 | if ogIsLocked $3 $4; then |
---|
| 522 | ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $3, $4" |
---|
| 523 | return $? |
---|
| 524 | fi |
---|
| 525 | # Desmontar y bloquear partición. |
---|
[8e83677] | 526 | ogUnmount $3 $4 2>/dev/null || return $(ogRaiseError $OG_ERR_PARTITION " $3 $4"; echo $?) |
---|
| 527 | ogLock $3 $4 || return $(ogRaiseError $OG_ERR_PARTITION " $3 $4"; echo $?) |
---|
[914d834] | 528 | trap "ogUnlock $3 $4" 1 2 3 6 9 |
---|
| 529 | |
---|
| 530 | # Restaurar según el tipo de imagen. |
---|
| 531 | # Atención: no se comprueba el tipo de sistema de archivos. |
---|
| 532 | # Atención: no se comprueba incongruencia entre partición e imagen. |
---|
| 533 | #Solicitamos la generación de la instruccion a ejecutar |
---|
| 534 | PROGRAM=`ogRestoreImageSyntax $IMGFILE $PART` |
---|
| 535 | echo $PROGRAM |
---|
| 536 | eval $PROGRAM |
---|
| 537 | |
---|
| 538 | ERRCODE=$? |
---|
| 539 | if [ $ERRCODE != 0 ]; then |
---|
| 540 | ogRaiseError $OG_ERR_IMAGE "$IMGFILE, $3, $4" |
---|
| 541 | fi |
---|
| 542 | ogUnlock $3 $4 |
---|
| 543 | return $ERRCODE |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | |
---|
| 547 | #/** |
---|
[a25cc03] | 548 | # ogRestoreMbrImage str_repo path_image int_ndisk |
---|
| 549 | #@brief Restaura la imagen del sector de arranque de un disco. |
---|
| 550 | #@param str_repo repositorio de imágenes o caché local |
---|
| 551 | #@param path_image camino de la imagen |
---|
| 552 | #@param int_ndisk nº de orden del disco |
---|
| 553 | #@return (por determinar) |
---|
| 554 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 555 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
| 556 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
| 557 | #@version 0.9 - Primera versión en pruebas. |
---|
| 558 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 559 | #@date 2010/01/12 |
---|
| 560 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
| 561 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 562 | #@date 2011/03/10 |
---|
| 563 | #*/ ## |
---|
| 564 | function ogRestoreMbrImage () |
---|
| 565 | { |
---|
| 566 | # Variables locales |
---|
| 567 | local DISK IMGFILE |
---|
| 568 | # Si se solicita, mostrar ayuda. |
---|
| 569 | if [ "$*" == "help" ]; then |
---|
| 570 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk" \ |
---|
| 571 | "$FUNCNAME REPO /aula1/mbr 1" |
---|
| 572 | return |
---|
| 573 | fi |
---|
| 574 | # Error si no se reciben 3 parámetros. |
---|
| 575 | [ $# -lt 3 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 576 | # Procesar parámetros. |
---|
| 577 | DISK=$(ogDiskToDev "$3") || return $? |
---|
| 578 | IMGFILE=$(ogGetPath "$1" "$2.mbr") || return $? |
---|
| 579 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 580 | |
---|
| 581 | # Restaurar imagen del MBR. |
---|
| 582 | dd if="$IMGFILE" of="$DISK" bs=512 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | |
---|
| 586 | #/** |
---|
[b52e658] | 587 | # ogRestoreBootLoaderImage str_repo path_image int_ndisk |
---|
| 588 | #@brief Restaura la imagen del boot loader del sector de arranque de un disco. |
---|
| 589 | #@param str_repo repositorio de imágenes o caché local |
---|
| 590 | #@param path_image camino de la imagen |
---|
| 591 | #@param int_ndisk nº de orden del disco |
---|
| 592 | #@return (por determinar) |
---|
| 593 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 594 | #@exception OG_ERR_NOTFOUND fichero de imagen o partición no detectados. |
---|
| 595 | #@exception OG_ERR_IMAGE error al restaurar la imagen del sistema. |
---|
| 596 | #@version 1.0 - Adaptacion de ogRestoreMbrImage para restaurar solo el Boot Loader |
---|
| 597 | #@author Juan Carlos Xifre, SICUZ Universidad de Zaragoza |
---|
| 598 | #@date 2011/03/21 |
---|
| 599 | #*/ ## |
---|
| 600 | function ogRestoreBootLoaderImage () |
---|
| 601 | { |
---|
| 602 | # Variables locales |
---|
| 603 | local DISK IMGFILE |
---|
| 604 | # Si se solicita, mostrar ayuda. |
---|
| 605 | if [ "$*" == "help" ]; then |
---|
| 606 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk" \ |
---|
| 607 | "$FUNCNAME REPO /aula1/mbr 1" |
---|
| 608 | return |
---|
| 609 | fi |
---|
| 610 | # Error si no se reciben 3 parámetros. |
---|
| 611 | [ $# -lt 3 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 612 | # Procesar parámetros. |
---|
| 613 | DISK=$(ogDiskToDev "$3") || return $? |
---|
| 614 | IMGFILE=$(ogGetPath "$1" "$2.mbr") || return $? |
---|
| 615 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 616 | |
---|
| 617 | # Restaurar imagen del MBR. |
---|
| 618 | dd if="$IMGFILE" of="$DISK" bs=446 count=1 || ogRaiseError $OG_ERR_IMAGE "$1 $IMGFILE" || return $? |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | #/** |
---|
[a25cc03] | 622 | # ogUnlockImage [str_repo] path_image |
---|
| 623 | #@brief Desbloquea una imagen con uso exclusivo. |
---|
| 624 | #@param str_repo repositorio de imágenes (opcional) |
---|
| 625 | #@param path_image camino de la imagen (sin extensión) |
---|
| 626 | #@return Nada. |
---|
| 627 | #@note repo = { REPO, CACHE } |
---|
| 628 | #@note Se elimina el fichero de bloqueo con extensión .lock |
---|
| 629 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 630 | #@version 1.0 - Adaptación a OpenGnSys 1.0 |
---|
| 631 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 632 | #@date 2011/03/10 |
---|
| 633 | #*/ ## |
---|
| 634 | function ogUnlockImage () |
---|
| 635 | { |
---|
| 636 | # Si se solicita, mostrar ayuda. |
---|
| 637 | if [ "$*" == "help" ]; then |
---|
| 638 | ogHelp "$FUNCNAME" "$FUNCNAME [str_repo] path_image" \ |
---|
| 639 | "$FUNCNAME /opt/opengnsys/images/aula1/winxp.img" \ |
---|
| 640 | "$FUNCNAME REPO /aula1/winxp.img" |
---|
| 641 | return |
---|
| 642 | fi |
---|
| 643 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 644 | [ $# -lt 1 -o $# -gt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 645 | |
---|
| 646 | # Borrar fichero de bloqueo para la imagen. |
---|
| 647 | rm -f $(ogGetPath $@.lock) |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | |
---|
| 651 | #/** |
---|
[914d834] | 652 | # ogGetImageInfo filename |
---|
| 653 | #@brief muestra información sobre la imagen monolitica. |
---|
| 654 | #@param 1 filename path absoluto del fichero imagen |
---|
| 655 | #@return cadena compuesta por clonacion:compresor:sistemaarchivos:tamañoKB |
---|
| 656 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 657 | #@exception OG_ERR_NOTFOUND fichero no encontrado. |
---|
| 658 | #@exception OG_ERR_IMAGE "Image format is not valid $IMGFILE" |
---|
| 659 | #@warning En pruebas iniciales |
---|
| 660 | #@TODO Definir sintaxis de salida (herramienta y compresor en minuscula) |
---|
| 661 | #@TODO Arreglar loop para ntfsclone |
---|
| 662 | #@TODO insertar parametros entrada tipo OG |
---|
| 663 | #@version 1.0 - Primeras pruebas |
---|
| 664 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 665 | #@date 2010/02/08 |
---|
| 666 | #*/ ## |
---|
| 667 | |
---|
[cbbb046] | 668 | function ogGetImageInfo () |
---|
| 669 | { |
---|
[914d834] | 670 | # Si se solicita, mostrar ayuda. |
---|
| 671 | if [ "$*" == "help" ]; then |
---|
| 672 | ogHelp "$FUNCNAME" "$FUNCNAME filename " \ |
---|
| 673 | "$FUNCNAME /opt/opengnsys/images/prueba.img " |
---|
| 674 | return |
---|
| 675 | fi |
---|
| 676 | |
---|
| 677 | # Error si no se reciben 1 parámetros. |
---|
| 678 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 679 | |
---|
| 680 | #comprobando que el parametro uno es un file. |
---|
| 681 | [ -f $1 ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 682 | |
---|
[2d5f79c] | 683 | local TOOLS COMPRESSOR IMGFILE FILEHEAD FS SIZE SIZEFACTOR PARTIMAGEINFO PARTCLONEINFO NTFSCLONEINFO IMGDETECT |
---|
[914d834] | 684 | IMGDETECT="FALSE" |
---|
| 685 | |
---|
| 686 | IMGFILE=$1 |
---|
| 687 | FILEHEAD=/tmp/`basename $IMGFILE`.infohead |
---|
| 688 | COMPRESSOR=`file $IMGFILE | awk '{print $2}'` |
---|
| 689 | ogCheckStringInGroup "$COMPRESSOR" "gzip lzop" || ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
| 690 | $($COMPRESSOR -dc $IMGFILE 2>/dev/null | head > $FILEHEAD) || ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
| 691 | |
---|
| 692 | ## buscando Primera opción. |
---|
| 693 | if [ "$IMGDETECT" == "FALSE" ] |
---|
| 694 | then |
---|
| 695 | PARTCLONEINFO=$(partclone.info $FILEHEAD 2>&1) |
---|
| 696 | if `echo $PARTCLONEINFO | grep size > /dev/null` |
---|
| 697 | then |
---|
| 698 | TOOLS=PARTCLONE |
---|
| 699 | FS=$(echo $PARTCLONEINFO | awk '{gsub(/\: /,"\n"); print toupper($8);}') |
---|
[be3b96a] | 700 | echo $PARTCLONEINFO | grep GB > /dev/null && SIZEFACTOR=1000000 || SIZEFACTOR=1024 |
---|
[2d5f79c] | 701 | SIZE=$(echo $PARTCLONEINFO | awk -v FACTOR=$SIZEFACTOR '{gsub(/\: /,"\n"); printf "%d\n", $11*FACTOR;}') |
---|
[914d834] | 702 | IMGDETECT="TRUE" |
---|
| 703 | fi |
---|
| 704 | fi |
---|
| 705 | #buscando segunda opcion. |
---|
| 706 | if [ "$IMGDETECT" == "FALSE" -a ! -f /dev/loop2 ] |
---|
| 707 | then |
---|
| 708 | cat $FILEHEAD | grep -w ntfsclone-image > /dev/null && NTFSCLONEINFO=$(cat $FILEHEAD | ntfsclone --restore --overwrite /dev/loop2 - 2>&1) |
---|
| 709 | if `echo $NTFSCLONEINFO | grep ntfsclone > /dev/null` |
---|
| 710 | then |
---|
| 711 | TOOLS=NTFSCLONE |
---|
| 712 | SIZE=$(echo $NTFSCLONEINFO | awk '{gsub(/\(|\)|\./,""); printf "%d\n",$17/1000;}') |
---|
| 713 | FS=NTFS |
---|
| 714 | IMGDETECT="TRUE" |
---|
| 715 | fi |
---|
| 716 | fi |
---|
| 717 | ## buscando Tercer opción. |
---|
| 718 | if [ "$IMGDETECT" == "FALSE" ] |
---|
| 719 | then |
---|
| 720 | PARTIMAGEINFO=$(partimage -B gui=no imginfo "$FILEHEAD" 2>&1) |
---|
| 721 | if `echo $PARTIMAGEINFO | grep Partition > /dev/null` |
---|
| 722 | then |
---|
| 723 | TOOLS=PARTIMAGE |
---|
| 724 | FS=$(echo $PARTIMAGEINFO | awk '{gsub(/ /,"\n"); print $17;}' | awk '{sub(/\.\.+/," "); print toupper($2)}') |
---|
| 725 | SIZE=$( echo $PARTIMAGEINFO | awk '{gsub(/ /,"\n"); print $36;}' | awk '{sub(/\.\.+/," "); printf "%d\n",$2*1024*1024;}') |
---|
| 726 | IMGDETECT="TRUE" |
---|
| 727 | fi |
---|
| 728 | fi |
---|
| 729 | #comprobamos valores #Chequeamos los valores devueltos. |
---|
| 730 | if [ -z "$TOOLS" -o -z "$COMPRESSOR" -o "$IMGDETECT" == "FALSE" ] |
---|
| 731 | then |
---|
| 732 | ogRaiseError $OG_ERR_IMAGE "Image format is not valid $IMGFILE" || return $? |
---|
| 733 | else |
---|
| 734 | COMPRESSOR=$(echo $COMPRESSOR | tr [a-z] [A-Z]) |
---|
| 735 | echo $TOOLS:$COMPRESSOR:$FS:$SIZE |
---|
| 736 | fi |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | function ogGetImageProgram () |
---|
| 740 | { |
---|
| 741 | local IMGFILE |
---|
| 742 | IMGFILE=$(ogGetPath "$1" "$2.img") || return $? |
---|
| 743 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 744 | ogGetImageInfo $IMGFILE | awk -F: '{print $1}' |
---|
| 745 | |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | function ogGetImageCompressor () |
---|
| 749 | { |
---|
| 750 | local IMGFILE |
---|
| 751 | IMGFILE=$(ogGetPath "$1" "$2.img") || return $? |
---|
| 752 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 753 | ogGetImageInfo $IMGFILE | awk -F: '{print $2}' |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | function ogGetImageType () |
---|
| 757 | { |
---|
| 758 | local IMGFILE |
---|
| 759 | IMGFILE=$(ogGetPath "$1" "$2.img") || return $? |
---|
| 760 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 761 | #partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 762 | # awk '/^Filesystem/ {sub(/\.\.+/," "); sub(/fs$/,""); print toupper($2);}' |
---|
| 763 | ogGetImageInfo $IMGFILE | awk -F: '{print $3}' |
---|
| 764 | |
---|
| 765 | } |
---|
| 766 | |
---|
| 767 | function ogGetImageSize () |
---|
| 768 | { |
---|
| 769 | # Variables locales |
---|
| 770 | local IMGFILE |
---|
| 771 | |
---|
| 772 | # Si se solicita, mostrar ayuda. |
---|
| 773 | if [ "$*" == "help" ]; then |
---|
[8e83677] | 774 | ogHelp "$FUNCNAME" "$FUNCNAME REPO|CACHE /str_image" \ |
---|
| 775 | "$FUNCNAME REPO /aula1/winxp ==> 5642158" |
---|
[914d834] | 776 | return |
---|
| 777 | fi |
---|
| 778 | # Error si no se reciben menos de 2 parámetros. |
---|
| 779 | [ $# -lt 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 780 | # Error si el fichero de imagen no es accesible. |
---|
| 781 | IMGFILE=$(ogGetPath "$1" "$2.img") || return $? |
---|
| 782 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 783 | |
---|
| 784 | # Devuelve el tamaño de la imagen en KB. |
---|
| 785 | #partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 786 | # awk '/Partition size/ {sub(/\.\.+/," "); printf "%d\n",$3*1024*1024;}' |
---|
| 787 | ogGetImageInfo $IMGFILE | awk -F: '{print $4}' |
---|
| 788 | } |
---|
| 789 | |
---|
| 790 | |
---|
[b094c59] | 791 | #/** |
---|
[0fbc05e] | 792 | # ogGetImageFs str_repo path_image |
---|
| 793 | #@brief Devuelve el tipo de sistema de archivos almacenado en un fichero de imagen. |
---|
| 794 | #@param str_repo repositorio de imágenes o caché local |
---|
| 795 | #@param path_image camino de la imagen |
---|
| 796 | #@return str_imgtype - mnemónico del tipo de sistema de archivos |
---|
| 797 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 798 | #@exception OG_ERR_NOTFOUND fichero de imagen no encontrado. |
---|
| 799 | #@todo Comprobar salidas para todos los tipos de sistemas de archivos. |
---|
| 800 | #/** |
---|
[914d834] | 801 | function ogGetImageFsUS () |
---|
[0fbc05e] | 802 | { |
---|
| 803 | local IMGFILE IMGTYPE |
---|
| 804 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 805 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") || return $? |
---|
| 806 | [ -r "$IMGFILE" ] || ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" || return $? |
---|
| 807 | case "$IMGTYPE" in |
---|
| 808 | img) # Partimage. |
---|
| 809 | partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 810 | awk '/^Filesystem/ {sub(/\.\.+/," "); if ($2=="ntfs") print NTFS; |
---|
| 811 | else { sub(/fs$/,""); print toupper($2);} }' |
---|
| 812 | ;; |
---|
| 813 | pgz) # Partclone / GZip |
---|
| 814 | gzip -dc "$IMGFILE" | partclone.chkimg -C -s - 2>&1 | \ |
---|
| 815 | awk '/^File system/ {if ($2=="EXTFS") print "EXT3"; else print $3;}' |
---|
| 816 | ;; |
---|
| 817 | *) # Error si el fichero de imagen no es accesible. |
---|
| 818 | ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" |
---|
| 819 | return $? ;; |
---|
| 820 | esac |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | |
---|
[39277f4] | 824 | # ogGetImageSize str_repo path_image |
---|
[b094c59] | 825 | #@brief Devuelve el tamaño del sistema de archivos almacenado en un fichero de imagen. |
---|
[42669ebf] | 826 | #@param str_repo repositorio de imágenes o caché local |
---|
| 827 | #@param path_image camino de la imagen |
---|
[0fbc05e] | 828 | #@return int_size - tamaño (en KB) |
---|
[b094c59] | 829 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 830 | #@exception OG_ERR_NOTFOUND fichero de imagen no encontrado. |
---|
| 831 | #*/ |
---|
| 832 | #@warning En pruebas iniciales |
---|
| 833 | #@todo Definición de parámetros y salidas. |
---|
| 834 | #@version 0.1 - Primera versión muy en pruebas para OpenGNSys |
---|
| 835 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 836 | #@date 2009/09/11 |
---|
[1e7eaab] | 837 | #*/ ## |
---|
[914d834] | 838 | function ogGetImageSizeUS () |
---|
[42669ebf] | 839 | { |
---|
[b094c59] | 840 | # Variables locales |
---|
[0fbc05e] | 841 | local IMGFILE IMGTYPE |
---|
[b094c59] | 842 | |
---|
[42669ebf] | 843 | # Si se solicita, mostrar ayuda. |
---|
[b094c59] | 844 | if [ "$*" == "help" ]; then |
---|
| 845 | ogHelp "$FUNCNAME" "$FUNCNAME path_dir str_image int_ndisk int_npart" \ |
---|
[3543b3e] | 846 | "$FUNCNAME 1 1 REPO /aula1/winxp ==> 5642158" |
---|
[b094c59] | 847 | return |
---|
| 848 | fi |
---|
[42669ebf] | 849 | # Error si no se reciben menos de 2 parámetros. |
---|
[0fbc05e] | 850 | [ $# -ne 2 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[42669ebf] | 851 | # Devuelve el tamaño de la imagen en KB. |
---|
[0fbc05e] | 852 | IMGTYPE=$(ogGetImageType "$1" "$2") |
---|
| 853 | IMGFILE=$(ogGetPath "$1" "$2.$IMGTYPE") |
---|
| 854 | case "$IMGTYPE" in |
---|
| 855 | img) # Partimage. |
---|
| 856 | partimage -B gui=no imginfo "$IMGFILE" 2>&1 | \ |
---|
| 857 | awk '/Partition size/ {sub(/\.\.+/," "); ps=$3} END {print ps*1024*1024;}' |
---|
| 858 | ;; |
---|
| 859 | pgz) # Partclone / GZip |
---|
| 860 | gzip -dc "$IMGFILE" | partclone.chkimg -C -s - 2>&1 | \ |
---|
| 861 | awk -F: '/Block size/ {bs=$2} /Used block/ {ub=$2} END {print bs*ub/1024}' |
---|
| 862 | ;; |
---|
| 863 | *) # Error si el fichero de imagen no es accesible. |
---|
| 864 | ogRaiseError OG_ERR_NOTFOUND "$IMGFILE" |
---|
| 865 | return $? ;; |
---|
| 866 | esac |
---|
[b094c59] | 867 | } |
---|
| 868 | |
---|