source: client/engine/File.lib @ c8f8a9c

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 c8f8a9c 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
RevLine 
[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.
7#@version 0.9
8#@warning License: GNU GPLv3+
9#*/
10
11
[55ad138c]12#/**
[e42f34e]13#         ogCopyFile [ str_repo | int_ndisk int_npart ] path_source [ str_repo | int_ndisk int_npart ] path_target
[55ad138c]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
[1e7eaab]20#*/ ##
[c40a6b4]21function ogCopyFile () {
[55ad138c]22
23# Variables locales.
[e42f34e]24local ARGS SOURCE TARGET
[55ad138c]25
[e42f34e]26ARGS="$@"
[c40a6b4]27case "$1" in
[1e7eaab]28    /*)     # Camino completo.          */ (Comentrio Doxygen)
[e42f34e]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 ;;
[c40a6b4]37esac
[1e7eaab]38# Comprobar fichero origen y directorio destino.
[e42f34e]39[ -n "$SOURCE" ] || ogRaiseError $OG_ERR_NOTFOUND "${ARGS% $*}" || return $?
40TARGET=$(ogGetPath "$@")
41[ -n "$TARGET" ] || ogRaiseError $OG_ERR_NOTFOUND "$@" || return $?
[1e7eaab]42# Copiar fichero.
[55ad138c]43cp -p "$SOURCE" "$TARGET"                    # (definir posible error)
[c40a6b4]44}
45
46
[4c63eb9]47#/**
[c7d9af7]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
[1e7eaab]54#*/ ##
[c7d9af7]55function ogDeleteFile () {
56# Variables locales.
57local FILE
[1e7eaab]58# Comprobar que existe el fichero y borrarlo.
[c7d9af7]59FILE=$(ogGetPath "$@")
[a3fb8b2]60[ -n "$FILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $?
61rm -f "$FILE" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $?
[c7d9af7]62}
63
64
65#/**
[3543b3e]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
[1e7eaab]72#*/ ##
[3543b3e]73function ogDeleteTree () {
[c7d9af7]74
75# Variables locales.
[3543b3e]76local DIR
[1e7eaab]77# Comprobar que existe el directorio y borrarlo con su contenido.
[c7d9af7]78DIR=$(ogGetPath "$@")
[a3fb8b2]79[ -n "$DIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $?
80rm -fr "$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $?
[3543b3e]81}
82
83
84#/**
[1d531f9]85#         ogGetPath [ str_repo | int_ndisk int_npartition ] path_filepath
[4c63eb9]86#@brief   Inicia el proceso de arranque de un sistema de archivos.
[1d531f9]87#@arg  \c filepath   camino del fichero (independiente de mayúsculas)
88#@arg  \c repo       repositorio de ficheros
[4c63eb9]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.
[55ad138c]92#@note    repo = { REPO, CACHE, CDROM }
[1d531f9]93#@note    Requisitos: \c grep \c sed
[4c63eb9]94#@exception OG_ERR_FORMAT    Formato incorrecto.
[ebf06c7]95#@exception OG_ERR_NOTFOUND  Fichero o dispositivo no encontrado.
[4c63eb9]96#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[cfeabbf]97#@warning En caso de error, sólo devuelve el código y no da mensajes.
[4c63eb9]98#@todo    Terminar de definir parámetros para acceso a repositorios.
[23c6c40]99#@version 0.9 - Pruebas con OpenGNSys.
[4c63eb9]100#@author  Ramon Gomez, ETSII Universidad de Sevilla
101#@date    2009-09-15
[1e7eaab]102#*/ ##
[4c63eb9]103function ogGetPath () {
104
105# Variables locales.
106local MNTDIR FILE PREVFILE FILEPATH CURRENTDIR
107
[1e7eaab]108# Si se solicita, mostrar ayuda.
[4c63eb9]109if [ "$*" == "help" ]; then
110    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
[d071d9b]111           "$FUNCNAME \"/mnt/sda1/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32" \
112           "$FUNCNAME REPO /etc/fstab  ==>  /opt/opengnsys/images/etc/fstab" \
[4c63eb9]113           "$FUNCNAME 1 1 \"/windows/system32\"  ==>  /mnt/sda1/WINDOWS/System32"
114    return
115fi
116
[1e7eaab]117# Procesar camino según el número de parámetros.
[4c63eb9]118case $# in
119    1)  FILE="$1" ;;
120    2)  case "$1" in
[ee4a96e]121            REPO|repo)
[39277f4]122                FILE="$OGIMG/$2" ;;
[ee4a96e]123            CACHE|cache)
124                FILE="$OGCAC/$OGIMG/$2" ;;
125            CDROM|cdrom)
[3543b3e]126                FILE="$(ogMountCdrom)/$2" ;;
[39277f4]127            *)  ogRaiseError $OG_ERR_FORMAT
128                return $? ;;
[a2336d6]129        esac ;;
[ebf06c7]130    3)  FILE="$(ogMount $1 $2)/$3" ;;
131    *)  ogRaiseError $OG_ERR_FORMAT
[c40a6b4]132        return $? ;;
[4c63eb9]133esac
134
[1e7eaab]135# Eliminar caracteres \c / iniciales, finales y duplicados.
[4c63eb9]136CURRENTDIR="$PWD"
[1e7eaab]137        # /* (comentario Doxygen)
[4c63eb9]138FILE="$(echo $FILE|sed -e 's/\(\/\)*\1/\//g' -e 's/^\///' -e 's/\/$//')"
139PREVFILE=""
140FILEPATH="/"
141while [ "$FILE" != "$PREVFILE" ]; do
[1e7eaab]142    # Busca el nombre correcto en el directorio actual.
[4c63eb9]143    cd "$FILEPATH"
[1e7eaab]144    FILEPATH="${FILEPATH}/$(ls -A | grep -i -m1 "^${FILE%%/*}$")" || return $?
[4c63eb9]145    PREVFILE="$FILE"
146    FILE="${FILE#*/}"
147done
[1e7eaab]148        # (comentario Doxygen) */
149# Muestra el camino Linux, quitando el / inicial duplicado.
[4c63eb9]150[ "$FILEPATH" != "/" ] && echo ${FILEPATH#/}
151cd $CURRENTDIR
152}
153
[a2336d6]154
[23c6c40]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
[1e7eaab]162#*/ ##
[ebf06c7]163function ogGetParentPath () {
164local PARENT
165case $# in
[23c6c40]166    1)  PARENT="$(dirname "$1")" ;;
[a3fb8b2]167    2)  PARENT="$1 $(dirname "/$2")" ;;
168    3)  PARENT="$1 $2 $(dirname "/$3")" ;;
[ebf06c7]169    *)  ogRaiseError $OG_ERR_FORMAT
[cfeabbf]170        return $? ;;
[ebf06c7]171esac
172ogGetPath $PARENT
173}
174
175
[23c6c40]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
[1e7eaab]183#*/ ##
[ebf06c7]184function ogMakeDir () {
185local PARENT DIR
186PARENT=$(ogGetParentPath "$@") || return $?
[23c6c40]187DIR="$(basename "${!#}")"
[a3fb8b2]188mkdir -p "$PARENT/$DIR" || ogRaiseError $OG_ERR_NOTFOUND "$*" || return $?
[ebf06c7]189}
190 
[a2336d6]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.