source: client/engine/File.lib @ 8964f9b

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 8964f9b was 8964f9b, checked in by ramon <ramongomez@…>, 16 years ago

Resstructuración de trunk.

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

  • Property mode set to 100755
File size: 7.3 KB
Line 
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.
7#@version 0.9
8#@warning License: GNU GPLv3+
9#*/
10
11
12##### PRUEBAS
13#         ogGetPath [ str_repo | int_ndisk int_npart ] path_source [ str_repo | int_ndisk int_npart ] path_target
14function ogCopyFile () {
15local SOURCE TARGET
16case "$1" in
17    /*)     SOURCE=$(ogGetFile "$1")      # */ (necesario Doxygen)
18            shift ;;
19    [1-9]*) SOURCE=$(ogGetFile "$1" "$2" "$3")
20            shift 3 ;;
21    *)      SOURCE=$(ogGetFile "$1" "$2")
22            shift 2 ;;
23esac
24
25}
26
27
28#/**
29#         ogGetPath [ str_repo | int_ndisk int_npartition ] path_filepath
30#@brief   Inicia el proceso de arranque de un sistema de archivos.
31#@arg  \c filepath   camino del fichero (independiente de mayúsculas)
32#@arg  \c repo       repositorio de ficheros
33#@arg  \c ndisk      nº de orden del disco
34#@arg  \c npartition nº de orden de la partición
35#@return  path_file - camino completo real del fichero.
36#@note    repo = { REPO, CACHE | CDROM }
37#@note    Requisitos: \c grep \c sed
38#@exception OG_ERR_FORMAT    Formato incorrecto.
39#@exception OG_ERR_NOTFOUND  Fichero o dispositivo no encontrado.
40#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
41#@warning En caso de error, sólo devuelve el código y no da mensajes.
42#@todo    Terminar de definir parámetros para acceso a repositorios.
43#@version 0.9 - Pruebas con OpenGNSys.
44#@author  Ramon Gomez, ETSII Universidad de Sevilla
45#@date    2009-09-15
46#*/
47function ogGetPath () {
48
49# Variables locales.
50local MNTDIR FILE PREVFILE FILEPATH CURRENTDIR
51
52#/// Si se solicita, mostrar ayuda.
53if [ "$*" == "help" ]; then
54    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
55           "$FUNCNAME \"/mnt/sda1/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32" \
56           "$FUNCNAME REPO /etc/fstab  ==>  /opt/opengnsys/images/etc/fstab" \
57           "$FUNCNAME 1 1 \"/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32"
58    return
59fi
60
61#/// Procesar camino según el número de parámetros.
62case $# in
63    1)  FILE="$1" ;;
64    2)  case "$1" in
65            REPO|repo)
66                FILE="$OGIMG/$2" ;;
67            CACHE|cache)
68                FILE="$OGCAC/$OGIMG/$2" ;;
69            CDROM|cdrom)
70                FILE="$(ogMount cdrom)/$2" ;;
71            *)  ogRaiseError $OG_ERR_FORMAT
72                return $? ;;
73        esac ;;
74    3)  FILE="$(ogMount $1 $2)/$3" ;;
75    *)  ogRaiseError $OG_ERR_FORMAT
76        return $? ;;
77esac
78
79#/// Eliminar caracteres \c / iniciales, finales y duplicados.
80CURRENTDIR="$PWD"
81FILE="$(echo $FILE|sed -e 's/\(\/\)*\1/\//g' -e 's/^\///' -e 's/\/$//')"
82PREVFILE=""
83FILEPATH="/"
84while [ "$FILE" != "$PREVFILE" ]; do
85    #/// Busca el nombre correcto en el directorio actual.
86    cd "$FILEPATH"
87    FILEPATH="${FILEPATH}/$(ls -A | grep -i -m1 "^${FILE%%/*}$")" || return $?
88    PREVFILE="$FILE"
89    FILE="${FILE#*/}"
90done
91
92#/// Muestra el camino Linux, quitando el "/" inicial duplicado.
93[ "$FILEPATH" != "/" ] && echo ${FILEPATH#/}
94cd $CURRENTDIR
95}
96
97
98#/**
99#         ogGetParentPath [ str_repo | int_ndisk int_npartition ] path_filepath
100#@brief   Metafunción que devuelve el camino del directorio padre.
101#@see     ogGetPath
102#@version 0.9 - Pruebas con OpenGNSys.
103#@author  Ramon Gomez, ETSII Universidad de Sevilla
104#@date    2009-09-29
105#*/
106function ogGetParentPath () {
107local PARENT
108case $# in
109    1)  PARENT="$(dirname "$1")" ;;
110    2)  PARENT="$1 $(dirname "$2")" ;;
111    3)  PARENT="$1 $2 $(dirname "$3")" ;;
112    *)  ogRaiseError $OG_ERR_FORMAT
113        return $? ;;
114esac
115ogGetPath $PARENT
116}
117
118
119#/**
120#         ogDeleteFile [ str_repo | int_ndisk int_npartition ] path_filepath
121#@brief   Metafunción que borra un fichero de un dispositivo.
122#@see     ogGetPath
123#@version 0.9 - Pruebas con OpenGNSys.
124#@author  Ramon Gomez, ETSII Universidad de Sevilla
125#@date    2009-09-29
126#*/
127function ogDeleteFile () {
128local FILE
129FILE=$(ogGetPath "$@") || return $?
130[ -z "$FILE" ] && ogRaiseError $OG_ERR_NOTFOUND "$*" && reutrn $?
131rm -f "$FILE" || ogRaiseError $OG_ERR_NOTFOUND "$*" || reutrn $?
132}
133
134
135#/**
136#         ogDeleteTree [ str_repo | int_ndisk int_npartition ] path_dirpath
137#@brief   Metafunción que borra todo un subárbol de directorios de un dispositivo.
138#@see     ogGetPath
139#@version 0.9 - Pruebas con OpenGNSys.
140#@author  Ramon Gomez, ETSII Universidad de Sevilla
141#@date    2009-09-29
142#*/
143# Borrar subárbol de directorio.
144function ogDeleteTree () {
145local DIR
146DIR=$(ogGetPath "$@") || return $?
147[ -z "$DIR" ] && ogRaiseError $OG_ERR_NOTFOUND "$*" && reutrn $?
148rm -fr "$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || reutrn $?
149}
150
151
152#/**
153#         ogMakeDir [ str_repo | int_ndisk int_npartition ] path_dirpath
154#@brief   Metafunción que crea un subdirectorio vacío en un dispositivo.
155#@see     ogGetParentPath
156#@version 0.9 - Pruebas con OpenGNSys.
157#@author  Ramon Gomez, ETSII Universidad de Sevilla
158#@date    2009-09-29
159#*/
160function ogMakeDir () {
161local PARENT DIR
162PARENT=$(ogGetParentPath "$@") || return $?
163DIR="$(basename "${!#}")"
164echo mkdir -p "$PARENT/$DIR"
165mkdir -p "$PARENT/$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || reutrn $?
166}
167 
168
169#/**
170#         ogNewPath [ str_repo | int_ndisk int_npartition ] path_filepath
171#@brief   Crea el directorio especificado
172#@arg  \c filepath   camino del fichero (independiente de mayúsculas)
173#@arg  \c repo       repositorio de ficheros
174#@arg  \c ndisk      nº de orden del disco
175#@arg  \c npartition nº de orden de la partición
176#@return  file - camino completo real del directorio creado
177#@note    repo = { REPO, CACHE }
178#@note    Requisitos: \c grep \c sed
179#@exception OG_ERR_FORMAT    Formato incorrecto.
180#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
181#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
182#@warning Primeras pruebas.
183#@todo    Terminar de definir parámetros para acceso a repositorios.
184#@version 0.1 - Primera adaptación para OpenGNSys.
185#@author  obtenido de ogGetPath de Ramon Gomez, ETSII Universidad de Sevilla
186#@date    2009-09-15
187#*/
188function ogNewPath () {
189
190# Variables locales.
191local MNTDIR FILE PREVFILE FILEPATH CURRENTDIR
192
193#/// Si se solicita, mostrar ayuda.
194if [ "$*" == "help" ]; then
195    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
196           "$FUNCNAME \"/mnt/sda1/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32" \
197           "$FUNCNAME REPO /etc/fstab  ==>  /opt/opengnsys/images/etc/fstab" \
198           "$FUNCNAME 1 1 \"/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32"
199    return
200fi
201
202#/// Procesar camino según el número de parámetros.
203case $# in
204     # si 1 parametro directorio-fichero completo.
205    1)  FILE="$1" ;;
206    # Si 2 parametros es REPOSITORIO  DIRECTORIO-FICHERO
207    2)  case "$1" in
208            # consultando servidor repositorio base
209            REPO | $IPREPOMAN )  FILE="$OGIMG/$2" || return $OG_ERR_NOTFOUND ;;
210            # consultando particion auxiliar cache local
211            CACHE | $IP )
212                ogMountCache >> /dev/null &&    FILE="$OGCAC/$OGIMG/$2" || return $OG_ERR_NOTFOUND ;;
213            # conectando con Servidor Axuliar.
214            *)     ogRaiseError $OG_ERR_FORMAT
215                   return $? ;;
216        esac ;;
217    # Si 3 parametros DISK PARTITION DIRECTORIO-FICHERO
218    3)  FILE="$(ogMount $1 $2)/$3" || return $OG_ERR_NOTFOUND ;;
219    *)  return $OG_ERR_FORMAT ;;
220esac
221
222mkdir -p ${FILE}
223echo $FILE
224}
225
Note: See TracBrowser for help on using the repository browser.