source: client/engine/System.lib @ 499a7ec

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 499a7ec was cd1f048, checked in by irina <irinagomez@…>, 12 years ago

#565 optimiza tamaño de las imágenes

git-svn-id: https://opengnsys.es/svn/branches/version1.0@3808 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 7.1 KB
Line 
1#!/bin/bash
2#/**
3#@file     System.lib
4#@brief    Librería o clase System
5#@class    System
6#@brief    Funciones básicas del sistema.
7#@version  1.0.4
8#@warning  License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogEcho [str_loglevel] "str_message..."
14#@brief   Muestra mensajes en consola y lo registra en fichero de incidencias.
15#@param   str_loglevel nivel de registro de incidencias.
16#@param   str_message  mensaje (puede recibir más de 1 parámetro.
17#@return  Mensaje mostrado.
18#@warning Si no se indica nivel de registro, solo muestra mensaje en pantalla.
19#@note    El nivel de ayuda \c (help) no se registra en el fichero de incidencias.
20#@version 0.9 - Primera versión para OpenGnSys
21#@author  Ramon Gomez, ETSII Universidad de Sevilla
22#@date    2009-07-23
23#*/
24function ogEcho () {
25
26# Variables locales
27local LOGLEVEL DATETIME
28
29# Selección del nivel de registro (opcional).
30case "$1" in
31     help)    shift ;;
32     info)    LOGLEVEL="$1"; shift ;;
33     warning) LOGLEVEL="$1"; shift ;;
34     error)   LOGLEVEL="$1"; shift ;;
35     *)       ;;
36esac
37DATETIME=$(date +"%F %T")
38
39if [ -n "$LOGLEVEL" ]; then
40    logger -s -t "OpenGnSys $LOGLEVEL" -f $OGLOGFILE "$DATETIME $*"
41    logger -t "OpenGnSys $LOGLEVEL" -f $OGLOGCOMMAND "$DATETIME $*"
42    logger -t "OpenGnSys $LOGLEVEL" -f $OGLOGSESSION "$DATETIME $*"
43else
44    echo "$*"
45fi
46}
47
48
49#/**
50#         ogRaiseError int_errcode ["str_errmessage" ...]
51#@brief   Devuelve el mensaje y el código de error correspondiente.
52#@param   int_errcode    código de error.
53#@param   str_errmessage mensajes complementarios de error.
54#@return  str_message - Mensaje de error.
55#@warning No definidas
56#@note    Mensajes internacionales del fichero de idiomas.
57#@version 0.9 - Primera versión para OpenGnSys.
58#@author  Ramon Gomez, ETSII Universidad de Sevilla
59#@date    2009-07-21
60#*/
61function ogRaiseError () {
62
63# Variables locales
64local MSG CODE
65
66# Obtener código y mensaje de error.
67CODE=$1
68case "$CODE" in
69     $OG_ERR_FORMAT)     MSG="$MSG_ERR_FORMAT \"$2\"" ;;
70     $OG_ERR_NOTFOUND)   MSG="$MSG_ERR_NOTFOUND \"$2\"" ;;
71     $OG_ERR_OUTOFLIMIT) MSG="$MSG_ERR_OUTOFLIMIT \"$2\"" ;;
72     $OG_ERR_PARTITION)  MSG="$MSG_ERR_PARTITION \"$2\"" ;;
73     $OG_ERR_LOCKED)     MSG="$MSG_ERR_LOCKED \"$2\"" ;;
74     $OG_ERR_CACHE)      MSG="$MSG_ERR_CACHE \"$2\"" ;;
75     $OG_ERR_NOGPT)      MSG="$MSG_ERR_NOGPT \"$2\"" ;;
76     $OG_ERR_FILESYS)    MSG="$MSG_ERR_FILESYS \"$2\"" ;;
77     $OG_ERR_IMAGE)      MSG="$MSG_ERR_IMAGE \"$2\"" ;;
78     $OG_ERR_NOTOS)      MSG="$MSG_ERR_NOTOS \"$2\"" ;;
79     $OG_ERR_NOTEXEC)    MSG="$MSG_ERR_NOTEXEC \"$2\"" ;;
80     $OG_ERR_NOTWRITE)   MSG="$MSG_ERR_NOTWRITE \"$2\"" ;;
81     $OG_ERR_NOTCACHE)   MSG="$MSG_ERR_NOTCACHE \"$2\"" ;;
82     $OG_ERR_CACHESIZE)  MSG="$MSG_ERR_CACHESIZE \"$2\"" ;;
83     $OG_ERR_REDUCEFS)   MSG="$MSG_ERR_REDUCEFS \"$2\"" ;;
84     $OG_ERR_EXTENDFS)   MSG="$MSG_ERR_EXTENDFS \"$2\"" ;;
85     $OG_ERR_IMGSIZEPARTITION)   MSG="$MSG_ERR_IMGSIZEPARTITION \"$2\"" ;;   
86     $OG_ERR_UCASTSYNTAXT)   MSG="$MSG_ERR_UCASTSYNTAXT \"$2\"" ;;
87     $OG_ERR_UCASTSENDPARTITION)   MSG="$MSG_ERR_UCASTSENDPARTITION \"$2\"" ;;   
88     $OG_ERR_UCASTSENDFILE)   MSG="$MSG_ERR_UCASTSENDFILE \"$2\"" ;; 
89     $OG_ERR_UCASTRECEIVERPARTITION)   MSG="$MSG_ERR_UCASTRECEIVERPARTITION \"$2\"" ;;   
90     $OG_ERR_UCASTRECEIVERFILE)   MSG="$MSG_ERR_UCASTRECEIVERFILE \"$2\"" ;; 
91     $OG_ERR_MCASTSYNTAXT)   MSG="$MSG_ERR_MCASTSYNTAXT \"$2\"" ;;
92     $OG_ERR_MCASTSENDFILE)   MSG="$MSG_ERR_MCASTSENDFILE \"$2\"" ;;
93     $OG_ERR_MCASTRECEIVERFILE)   MSG="$MSG_ERR_MCASTRECEIVERFILE \"$2\"" ;;
94     $OG_ERR_MCASTSENDPARTITION)   MSG="$MSG_ERR_MCASTSENDPARTITION \"$2\"" ;;
95     $OG_ERR_MCASTRECEIVERPARTITION)   MSG="$MSG_ERR_MCASTRECEIVERPARTITION \"$2\"" ;;
96     $OG_ERR_PROTOCOLJOINMASTER)   MSG="$MSG_ERR_PROTOCOLJOINMASTER \"$2\"" ;;
97     $OG_ERR_DONTMOUNT_IMAGE)   MSG="$MSG_ERR_DONTMOUNT_IMAGE \"$2\"" ;;
98     $OG_ERR_DONTUNMOUNT_IMAGE)   MSG="$MSG_ERR_DONTUNMOUNT_IMAGE \"$2\"" ;;
99     $OG_ERR_DONTSYNC_IMAGE)    MSG="$MSG_ERR_DONTSYNC_IMAGE \"$2\"" ;;
100     *)                  MSG="$MSG_ERR_GENERIC"; CODE=$OG_ERR_GENERIC ;;
101esac
102
103# Mostrar mensaje de error y salir con el código indicado.
104ogEcho error "${FUNCNAME[1]}: $MSG" >&2
105return $CODE
106}
107
108
109#/**
110#         ogGetCaller
111#@brief   Devuelve nombre del programa o script ejecutor (padre).
112#@param   No.
113#@return  str_name - Nombre del programa ejecutor.
114#@version 0.10 - Primera versión para OpenGnSys.
115#@author  Ramon Gomez, ETSII Universidad de Sevilla
116#@date    2011-01-17
117#*/
118function ogGetCaller () {
119
120# Obtener el nombre del programa o del script que ha llamado al proceso actual.
121basename $(ps hlp $PPID | awk '{if ($13~/bash/ && $14!="") print $14;
122                                else print $13;}')
123}
124
125
126#/**
127#         ogIsRepoLocked
128#@brief   Comprueba si el repositorio está siendo usado (tiene ficheros abiertos).
129#@param   No.
130#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
131#@version 0.10 - Primera versión para OpenGnSys.
132#@author  Ramon Gomez, ETSII Universidad de Sevilla
133#@date    2011-01-17
134#@version 1.0.1 - Devolver falso en caso de error.
135#@author  Ramon Gomez, ETSII Universidad de Sevilla
136#@date    2011-05-18
137#*/
138function ogIsRepoLocked ()
139{
140# Variables locales.
141local f FILES
142
143# No hacer nada, si no está definido el punto de montaje del repositorio.
144[ -z "$OGIMG" ] && return 1
145
146# Comprobar si alguno de los ficheros abiertos por los procesos activos está en el
147# punto de montaje del repositorio de imágenes.
148FILES=$(for f in /proc/[0-9]*/fd/*; do readlink -f "$f"; done | grep "^$OGIMG")   # */ (comentario Doxygen)
149test -n "$FILES"
150}
151
152
153
154#/**
155#         ogHelp ["str_function" ["str_format" ["str_example" ... ]]]
156#@brief   Muestra mensaje de ayuda para una función determinda.
157#@param   str_function Nombre de la función.
158#@param   str_format   Formato de ejecución de la función.
159#@param   str_example  Ejemplo de ejecución de la función.
160#@return  str_help - Salida de ayuda.
161#@note    Si no se indican parámetros, la función se toma de la variable \c $FUNCNAME
162#@note    La descripción de la función se toma de la variable compuesta por \c MSG_FUNC_$función incluida en el fichero de idiomas.
163#@note    Pueden especificarse varios mensajes con ejemplos.
164#@version 0.9 - Primera versión para OpenGnSys.
165#@author  Ramon Gomez, ETSII Universidad de Sevilla
166#@date    2009-07-27
167#*/
168function ogHelp () {
169
170# Variables locales.
171local FUNC MSG
172
173# Mostrar función, descripción y formato.
174FUNC="${1:-${FUNCNAME[${#FUNCNAME[*]}-1]}}"
175MSG="MSG_HELP_$FUNC"
176ogEcho help "$MSG_FUNCTION $FUNC: ${!MSG}"
177[ -n "$2" ] && ogEcho help "    $MSG_FORMAT: $2"
178# Mostrar ejemplos (si existen).
179shift 2
180while [ $# -gt 0 ]; do
181    ogEcho help "    $MSG_EXAMPLE: $1"
182    shift
183done
184}
185
186
187function ogCheckProgram ()
188{
189# Si se solicita, mostrar ayuda.
190if [ "$*" == "help" ]; then
191    ogHelp "$FUNCNAME \"str_program ...\"" \
192           "$FUNCNAME \"partimage partclone mbuffer\""
193    return
194fi
195
196# Error si no se recibe 1 parámetro.
197[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
198
199local PERROR PLOG i
200PERROR=0
201PLOG=" "
202for i in `echo $1`
203do
204  if [ ! `which $i` ]
205     then
206        PERROR=1
207        PLOG="$PLOG $i"
208     fi
209done
210if [ "$PERROR" == "1" ]
211then
212        ogRaiseError $OG_ERR_NOTEXEC "$PLOG" || return $?
213else           
214        return 0
215fi
216}
217
Note: See TracBrowser for help on using the repository browser.