[4c63eb9] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file File.lib |
---|
| 4 | #@brief Librería o clase File |
---|
| 5 | #@class File |
---|
| 6 | #@brief Funciones para gestión de archivos y directorios. |
---|
[9eefff4] | 7 | #@version 0.9.2 |
---|
[4c63eb9] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
| 11 | |
---|
[55ad138c] | 12 | #/** |
---|
[95e48e1] | 13 | # ogCalculateChecksum [ str_repo | int_ndisk int_npart ] path_filepath |
---|
| 14 | #@brief Devuelve la suma de comprobación (checksum) de un fichero. |
---|
| 15 | #@param path_filepath camino del fichero (independiente de mayúsculas) |
---|
| 16 | #@param str_repo repositorio de ficheros |
---|
| 17 | #@param int_ndisk nº de orden del disco |
---|
| 18 | #@param int_npartition nº de orden de la partición |
---|
| 19 | #@return hex_checksum Checksum del fichero |
---|
| 20 | #@version 0.9.2 - Primera versión para OpenGnSys. |
---|
| 21 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 22 | #@date 2010-07-24 |
---|
[12e8e382] | 23 | #@version 1.0.4 - Calcula solo el checksum del último MB del fichero. |
---|
| 24 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 25 | #@date 2012-03-16 |
---|
[95e48e1] | 26 | #*/ ## |
---|
| 27 | function ogCalculateChecksum () |
---|
| 28 | { |
---|
| 29 | # Variables locales. |
---|
| 30 | local FILE |
---|
| 31 | if [ "$*" == "help" ]; then |
---|
| 32 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath" \ |
---|
[cbbb046] | 33 | "$FUNCNAME REPO ubuntu.img ==> ef899299caf8b517ce36f1157a93d8bf" |
---|
[95e48e1] | 34 | return |
---|
| 35 | fi |
---|
| 36 | |
---|
| 37 | # Comprobar que existe el fichero y devolver sus datos. |
---|
| 38 | FILE=$(ogGetPath "$@") |
---|
| 39 | [ -n "$FILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
[12e8e382] | 40 | tail -c1M "$FILE" | md5sum -b 2>&1 | cut -f1 -d" " |
---|
[95e48e1] | 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | #/** |
---|
| 45 | # ogCompareChecksumFiles [ str_repo | int_ndisk int_npart ] path_source [ str_repo | int_ndisk int_npart ] path_target |
---|
| 46 | #@brief Metafunción que compara las sumas de comprobación almacenadas de 2 ficheros. |
---|
| 47 | #@return bool_compare Valor de comparación. |
---|
| 48 | #@warning No es necesario especificar la extensión ".sum". |
---|
| 49 | #@version 0.9.2 - Primera versión para OpenGnSys. |
---|
| 50 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 51 | #@date 2010-07-24 |
---|
| 52 | #*/ ## |
---|
| 53 | function ogCompareChecksumFiles () |
---|
| 54 | { |
---|
| 55 | # Variables locales. |
---|
| 56 | local ARGS SOURCE TARGET |
---|
| 57 | if [ "$*" == "help" ]; then |
---|
| 58 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath" \ |
---|
[cbbb046] | 59 | "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ...; fi" |
---|
[95e48e1] | 60 | return |
---|
| 61 | fi |
---|
| 62 | |
---|
| 63 | ARGS="$@" |
---|
| 64 | case "$1" in |
---|
| 65 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
| 66 | SOURCE=$(ogGetPath "$1") |
---|
| 67 | shift ;; |
---|
| 68 | [1-9]*) # ndisco npartición. |
---|
| 69 | SOURCE=$(ogGetPath "$1" "$2" "$3") |
---|
| 70 | shift 3 ;; |
---|
| 71 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
| 72 | SOURCE=$(ogGetPath "$1" "$2") |
---|
| 73 | shift 2 ;; |
---|
| 74 | esac |
---|
| 75 | TARGET=$(ogGetPath "$@") |
---|
| 76 | |
---|
| 77 | # Comparar los ficheros de checksum. |
---|
| 78 | test "$(cat "$SOURCE.sum" 2>/dev/null)" == "$(cat "$TARGET.sum" 2>/dev/null)" |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | #/** |
---|
[e42f34e] | 83 | # ogCopyFile [ str_repo | int_ndisk int_npart ] path_source [ str_repo | int_ndisk int_npart ] path_target |
---|
[9eefff4] | 84 | #@brief Metafunción para copiar un fichero de sistema OpenGnSys a un directorio. |
---|
[55ad138c] | 85 | #@see ogGetPath |
---|
| 86 | #@warning Deben existir tanto el fichero origen como el directorio destino. |
---|
[9eefff4] | 87 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[55ad138c] | 88 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 89 | #@date 2009-10-20 |
---|
[1e7eaab] | 90 | #*/ ## |
---|
[42669ebf] | 91 | function ogCopyFile () |
---|
| 92 | { |
---|
[55ad138c] | 93 | # Variables locales. |
---|
[e42f34e] | 94 | local ARGS SOURCE TARGET |
---|
[cbbb046] | 95 | if [ "$*" == "help" ]; then |
---|
| 96 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target" \ |
---|
| 97 | "$FUNCNAME REPO newfile.txt 1 2 /tmp/newfile.txt" |
---|
| 98 | return |
---|
| 99 | fi |
---|
[55ad138c] | 100 | |
---|
[e42f34e] | 101 | ARGS="$@" |
---|
[c40a6b4] | 102 | case "$1" in |
---|
[1e7eaab] | 103 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
[3915005] | 104 | SOURCE="$(ogGetPath "$1")" |
---|
[e42f34e] | 105 | shift ;; |
---|
| 106 | [1-9]*) # ndisco npartición. |
---|
[3915005] | 107 | SOURCE="$(ogGetPath "$1" "$2" "$3")" |
---|
[e42f34e] | 108 | shift 3 ;; |
---|
| 109 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[3915005] | 110 | SOURCE="$(ogGetPath "$1" "$2")" |
---|
[e42f34e] | 111 | shift 2 ;; |
---|
[c40a6b4] | 112 | esac |
---|
[1e7eaab] | 113 | # Comprobar fichero origen y directorio destino. |
---|
[e42f34e] | 114 | [ -n "$SOURCE" ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $? |
---|
[3915005] | 115 | TARGET="$(ogGetPath "$@")" |
---|
[e42f34e] | 116 | [ -n "$TARGET" ] || ogRaiseError $OG_ERR_NOTFOUND "$@" || return $? |
---|
[1e7eaab] | 117 | # Copiar fichero. |
---|
[01a9904] | 118 | cp -a "$SOURCE" "$TARGET" # (definir posible error) |
---|
[c40a6b4] | 119 | } |
---|
| 120 | |
---|
| 121 | |
---|
[4c63eb9] | 122 | #/** |
---|
[c7d9af7] | 123 | # ogDeleteFile [ str_repo | int_ndisk int_npartition ] path_filepath |
---|
| 124 | #@brief Metafunción que borra un fichero de un dispositivo. |
---|
| 125 | #@see ogGetPath |
---|
[9eefff4] | 126 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[c7d9af7] | 127 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 128 | #@date 2009-09-29 |
---|
[1e7eaab] | 129 | #*/ ## |
---|
[42669ebf] | 130 | function ogDeleteFile () |
---|
| 131 | { |
---|
[c7d9af7] | 132 | # Variables locales. |
---|
| 133 | local FILE |
---|
[cbbb046] | 134 | if [ "$*" == "help" ]; then |
---|
| 135 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_file" \ |
---|
| 136 | "$FUNCNAME 1 2 /tmp/newfile.txt" |
---|
| 137 | return |
---|
| 138 | fi |
---|
| 139 | |
---|
[1e7eaab] | 140 | # Comprobar que existe el fichero y borrarlo. |
---|
[3915005] | 141 | FILE="$(ogGetPath "$@")" |
---|
[a3fb8b2] | 142 | [ -n "$FILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
| 143 | rm -f "$FILE" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
[c7d9af7] | 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | #/** |
---|
[3543b3e] | 148 | # ogDeleteTree [ str_repo | int_ndisk int_npartition ] path_dirpath |
---|
| 149 | #@brief Metafunción que borra todo un subárbol de directorios de un dispositivo. |
---|
| 150 | #@see ogGetPath |
---|
[9eefff4] | 151 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[3543b3e] | 152 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 153 | #@date 2009-09-29 |
---|
[1e7eaab] | 154 | #*/ ## |
---|
[42669ebf] | 155 | function ogDeleteTree () |
---|
| 156 | { |
---|
[c7d9af7] | 157 | # Variables locales. |
---|
[3543b3e] | 158 | local DIR |
---|
[cbbb046] | 159 | if [ "$*" == "help" ]; then |
---|
| 160 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir" \ |
---|
| 161 | "$FUNCNAME 1 2 /tmp/newdir" |
---|
| 162 | return |
---|
| 163 | fi |
---|
| 164 | |
---|
[1e7eaab] | 165 | # Comprobar que existe el directorio y borrarlo con su contenido. |
---|
[3915005] | 166 | DIR="$(ogGetPath "$@")" |
---|
[a3fb8b2] | 167 | [ -n "$DIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
| 168 | rm -fr "$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
[3543b3e] | 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | #/** |
---|
[1d531f9] | 173 | # ogGetPath [ str_repo | int_ndisk int_npartition ] path_filepath |
---|
[4c63eb9] | 174 | #@brief Inicia el proceso de arranque de un sistema de archivos. |
---|
[42669ebf] | 175 | #@param path_filepath camino del fichero (independiente de mayúsculas) |
---|
| 176 | #@param str_repo repositorio de ficheros |
---|
| 177 | #@param int_ndisk nº de orden del disco |
---|
| 178 | #@param int_npartition nº de orden de la partición |
---|
[4c63eb9] | 179 | #@return path_file - camino completo real del fichero. |
---|
[55ad138c] | 180 | #@note repo = { REPO, CACHE, CDROM } |
---|
[1d531f9] | 181 | #@note Requisitos: \c grep \c sed |
---|
[4c63eb9] | 182 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[ebf06c7] | 183 | #@exception OG_ERR_NOTFOUND Fichero o dispositivo no encontrado. |
---|
[4c63eb9] | 184 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
[cfeabbf] | 185 | #@warning En caso de error, sólo devuelve el código y no da mensajes. |
---|
[4c63eb9] | 186 | #@todo Terminar de definir parámetros para acceso a repositorios. |
---|
[985bef0] | 187 | #@version 0.1 - Integracion para Opengnsys - HIDRA: CaminoWindows.sh; EAC: GetPath(), FormatSintaxSpacePath(), FormatSintaxBackSlashPath (), en FileSystem.lib |
---|
| 188 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 189 | #@Date 2008/10/10 |
---|
| 190 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 191 | #@date 2008/10/27 |
---|
[9eefff4] | 192 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[4c63eb9] | 193 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 194 | #@date 2009-09-15 |
---|
[1e7eaab] | 195 | #*/ ## |
---|
[42669ebf] | 196 | function ogGetPath () |
---|
| 197 | { |
---|
[4c63eb9] | 198 | # Variables locales. |
---|
| 199 | local MNTDIR FILE PREVFILE FILEPATH CURRENTDIR |
---|
| 200 | |
---|
[1e7eaab] | 201 | # Si se solicita, mostrar ayuda. |
---|
[4c63eb9] | 202 | if [ "$*" == "help" ]; then |
---|
[4edc0b0] | 203 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath" \ |
---|
[d071d9b] | 204 | "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS/System32" \ |
---|
| 205 | "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc/fstab" \ |
---|
[4c63eb9] | 206 | "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS/System32" |
---|
| 207 | return |
---|
| 208 | fi |
---|
| 209 | |
---|
[1e7eaab] | 210 | # Procesar camino según el número de parámetros. |
---|
[4c63eb9] | 211 | case $# in |
---|
| 212 | 1) FILE="$1" ;; |
---|
| 213 | 2) case "$1" in |
---|
[ee4a96e] | 214 | REPO|repo) |
---|
[39277f4] | 215 | FILE="$OGIMG/$2" ;; |
---|
[ee4a96e] | 216 | CACHE|cache) |
---|
[4edc0b0] | 217 | FILE="$(ogMountCache)/$OGIMG/$2" ;; |
---|
[ee4a96e] | 218 | CDROM|cdrom) |
---|
[3543b3e] | 219 | FILE="$(ogMountCdrom)/$2" ;; |
---|
[39277f4] | 220 | *) ogRaiseError $OG_ERR_FORMAT |
---|
| 221 | return $? ;; |
---|
[a2336d6] | 222 | esac ;; |
---|
[ebf06c7] | 223 | 3) FILE="$(ogMount $1 $2)/$3" ;; |
---|
| 224 | *) ogRaiseError $OG_ERR_FORMAT |
---|
[c40a6b4] | 225 | return $? ;; |
---|
[4c63eb9] | 226 | esac |
---|
| 227 | |
---|
[1e7eaab] | 228 | # Eliminar caracteres \c / iniciales, finales y duplicados. |
---|
[4c63eb9] | 229 | CURRENTDIR="$PWD" |
---|
[1e7eaab] | 230 | # /* (comentario Doxygen) |
---|
[4c63eb9] | 231 | FILE="$(echo $FILE|sed -e 's/\(\/\)*\1/\//g' -e 's/^\///' -e 's/\/$//')" |
---|
| 232 | PREVFILE="" |
---|
| 233 | FILEPATH="/" |
---|
| 234 | while [ "$FILE" != "$PREVFILE" ]; do |
---|
[1e7eaab] | 235 | # Busca el nombre correcto en el directorio actual. |
---|
[4c63eb9] | 236 | cd "$FILEPATH" |
---|
[1e7eaab] | 237 | FILEPATH="${FILEPATH}/$(ls -A | grep -i -m1 "^${FILE%%/*}$")" || return $? |
---|
[4c63eb9] | 238 | PREVFILE="$FILE" |
---|
| 239 | FILE="${FILE#*/}" |
---|
| 240 | done |
---|
[1e7eaab] | 241 | # (comentario Doxygen) */ |
---|
| 242 | # Muestra el camino Linux, quitando el / inicial duplicado. |
---|
[4c63eb9] | 243 | [ "$FILEPATH" != "/" ] && echo ${FILEPATH#/} |
---|
| 244 | cd $CURRENTDIR |
---|
| 245 | } |
---|
| 246 | |
---|
[a2336d6] | 247 | |
---|
[23c6c40] | 248 | #/** |
---|
| 249 | # ogGetParentPath [ str_repo | int_ndisk int_npartition ] path_filepath |
---|
| 250 | #@brief Metafunción que devuelve el camino del directorio padre. |
---|
| 251 | #@see ogGetPath |
---|
[9eefff4] | 252 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[23c6c40] | 253 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 254 | #@date 2009-09-29 |
---|
[1e7eaab] | 255 | #*/ ## |
---|
[42669ebf] | 256 | function ogGetParentPath () |
---|
| 257 | { |
---|
[ebf06c7] | 258 | local PARENT |
---|
[4edc0b0] | 259 | if [ "$*" == "help" ]; then |
---|
| 260 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath" \ |
---|
| 261 | "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS" \ |
---|
| 262 | "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc" \ |
---|
| 263 | "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS" |
---|
| 264 | return |
---|
| 265 | fi |
---|
| 266 | |
---|
[ebf06c7] | 267 | case $# in |
---|
[3915005] | 268 | 1) PARENT="$(dirname "$1")" ;; |
---|
[a3fb8b2] | 269 | 2) PARENT="$1 $(dirname "/$2")" ;; |
---|
| 270 | 3) PARENT="$1 $2 $(dirname "/$3")" ;; |
---|
[ebf06c7] | 271 | *) ogRaiseError $OG_ERR_FORMAT |
---|
[cfeabbf] | 272 | return $? ;; |
---|
[ebf06c7] | 273 | esac |
---|
[f81a4deb] | 274 | ogGetPath $PARENT |
---|
[ebf06c7] | 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
[23c6c40] | 278 | #/** |
---|
[9eefff4] | 279 | # ogIsNewerFile [ str_repo | int_ndisk int_npart ] path_source [ str_repo | int_ndisk int_npart ] path_target |
---|
| 280 | #@brief Metafunción que indica se un fichero es más nuevo que otro. |
---|
| 281 | #@see ogGetPath |
---|
[7685100] | 282 | #@return Código de salida: 0 - nuevo, 1 - antiguo o error |
---|
[9eefff4] | 283 | #@warning Deben existir tanto el fichero origen como el destino. |
---|
| 284 | #@version 0.9.2 - Primera versión para OpenGnSys. |
---|
| 285 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 286 | #@date 2010-07-24 |
---|
[7685100] | 287 | #@version 1.0.1 - Devolver falso en caso de error. |
---|
| 288 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 289 | #@date 2011-05-18 |
---|
[9eefff4] | 290 | #*/ ## |
---|
| 291 | function ogIsNewerFile () |
---|
| 292 | { |
---|
| 293 | # Variables locales. |
---|
| 294 | local ARGS SOURCE TARGET |
---|
| 295 | # Si se solicita, mostrar ayuda. |
---|
| 296 | if [ "$*" == "help" ]; then |
---|
| 297 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target" \ |
---|
| 298 | "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ... fi" |
---|
| 299 | return |
---|
| 300 | fi |
---|
| 301 | |
---|
| 302 | ARGS="$@" |
---|
| 303 | case "$1" in |
---|
| 304 | /*) # Camino completo. */ (Comentrio Doxygen) |
---|
[3915005] | 305 | SOURCE="$(ogGetPath "$1")" |
---|
[9eefff4] | 306 | shift ;; |
---|
| 307 | [1-9]*) # ndisco npartición. |
---|
[3915005] | 308 | SOURCE="$(ogGetPath "$1" "$2" "$3")" |
---|
[9eefff4] | 309 | shift 3 ;; |
---|
| 310 | *) # Otros: repo, cache, cdrom (no se permiten caminos relativos). |
---|
[3915005] | 311 | SOURCE="$(ogGetPath "$1" "$2")" |
---|
[9eefff4] | 312 | shift 2 ;; |
---|
| 313 | esac |
---|
| 314 | # Comprobar que existen los ficheros origen y destino. |
---|
[7685100] | 315 | [ -n "$SOURCE" ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return 1 |
---|
[9eefff4] | 316 | TARGET=$(ogGetPath "$@") |
---|
[7685100] | 317 | [ -n "$TARGET" ] || ogRaiseError $OG_ERR_NOTFOUND "$@" || return 1 |
---|
[9eefff4] | 318 | # Devolver si el primer fichero se ha modificado después que el segundo. |
---|
| 319 | test "$SOURCE" -nt "$TARGET" |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | #/** |
---|
[95e48e1] | 324 | # ogMakeChecksumFile [ str_repo | int_ndisk int_npart ] path_filepath |
---|
| 325 | #@brief Metafunción que guarda el valor de comprobación de un fichero. |
---|
| 326 | #@see ogCalculateChecksum |
---|
| 327 | #@warning Genera un fichero con extensión ".sum". |
---|
| 328 | #@version 0.9.2 - Primera versión para OpenGnSys. |
---|
| 329 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 330 | #@date 2010-07-24 |
---|
| 331 | #*/ ## |
---|
| 332 | function ogMakeChecksumFile () |
---|
| 333 | { |
---|
| 334 | # Variables locales. |
---|
[3915005] | 335 | local FILE |
---|
[95e48e1] | 336 | if [ "$*" == "help" ]; then |
---|
| 337 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath" \ |
---|
| 338 | "$FUNCNAME REPO ubuntu.img" |
---|
| 339 | return |
---|
| 340 | fi |
---|
| 341 | |
---|
| 342 | # Comprobar que existe el fichero y guardar su checksum. |
---|
[3915005] | 343 | FILE="$(ogGetPath "$@")" |
---|
[95e48e1] | 344 | [ -n "$FILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
| 345 | ogCalculateChecksum "$FILE" > "$FILE.sum" |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | #/** |
---|
[23c6c40] | 350 | # ogMakeDir [ str_repo | int_ndisk int_npartition ] path_dirpath |
---|
| 351 | #@brief Metafunción que crea un subdirectorio vacío en un dispositivo. |
---|
| 352 | #@see ogGetParentPath |
---|
[985bef0] | 353 | #@version 0.1 - Integracion para Opengnsys - HIDRA: CrearDirectorio.sh, EAC: MkdirPath() en FileSystem.lib |
---|
| 354 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 355 | #@Date 2008/10/10 |
---|
| 356 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 357 | #@date 2008/10/27 |
---|
[9eefff4] | 358 | #@version 0.9 - Pruebas con OpenGnSys. |
---|
[23c6c40] | 359 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 360 | #@date 2009-09-29 |
---|
[1e7eaab] | 361 | #*/ ## |
---|
[42669ebf] | 362 | function ogMakeDir () |
---|
| 363 | { |
---|
[ebf06c7] | 364 | local PARENT DIR |
---|
[cbbb046] | 365 | if [ "$*" == "help" ]; then |
---|
| 366 | ogHelp "$FUNCNAME" "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir" \ |
---|
| 367 | "$FUNCNAME 1 2 /tmp/newdir" |
---|
| 368 | return |
---|
| 369 | fi |
---|
| 370 | |
---|
[3915005] | 371 | PARENT="$(ogGetParentPath "$@")" || return $? |
---|
[23c6c40] | 372 | DIR="$(basename "${!#}")" |
---|
[a3fb8b2] | 373 | mkdir -p "$PARENT/$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $? |
---|
[ebf06c7] | 374 | } |
---|
| 375 | |
---|
[a2336d6] | 376 | |
---|
| 377 | #/** |
---|
| 378 | # ogNewPath [ str_repo | int_ndisk int_npartition ] path_filepath |
---|
| 379 | #@brief Crea el directorio especificado |
---|
[42669ebf] | 380 | #@param path_filepath camino del fichero (independiente de mayúsculas) |
---|
| 381 | #@param str_repo repositorio de ficheros |
---|
| 382 | #@param int_ndisk nº de orden del disco |
---|
| 383 | #@param int_npartition nº de orden de la partición |
---|
[a2336d6] | 384 | #@return file - camino completo real del directorio creado |
---|
| 385 | #@note repo = { REPO, CACHE } |
---|
| 386 | #@note Requisitos: \c grep \c sed |
---|
| 387 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 388 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 389 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 390 | #@warning Primeras pruebas. |
---|
| 391 | #@todo Terminar de definir parámetros para acceso a repositorios. |
---|
[9eefff4] | 392 | #@version 0.1 - Primera adaptaci³n para OpenGNSys. |
---|
[a2336d6] | 393 | #@author obtenido de ogGetPath de Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 394 | #@date 2009-09-15 |
---|
| 395 | #*/ |
---|
[42669ebf] | 396 | function ogNewPath () |
---|
| 397 | { |
---|
[a2336d6] | 398 | # Variables locales. |
---|
| 399 | local MNTDIR FILE PREVFILE FILEPATH CURRENTDIR |
---|
| 400 | |
---|
| 401 | #/// Si se solicita, mostrar ayuda. |
---|
| 402 | if [ "$*" == "help" ]; then |
---|
| 403 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 404 | "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS/System32" \ |
---|
| 405 | "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc/fstab" \ |
---|
| 406 | "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS/System32" |
---|
| 407 | return |
---|
| 408 | fi |
---|
| 409 | |
---|
| 410 | #/// Procesar camino según el número de parámetros. |
---|
| 411 | case $# in |
---|
| 412 | # si 1 parametro directorio-fichero completo. |
---|
| 413 | 1) FILE="$1" ;; |
---|
| 414 | # Si 2 parametros es REPOSITORIO DIRECTORIO-FICHERO |
---|
| 415 | 2) case "$1" in |
---|
| 416 | # consultando servidor repositorio base |
---|
| 417 | REPO | $IPREPOMAN ) FILE="$OGIMG/$2" || return $OG_ERR_NOTFOUND ;; |
---|
| 418 | # consultando particion auxiliar cache local |
---|
| 419 | CACHE | $IP ) |
---|
| 420 | ogMountCache >> /dev/null && FILE="$OGCAC/$OGIMG/$2" || return $OG_ERR_NOTFOUND ;; |
---|
| 421 | # conectando con Servidor Axuliar. |
---|
| 422 | *) ogRaiseError $OG_ERR_FORMAT |
---|
| 423 | return $? ;; |
---|
| 424 | esac ;; |
---|
| 425 | # Si 3 parametros DISK PARTITION DIRECTORIO-FICHERO |
---|
| 426 | 3) FILE="$(ogMount $1 $2)/$3" || return $OG_ERR_NOTFOUND ;; |
---|
| 427 | *) return $OG_ERR_FORMAT ;; |
---|
| 428 | esac |
---|
| 429 | |
---|
| 430 | mkdir -p ${FILE} |
---|
| 431 | echo $FILE |
---|
| 432 | } |
---|
| 433 | |
---|