[9f29ba6] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file System.lib |
---|
[9f57de01] | 4 | #@brief Librería o clase System |
---|
[9f29ba6] | 5 | #@class System |
---|
| 6 | #@brief Funciones básicas del sistema. |
---|
| 7 | #@version 0.9 |
---|
| 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[2e15649] | 11 | |
---|
[9f29ba6] | 12 | #/** |
---|
[42669ebf] | 13 | # ogEcho [str_loglevel] "str_message..." |
---|
[9f57de01] | 14 | #@brief Muestra mensajes en consola y lo registra en fichero de incidencias. |
---|
[42669ebf] | 15 | #@param str_loglevel nivel de registro de incidencias. |
---|
| 16 | #@param str_message mensaje (puede recibir más de 1 parámetro. |
---|
[9f57de01] | 17 | #@return Mensaje mostrado. |
---|
[aae34f6] | 18 | #@note El nivel de ayuda \c (help) no se registra en el fichero de incidencias. |
---|
[ead38fb] | 19 | #@version 0.9 - Primera versión para OpenGnSys |
---|
[aae34f6] | 20 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[9f57de01] | 21 | #@date 2009-07-23 |
---|
[9f29ba6] | 22 | #*/ |
---|
[9f57de01] | 23 | function ogEcho () { |
---|
[9f29ba6] | 24 | |
---|
[59f9ad2] | 25 | # Variables locales |
---|
[cfeabbf] | 26 | local LOGLEVEL LOGFILE DATETIME |
---|
[9f57de01] | 27 | |
---|
[42669ebf] | 28 | # Selección del nivel de registro (opcional). |
---|
[9f57de01] | 29 | case "$1" in |
---|
[d071d9b] | 30 | help) shift ;; |
---|
| 31 | info) LOGLEVEL=$1; shift ;; |
---|
| 32 | warning) LOGLEVEL=$1; shift ;; |
---|
| 33 | error) LOGLEVEL=$1; shift ;; |
---|
| 34 | *) ;; |
---|
[9f57de01] | 35 | esac |
---|
[42669ebf] | 36 | # Pendiente en cliente Initrd. |
---|
| 37 | #DATETIME=$(date +"%F %T") |
---|
| 38 | |
---|
[cfeabbf] | 39 | if [ -n "$LOGLEVEL" ]; then |
---|
[ead38fb] | 40 | logger -s -t "OpenGnSys $LOGLEVEL" $LOGFILE "$DATETIME $*" |
---|
[cfeabbf] | 41 | else |
---|
| 42 | echo "$*" |
---|
[9f57de01] | 43 | fi |
---|
[9f29ba6] | 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | #/** |
---|
[42669ebf] | 48 | # ogRaiseError int_errcode ["str_errmessage" ...] |
---|
[9f57de01] | 49 | #@brief Devuelve el mensaje y el código de error correspondiente. |
---|
[42669ebf] | 50 | #@param int_errcode código de error. |
---|
| 51 | #@param str_errmessage mensajes complementarios de error. |
---|
[9f57de01] | 52 | #@return Mensaje de error. |
---|
| 53 | #@warning No definidas |
---|
[aae34f6] | 54 | #@note Mensajes internacionales del fichero de idiomas. |
---|
[ead38fb] | 55 | #@version 0.9 - Primera versión para OpenGnSys. |
---|
[aae34f6] | 56 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[9f57de01] | 57 | #@date 2009-07-21 |
---|
[9f29ba6] | 58 | #*/ |
---|
[9f57de01] | 59 | function ogRaiseError () { |
---|
[9f29ba6] | 60 | |
---|
[59f9ad2] | 61 | # Variables locales |
---|
[a5df9b9] | 62 | local MSG CODE |
---|
[2e15649] | 63 | |
---|
[42669ebf] | 64 | # Obtener código y mensaje de error. |
---|
[a5df9b9] | 65 | CODE=$1 |
---|
| 66 | case "$CODE" in |
---|
[315aaca] | 67 | $OG_ERR_FORMAT) MSG="$MSG_ERR_FORMAT \"$2\"" ;; |
---|
| 68 | $OG_ERR_NOTFOUND) MSG="$MSG_ERR_NOTFOUND \"$2\"" ;; |
---|
| 69 | $OG_ERR_OUTOFLIMIT) MSG="$MSG_ERR_OUTOFLIMIT \"$2\"" ;; |
---|
| 70 | $OG_ERR_PARTITION) MSG="$MSG_ERR_PARTITION \"$2\"" ;; |
---|
| 71 | $OG_ERR_LOCKED) MSG="$MSG_ERR_LOCKED \"$2\"" ;; |
---|
| 72 | $OG_ERR_CACHE) MSG="$MSG_ERR_CACHE \"$2\"" ;; |
---|
| 73 | $OG_ERR_FILESYS) MSG="$MSG_ERR_FILESYS \"$2\"" ;; |
---|
| 74 | $OG_ERR_IMAGE) MSG="$MSG_ERR_IMAGE \"$2\"" ;; |
---|
| 75 | $OG_ERR_NOTOS) MSG="$MSG_ERR_NOTOS \"$2\"" ;; |
---|
| 76 | $OG_ERR_NOTEXEC) MSG="$MSG_ERR_NOTEXEC \"$2\"" ;; |
---|
| 77 | *) MSG="$MSG_ERR_GENERIC"; CODE=$OG_ERR_GENERIC ;; |
---|
[2e15649] | 78 | esac |
---|
| 79 | |
---|
[42669ebf] | 80 | # Mostrar mensaje de error y salir con el código indicado. |
---|
[aae34f6] | 81 | ogEcho error "${FUNCNAME[1]}: $MSG" >&2 |
---|
[a5df9b9] | 82 | return $CODE |
---|
[9f29ba6] | 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
[aae34f6] | 86 | #/** |
---|
[1e7eaab] | 87 | # ogHelp ["str_function" ["str_format" ["str_example" ... ]]] |
---|
[aae34f6] | 88 | #@brief Muestra mensaje de ayuda para una función determinda. |
---|
[42669ebf] | 89 | #@param str_function Nombre de la función. |
---|
| 90 | #@param str_format Formato de ejecución de la función. |
---|
| 91 | #@param str_example Ejemplo de ejecución de la función. |
---|
| 92 | #@return str_help - Salida de ayuda. |
---|
[aae34f6] | 93 | #@note Si no se indican parámetros, la función se toma de la variable \c $FUNCNAME |
---|
| 94 | #@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. |
---|
| 95 | #@note Pueden especificarse varios mensajes con ejemplos. |
---|
[ead38fb] | 96 | #@version 0.9 - Primera versión para OpenGnSys. |
---|
[aae34f6] | 97 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 98 | #@date 2009-07-27 |
---|
| 99 | #*/ |
---|
| 100 | function ogHelp () { |
---|
| 101 | |
---|
[59f9ad2] | 102 | # Variables locales. |
---|
[aae34f6] | 103 | local FUNC MSG |
---|
| 104 | |
---|
[42669ebf] | 105 | # Mostrar función, descripción y formato. |
---|
[aae34f6] | 106 | FUNC="${1:-${FUNCNAME[${#FUNCNAME[*]}-1]}}" |
---|
| 107 | MSG="MSG_HELP_$FUNC" |
---|
| 108 | ogEcho help "$MSG_FUNCTION $FUNC: ${!MSG}" |
---|
| 109 | [ -n "$2" ] && ogEcho help " $MSG_FORMAT: $2" |
---|
[42669ebf] | 110 | # Mostrar ejemplos (si existen). |
---|
[aae34f6] | 111 | shift 2 |
---|
| 112 | while [ $# -gt 0 ]; do |
---|
| 113 | ogEcho help " $MSG_EXAMPLE: $1" |
---|
| 114 | shift |
---|
| 115 | done |
---|
| 116 | } |
---|
| 117 | |
---|