source: client/engine/System.lib @ 9a2cda1e

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 9a2cda1e was 3458879, checked in by ramon <ramongomez@…>, 16 years ago

Correcciones en varias funciones; función en pruebas ogGetIpAddress.

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

  • Property mode set to 100755
File size: 4.2 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 [loglevel] message...
14#@brief   Muestra mensajes en consola y lo registra en fichero de incidencias.
15#@arg  \c str_loglevel nivel de registro de incidencias.
16#@arg  \c str_message  mensaje (puede recibir más de 1 parámetro.
17#@return  Mensaje mostrado.
18#@note    El nivel de ayuda \c (help) no se registra en el fichero de incidencias.
19#@version 0.9 - Primera versión para OpenGNSys
20#@author  Ramon Gomez, ETSII Universidad de Sevilla
21#@date    2009-07-23
22#*/
23function ogEcho () {
24
25# Variables locales
26local LOGLEVEL LOGFILE DATETIME
27
28#/// Selección del nivel de registro (opcional).
29case "$1" in
30     help)    shift ;;
31     info)    LOGLEVEL=$1; shift ;;
32     warning) LOGLEVEL=$1; shift ;;
33     error)   LOGLEVEL=$1; shift ;;
34     *)       ;;
35esac
36 
37#/// Registro de incidencias.
38#[ -w "$OGLOGFILE" ] && LOGFILE="-f $OGLOGFILE"
39#DATETIME=$(date +"%F %T")    # pendiente en cliente Initrd
40if [ -n "$LOGLEVEL" ]; then
41    logger -s -t "OpenGNSys $LOGLEVEL" $LOGFILE "$DATETIME $*"
42else
43    echo "$*"
44fi
45}
46
47
48##### PRUEBAS
49#         ogGetHostname
50function ogGetHostname () {
51local HOST
52#/// Tomar nombre de la variable \c HOSTNAME
53HOST="$HOSTNAME"
54#/// Si no, tomar del DHCP, opción \c host-name
55[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
56                                   END {print host}
57                                  ' /var/lib/dhcp3/dhclient.leases)
58#/// Si no, tomar del parámetro del kernel \c hostname
59[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
60                              $1~/hostname/ {print $2}' /proc/cmdline)
61[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
62echo $HOST
63}
64
65#         ogGetIpAddress
66function ogGetIpAddress () {
67local IP
68IP=$(awk '/fixed-address/ {gsub(/;/,""); host=$2}
69          END {print host}
70         ' /var/lib/dhcp3/dhclient.leases)
71echo $IP;
72}
73
74
75#/**
76#         ogRaiseError errcode ["errmessage" ...]
77#@brief   Devuelve el mensaje y el código de error correspondiente.
78#@arg  \c int_errcode    código de error.
79#@arg  \c str_errmessage mensajes complementarios de error.
80#@return  Mensaje de error.
81#@warning No definidas
82#@note    Mensajes internacionales del fichero de idiomas.
83#@version 0.9 - Primera versión para OpenGNSys.
84#@author  Ramon Gomez, ETSII Universidad de Sevilla
85#@date    2009-07-21
86#*/
87function ogRaiseError () {
88
89# Variables locales
90local MSG CODE
91
92#/// Obtener código y mensaje de error.
93CODE=$1
94case "$CODE" in
95     $OG_ERR_FORMAT)    MSG="$MSG_ERR_FORMAT \"$2\"" ;;
96     $OG_ERR_NOTFOUND)  MSG="$MSG_ERR_NOTFOUND \"$2\"" ;;
97     $OG_ERR_PARTITION) MSG="$MSG_ERR_PARTITION \"$2\"" ;;
98     $OG_ERR_LOCKED)    MSG="$MSG_ERR_LOCKED \"$2\"" ;;
99     $OG_ERR_IMAGE)     MSG="$MSG_ERR_IMAGE \"$2\"" ;;
100     $OG_ERR_NOTOS)     MSG="$MSG_ERR_NOTOS \"$2\"" ;;
101     $OG_ERR_NOTEXEC)   MSG="$MSG_ERR_NOTEXEC \"$2\"" ;;
102     *)                 MSG="$MSG_ERR_GENERIC"; CODE=$OG_ERR_GENERIC ;;
103esac
104
105#/// Mostrar mensaje de error y salir con el código indicado.
106ogEcho error "${FUNCNAME[1]}: $MSG" >&2
107return $CODE
108}
109
110
111#/**
112#         ogHelp ["function" ["format" ["example" ... ]]]
113#@brief   Muestra mensaje de ayuda para una función determinda.
114#@arg  \c str_function Nombre de la función.
115#@arg  \c str_format   Formato de ejecución de la función.
116#@arg  \c str_example  Ejemplo de ejecución de la función.
117#@return  Salida de ayuda.
118#@note    Si no se indican parámetros, la función se toma de la variable \c $FUNCNAME
119#@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.
120#@note    Pueden especificarse varios mensajes con ejemplos.
121#@version 0.9 - Primera versión para OpenGNSys.
122#@author  Ramon Gomez, ETSII Universidad de Sevilla
123#@date    2009-07-27
124#*/
125function ogHelp () {
126
127# Variables locales.
128local FUNC MSG
129
130#/// Mostrar función, descripción y formato.
131FUNC="${1:-${FUNCNAME[${#FUNCNAME[*]}-1]}}"
132MSG="MSG_HELP_$FUNC"
133ogEcho help "$MSG_FUNCTION $FUNC: ${!MSG}"
134[ -n "$2" ] && ogEcho help "    $MSG_FORMAT: $2"
135#/// Mostrar ejemplos.
136shift 2
137while [ $# -gt 0 ]; do
138    ogEcho help "    $MSG_EXAMPLE: $1"
139    shift
140done
141}
142
Note: See TracBrowser for help on using the repository browser.