source: client/shared/scripts/initCache @ c21abbc

Last change on this file since c21abbc was de687e3, checked in by ramon <ramongomez@…>, 10 years ago

#673: Integrar código de la versión 1.0.6 en rama principal.

git-svn-id: https://opengnsys.es/svn/trunk@4641 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 2.8 KB
RevLine 
[e6c0037]1#!/bin/bash
2# Scirpt de iniciación de la caché local de disco.
3# (puede usarse como base para el programa de restauración de imágenes usado por OpenGnSys Admin).
[8abcdfe]4# Versión: 0.9.1, 2009/03/17, - Ramón Gómez, Univ. Sevilla - Versión inicial.
5# Versión: 0.9.2, 2010/07/27, - Ramón Gómez, Univ. Sevilla - redefinir parámetro.
[1602040]6# Version: 1.0.5, 2012/09/18, - Univ. Huelva - Nuevo parametro para indicar el disco donde se creara la CACHE, si no se indica, se usa 1
[e6c0037]7
8TIME1=$SECONDS
9PROG="$(basename $0)"
[1602040]10# Si el numero de parametros es 1, es el tamano de la CACHE
11if [ $# == 1 ]
12then
13        NDISK=1
14        SIZE=$1
15elif [ $# == 2 ]
16then
17        NDISK=$1
18        SIZE=$2
19else
20    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG [int_ndisk] -1 | 0 | size"
21    exit $?
22fi
23
24# Si disco no es mayor o igual que 1, error.
25if [ -n "${NDISK//[-0-9]/}" ] || [ $NDISK -lt 1 ]; then
26    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG [int_ndisk] -1 | 0 | size"
[e6c0037]27    exit $?
28fi
29
[8abcdfe]30# Si tamaño no es numérico o tamaño<-1, error.
[1602040]31if [ -n "${SIZE//[-0-9]/}" ] || [ $SIZE -lt -1 ]; then
32    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $PROG int_ndisk [-1 | 0 | size]"
[8abcdfe]33    exit $?
34fi
35# Si tamaño=0, no hacer nada.
[1602040]36if [ $SIZE -eq 0 ]; then
[8abcdfe]37    echo "No modificar la caché local."
38    exit
39fi
40# Si tamaño=-1, borrar caché.
[1602040]41if [ $SIZE -eq -1 ]; then
[e6c0037]42    echo "[10] Trabajar sin caché local."
43    ogUnmountCache 2>/dev/null
44    ogDeleteCache
45else
[1602040]46    # Comprobar disco y particion donde se aloja la cache actualmente, si la hay
47    FINDCACHE=`ogFindCache`
48    echo "[5] ogFindCache: "$FINDCACHE
49    CACHEDISK=${FINDCACHE% *}
50    PART=${FINDCACHE#* }
51
52    # Si la CACHE actual esta definida en otro disco, se elimina
[de687e3]53    if [ -n "$CACHEDISK" -a "$NDISK" != "$CACHEDISK" ]
[1602040]54    then
55        echo "[10] Detectada cache en otro disco, eliminarla"
56        ogUnmountCache 2>/dev/null
57        ogDeleteCache
58    fi
59
[8abcdfe]60    # Si tamaño>0, ...
[1602040]61    if [ ! $SIZE -gt 0 ]; then
62        ogRaiseError $OG_ERR_FORMAT "$MSG_ERR_FORMAT: !($SIZE>0)"
[8abcdfe]63        exit $?
64    fi
[e6c0037]65    # Si no existe caché o si cambia su tamaño, crearla.
[1602040]66    CACHESIZE=$(ogGetCacheSize 2>/dev/null)
67    if [ "$SIZE" != "$CACHESIZE" ]; then
[e6c0037]68        echo "[10] Crar partición de caché local."
69        ogUnmountCache 2>/dev/null
[1602040]70        ogCreateCache $NDISK "$SIZE"
[e6c0037]71    fi
72    # Si caché no montada y no formateada, formatear.
[e1c4317]73    CACHE=$(ogFindCache) || exit $?
[5a4f399]74    if ! ogIsFormated $CACHE; then
[e6c0037]75        echo "[50] Formatear caché local."
76        ogFormatCache
77    fi
78    echo "[70] Montar caché local."
[e1c4317]79    ogMountCache 2>/dev/null
[e6c0037]80    # Si error al montar, chequear sistema de archivos y volver a montar.
81    if [ $? != 0 ]; then
82        echo "[80] Comprobar y montar caché local."
83        ogCheckFs $CACHE
[e1c4317]84        ogMountCache || exit $?
[e6c0037]85    fi
86fi
87# Duración del proceso.
88TIME=$[SECONDS-TIME1]
89echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s"
90
Note: See TracBrowser for help on using the repository browser.