source: client/shared/scripts/initCache

qndtest
Last change on this file was f097c21, checked in by Irina Gómez <irinagomez@…>, 5 years ago

Fix initCache: if the size of the cache changes, it always formats the cache. ogCheckFs includes the CACHE file system type

  • Property mode set to 100755
File size: 3.8 KB
Line 
1#!/bin/bash
2# Scirpt de iniciación de la caché local de disco.
3# Nota: se usa como base para el programa de configuración de equipos de OpenGnsys Admin).
4# Formato: initCache [int_ndisk [int_npart]] {-1 | 0 | int_size} [NOMOUNT]
5# Versión: 0.9.1, 2009/03/17, - Ramón Gómez, Univ. Sevilla - Versión inicial.
6# Versión: 0.9.2, 2010/07/27, - Ramón Gómez, Univ. Sevilla - redefinir parámetro.
7# 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
8# Version: 1.1.0, 2016/06/16, - Ramón Gómez, Univ. Sevilla - Nuevos parámetros: partición de caché (por defecto, 4) y cadena opcional "NOMOUNT" para dejar la caché sin montar.
9
10TIME1=$SECONDS
11PROG="$(basename $0)"
12EXECFORMAT="$PROG [int_ndisk [int_npart]] {-1 | 0 | int_size} [NOMOUNT]"
13
14# Si el último parámetro es la cadena "NOMOUNT", marcar para no montar y descartarlo.
15if [[ "${*^^}" =~ \ NOMOUNT$ ]]; then
16    MOUNT=0
17    PARAMS=$[$#-1]
18else
19    MOUNT=1
20    PARAMS=$#
21fi
22# Tomar valores según el número de parámetros restantes.
23case $PARAMS in
24    1)  # Por defecto, disco 1 partición 4.
25        NDISK=1
26        NPART=4
27        SIZE=$1
28        ;;
29    2)  # Elegir disco y partición 4 por defecto.
30        NDISK=$1
31        NPART=4
32        SIZE=$2
33        ;;
34    3)  # Elegir disco y partición.
35        NDISK=$1
36        NPART=$2
37        SIZE=$3
38        ;;
39    *)  # Error de formato.
40        ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $EXECFORMAT"
41        exit $?
42        ;;
43esac
44
45# Si disco o partición no son mayores o iguales que 1, error.
46if [ -n "${NDISK//[-0-9]/}${NPART//[-0-9]/}" ] || [ $NDISK -lt 1 ] || [ $NPART -lt 1 ] ; then
47    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $EXECFORMAT"
48    exit $?
49fi
50# Si tamaño no es numérico o tamaño<-1, error.
51if [ -n "${SIZE//[-0-9]/}" ] || [ $SIZE -lt -1 ]; then
52    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $EXECFORMAT"
53    exit $?
54fi
55# Si tamaño=0, no hacer nada.
56if [ $SIZE -eq 0 ]; then
57    echo "No modificar la caché local."
58    exit
59fi
60# Si tamaño=-1, borrar caché.
61if [ $SIZE -eq -1 ]; then
62    echo "[10] Trabajar sin caché local."
63    ogUnmountCache 2>/dev/null
64    ogDeleteCache
65else
66    # Si la caché actual está definida en otro disco y partición, se elimina.
67    if [ -n "$(ogFindCache)" -a "$NDISK $NPART" != "$(ogFindCache)" ]; then
68        echo "[10] Detectada otra caché, eliminarla"
69        ogUnmountCache 2>/dev/null
70        ogDeleteCache
71    fi
72    # Tomamos el tamaño actual. Si no existe cache será 0.
73    OLDSIZE=$(ogGetCacheSize 2>/dev/null) || OLDSIZE=0
74
75    # Error si tamaño definido no es >0.
76    if [ ! $SIZE -gt 0 ]; then
77        ogRaiseError $OG_ERR_FORMAT "$MSG_ERR_FORMAT: !($SIZE>0)"
78        exit $?
79    fi
80    # Si no existe caché o si cambia su tamaño, crearla.
81    CACHESIZE=$(ogGetCacheSize 2>/dev/null)
82    if [ "$SIZE" != "$CACHESIZE" ]; then
83        echo "[10] Crar partición de caché local."
84        ogUnmountCache 2>/dev/null
85        ogCreateCache $NDISK $NPART $SIZE
86        ogUpdatePartitionTable $NDISK
87    fi
88    # Si caché no montada y no formateada o cambia el tamaño: formatear.
89    CACHE=$(ogFindCache) || exit $?
90    if ! ogIsFormated $CACHE || [ $SIZE -ne $OLDSIZE ]; then
91        echo "[50] Formatear caché local."
92        ogFormatCache
93    fi
94    echo "[70] Comprobar montaje de caché local."
95    ogMountCache 2>/dev/null
96    # Si error al montar, chequear sistema de archivos y volver a montar.
97    if [ $? != 0 ]; then
98        echo "[80] Comprobar consistencia y volver a montar caché local."
99        ogCheckFs $CACHE
100        ogMountCache || exit $?
101    fi
102    # Dejar desmontada la caché si se ha solicitado.
103    if [ $MOUNT == 0 ]; then
104        echo "[90] Dejar desmontada la caché local."
105        ogUnmountCache 2>/dev/null
106    fi
107fi
108# Duración del proceso.
109TIME=$[SECONDS-TIME1]
110echo "[100] Duración de la operación $[TIME/60]m $[TIME%60]s"
111
Note: See TracBrowser for help on using the repository browser.