source: client/engine/File.lib @ 7a6b41b

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 7a6b41b was 1e7eaab, checked in by ramon <ramongomez@…>, 15 years ago

Installador vale para repositorio y descargable; funciones de API compatibles Doxygen.

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

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