source: client/engine/System.lib @ 3c2933e

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 3c2933e was e2923e1, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.2: corregir errata al generar registros de incidencias en la función ogEcho.

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

  • Property mode set to 100755
File size: 6.9 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  0.9
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 LOGFILE 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 $LOGFILE "$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_FILESYS)    MSG="$MSG_ERR_FILESYS \"$2\"" ;;
76     $OG_ERR_IMAGE)      MSG="$MSG_ERR_IMAGE \"$2\"" ;;
77     $OG_ERR_NOTOS)      MSG="$MSG_ERR_NOTOS \"$2\"" ;;
78     $OG_ERR_NOTEXEC)    MSG="$MSG_ERR_NOTEXEC \"$2\"" ;;
79     $OG_ERR_NOTWRITE)   MSG="$MSG_ERR_NOTWRITE \"$2\"" ;;
80     $OG_ERR_NOTCACHE)   MSG="$MSG_ERR_NOTCACHE \"$2\"" ;;
81     $OG_ERR_CACHESIZE)  MSG="$MSG_ERR_CACHESIZE \"$2\"" ;;
82     $OG_ERR_REDUCEFS)   MSG="$MSG_ERR_REDUCEFS \"$2\"" ;;
83     $OG_ERR_EXTENDFS)   MSG="$MSG_ERR_EXTENDFS \"$2\"" ;;
84     $OG_ERR_IMGSIZEPARTITION)   MSG="$MSG_ERR_IMGSIZEPARTITION \"$2\"" ;;   
85     $OG_ERR_UCASTSYNTAXT)   MSG="$MSG_ERR_UCASTSYNTAXT \"$2\"" ;;
86     $OG_ERR_UCASTSENDPARTITION)   MSG="$MSG_ERR_UCASTSENDPARTITION \"$2\"" ;;   
87     $OG_ERR_UCASTSENDFILE)   MSG="$MSG_ERR_UCASTSENDFILE \"$2\"" ;; 
88     $OG_ERR_UCASTRECEIVERPARTITION)   MSG="$MSG_ERR_UCASTRECEIVERPARTITION \"$2\"" ;;   
89     $OG_ERR_UCASTRECEIVERFILE)   MSG="$MSG_ERR_UCASTRECEIVERFILE \"$2\"" ;; 
90     $OG_ERR_MCASTSYNTAXT)   MSG="$MSG_ERR_MCASTSYNTAXT \"$2\"" ;;
91     $OG_ERR_MCASTSENDFILE)   MSG="$MSG_ERR_MCASTSENDFILE \"$2\"" ;;
92     $OG_ERR_MCASTRECEIVERFILE)   MSG="$MSG_ERR_MCASTRECEIVERFILE \"$2\"" ;;
93     $OG_ERR_MCASTSENDPARTITION)   MSG="$MSG_ERR_MCASTSENDPARTITION \"$2\"" ;;
94     $OG_ERR_MCASTRECEIVERPARTITION)   MSG="$MSG_ERR_MCASTRECEIVERPARTITION \"$2\"" ;;
95     $OG_ERR_PROTOCOLJOINMASTER)   MSG="$MSG_ERR_PROTOCOLJOINMASTER \"$2\"" ;;
96     *)                  MSG="$MSG_ERR_GENERIC"; CODE=$OG_ERR_GENERIC ;;
97esac
98
99# Mostrar mensaje de error y salir con el código indicado.
100ogEcho error "${FUNCNAME[1]}: $MSG" >&2
101return $CODE
102}
103
104
105#/**
106#         ogGetCaller
107#@brief   Devuelve nombre del programa o script ejecutor (padre).
108#@param   No.
109#@return  str_name - Nombre del programa ejecutor.
110#@version 0.10 - Primera versión para OpenGnSys.
111#@author  Ramon Gomez, ETSII Universidad de Sevilla
112#@date    2011-01-17
113#*/
114function ogGetCaller () {
115
116# Obtener el nombre del programa o del script que ha llamado al proceso actual.
117basename $(ps hlp $PPID | awk '{if ($13~/bash/ && $14!="") print $14;
118                                else print $13;}')
119}
120
121
122#/**
123#         ogIsRepoLocked
124#@brief   Comprueba si el repositorio está siendo usado (tiene ficheros abiertos).
125#@param   No.
126#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
127#@version 0.10 - Primera versión para OpenGnSys.
128#@author  Ramon Gomez, ETSII Universidad de Sevilla
129#@date    2011-01-17
130#@version 1.0.1 - Devolver falso en caso de error.
131#@author  Ramon Gomez, ETSII Universidad de Sevilla
132#@date    2011-05-18
133#*/
134function ogIsRepoLocked ()
135{
136# Variables locales.
137local f FILES
138
139# No hacer nada, si no está definido el punto de montaje del repositorio.
140[ -z "$OGIMG" ] && return 1
141
142# Comprobar si alguno de los ficheros abiertos por los procesos activos está en el
143# punto de montaje del repositorio de imágenes.
144FILES=$(for f in /proc/[0-9]*/fd/*; do readlink -f "$f"; done | grep "^$OGIMG")   # */ (comentario Doxygen)
145test -n "$FILES"
146}
147
148
149
150#/**
151#         ogHelp ["str_function" ["str_format" ["str_example" ... ]]]
152#@brief   Muestra mensaje de ayuda para una función determinda.
153#@param   str_function Nombre de la función.
154#@param   str_format   Formato de ejecución de la función.
155#@param   str_example  Ejemplo de ejecución de la función.
156#@return  str_help - Salida de ayuda.
157#@note    Si no se indican parámetros, la función se toma de la variable \c $FUNCNAME
158#@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.
159#@note    Pueden especificarse varios mensajes con ejemplos.
160#@version 0.9 - Primera versión para OpenGnSys.
161#@author  Ramon Gomez, ETSII Universidad de Sevilla
162#@date    2009-07-27
163#*/
164function ogHelp () {
165
166# Variables locales.
167local FUNC MSG
168
169# Mostrar función, descripción y formato.
170FUNC="${1:-${FUNCNAME[${#FUNCNAME[*]}-1]}}"
171MSG="MSG_HELP_$FUNC"
172ogEcho help "$MSG_FUNCTION $FUNC: ${!MSG}"
173[ -n "$2" ] && ogEcho help "    $MSG_FORMAT: $2"
174# Mostrar ejemplos (si existen).
175shift 2
176while [ $# -gt 0 ]; do
177    ogEcho help "    $MSG_EXAMPLE: $1"
178    shift
179done
180}
181
182
183function ogCheckProgram ()
184{
185# Si se solicita, mostrar ayuda.
186if [ "$*" == "help" ]; then
187    ogHelp "$FUNCNAME \"str_program ...\"" \
188           "$FUNCNAME \"partimage partclone mbuffer\""
189    return
190fi
191
192# Error si no se recibe 1 parámetro.
193[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
194
195local PERROR PLOG i
196PERROR=0
197PLOG=" "
198for i in `echo $1`
199do
200  if [ ! `which $i` ]
201     then
202        PERROR=1
203        PLOG="$PLOG $i"
204     fi
205done
206if [ "$PERROR" == "1" ]
207then
208        ogRaiseError $OG_ERR_NOTEXEC "$PLOG" || return $?
209else           
210        return 0
211fi
212}
213
Note: See TracBrowser for help on using the repository browser.