source: client/engine/Net.lib @ 20a91aa

Last change on this file since 20a91aa was 71643c0, checked in by ramon <ramongomez@…>, 13 years ago

Integrar versión 1.0.2 en rama trunk (modificar #464).

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

  • Property mode set to 100755
File size: 6.6 KB
RevLine 
[e0f3634]1#!/bin/bash
2#/**
3#@file     Net.lib
4#@brief    Librería o clase Net
5#@class    Net
6#@brief    Funciones básicas de red.
[71643c0]7#@version  1.0.2
[e0f3634]8#@warning  License: GNU GPLv3+
9#*/
10
11
12#/**
[71643c0]13#         ogGetGroupDir [ str_repo ]
14#@brief   Devuelve el cmaino del directorio para el grupo del cliente.
15#@param   str_repo     repositorio de imágenes (opcional)
16#@return  path_dir  -  Camino al directorio del grupo.
17#@note    repo = { REPO, CACHE }     REPO por defecto
18#@exception OG_ERR_FORMAT    formato incorrecto.
19#@version 1.0.2 - Primera versión para OpenGnSys.
20#@author  Ramon Gomez, ETSII Universidad de Sevilla
21#@date    2011-10-03
22#*/
23function ogGetGroupDir ()
24{
25local REPO DIR GROUP
26if [ "$*" == "help" ]; then
27    ogHelp "$FUNCNAME" "$FUNCNAME str_repo" \
28           "$FUNCNAME REPO  ==>  /opt/opengnsys/images/groups/Grupo1"
29    return
30fi
31# Error si se recibe más de 1 parámetro.
32case $# in
33    0)  REPO="REPO" ;;
34    1)  REPO="$1" ;;
35    *)  ogRaiseError $OG_ERR_FORMAT "$*"
36        return $? ;;
37esac
38
39GROUP="$(ogGetGroupName)"
40if [ -n "$GROUP" ]; then
41    DIR=$(ogGetPath "$REPO" "/groups/$GROUP" 2>/dev/null)
42    [ -d "$DIR" ] && echo "$DIR"
43fi
44}
45
46
47#/**
48#         ogGetGroupName
49#@brief   Devuelve el nombre del grupo al que pertenece el cliente.
50#@return  str_group - Nombre de grupo.
51#@version 1.0.2 - Primera versión para OpenGnSys.
52#@author  Ramon Gomez, ETSII Universidad de Sevilla
53#@date    2011-10-03
54#*/
55function ogGetGroupName ()
56{
57if [ "$*" == "help" ]; then
58    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  Grupo1"
59    return
60fi
61[ -n "$group" ] && echo "$group"
62}
63
64
65#/**
[e0f3634]66#         ogGetHostname
67#@brief   Muestra el nombre del cliente.
68#@return  str_host - nombre de máquina
[fb8c54b]69#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]70#@author  Ramon Gomez, ETSII Universidad de Sevilla
71#@date    2010-02-11
72#*/ ##
73function ogGetHostname ()
74{
75local HOST
[71643c0]76if [ "$*" == "help" ]; then
77    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  pc1"
78    return
79fi
[0bfbbe1]80# Tomar nombre de la variable HOSTNAME
[e0f3634]81HOST="$HOSTNAME"
[0bfbbe1]82# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
[e0f3634]83[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
84                                   END {print host}
85                                  ' /var/lib/dhcp3/dhclient.leases)
[0bfbbe1]86# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
[e0f3634]87[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
88                              $1~/hostname/ {print $2}' /proc/cmdline)
89[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
[71643c0]90[ -n "$HOST" ] && echo $HOST
[e0f3634]91}
92
93
94#/**
[bd27de2]95#         ogGetNetInterface
96#@brief   Muestra la interfaz de red del sistema
[71643c0]97#@return  str_interface - interfaz de red
[bd27de2]98#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
99#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
100#@author  Antonio J. Doblas Viso. Universidad de Malaga.
101#@date    2011-02-24
102#*/ ##
103function ogGetNetInterface ()
104{
[71643c0]105if [ "$*" == "help" ]; then
106    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  eth0"
107    return
108fi
109[ -n "$DEVICE" ] && echo "$DEVICE"
[bd27de2]110}
111
112
113#/**
[e0f3634]114#         ogGetIpAddress
115#@brief   Muestra la dirección IP del sistema
116#@return  str_ip - Dirección IP
[fb8c54b]117#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]118#@author  Ramon Gomez, ETSII Universidad de Sevilla
119#@date    2010-02-11
[8368c0d]120#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
[bd27de2]121#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
[8368c0d]122#@author  Antonio J. Doblas Viso. Universidad de Malaga.
123#@date    2011-02-24
[71643c0]124#@version 1.0.2 - Soporte para varias tarjetas de red
125#@author  Ramon Gomez, ETSII Universidad de Sevilla
126#@date    2011-06-17
[e0f3634]127#*/ ##
128function ogGetIpAddress ()
129{
130local IP
[71643c0]131if [ "$*" == "help" ]; then
132    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.10"
133    return
134fi
135if [ -n $IPV4ADDR ]; then
136     IP=$IPV4ADDR
[8368c0d]137else
[71643c0]138    # Obtener direcciones IP.
139    if [ -n "$DEVICE" ]; then
140        IP=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{if ($3~/inet$/) {printf ("%s ", $4)}}')
141    else
142        IP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
143    fi
[8368c0d]144fi
[71643c0]145# Mostrar solo la primera.
146echo ${IP%%/*}       # (comentario para Doxygen) */
[e0f3634]147}
148
149
150#/**
151#         ogGetMacAddress
152#@brief   Muestra la dirección Ethernet del cliente.
153#@return  str_ether - Dirección Ethernet
[fb8c54b]154#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]155#@author  Ramon Gomez, ETSII Universidad de Sevilla
156#@date    2010-02-11
[71643c0]157#@version 1.0.2 - Soporte para varias tarjetas de red
158#@author  Ramon Gomez, ETSII Universidad de Sevilla
159#@date    2011-06-17
[e0f3634]160#*/ ##
161function ogGetMacAddress ()
162{
163local MAC
[71643c0]164if [ "$*" == "help" ]; then
165    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  00:11:22:33:44:55"
166    return
167fi
[e0f3634]168# Obtener direcciones Ethernet.
[71643c0]169if [ -n "$DEVICE" ]; then
170    MAC=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
171else
172    MAC=$(ip -o address show up | awk '$2!~/lo/ {sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
173fi
[e0f3634]174# Mostrar sólo la primera.
175echo ${MAC%% *}
176}
177
[fb8c54b]178
179#/**
180#         ogGetRepoIp
181#@brief   Muestra la dirección IP del repositorio de datos.
182#@return  str_ip - Dirección IP
183#@version 0.10 - Integración en OpenGnSys 0.10
184#@author  Ramon Gomez, ETSII Universidad de Sevilla
185#@date    2011-01-13
[bd27de2]186#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
187#@note   Comprobacion segun protocolo de conexion al Repo
188#@author  Antonio J. Doblas Viso. Universidad de Malaga.
189#@date    2011-02-24
[fb8c54b]190#*/ ##
191function ogGetRepoIp ()
192{
[71643c0]193if [ "$*" == "help" ]; then
194    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
195    return
196fi
[bd27de2]197# Obtener direcciones IP, segun el protocolo de montaje
[16919ef]198if [ -n "$OGIMG" ]; then
199    case "$ogprotocol" in
200        nfs)  mount | grep " on $OGIMG " | cut -f1 -d: ;;
201        smb)  mount | grep " on $OGIMG " | cut -f3 -d/ ;;
202    esac
203fi
[fb8c54b]204}
205
206
207#/**
208#         ogGetServerIp
209#@brief   Muestra la dirección IP del Servidor de OpenGnSys.
210#@return  str_ip - Dirección IP
211#@version 0.10 - Integración en OpenGnSys 0.10
212#@author  Ramon Gomez, ETSII Universidad de Sevilla
213#@date    2011-01-13
[bd27de2]214#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
215#@note   Comprobacion segun protocolo de conexion al Repo
216#@author  Antonio J. Doblas Viso. Universidad de Malaga.
217#@date    2011-02-24
[fb8c54b]218#*/ ##
219function ogGetServerIp ()
220{
[71643c0]221if [ "$*" == "help" ]; then
222    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
223    return
224fi
[fb8c54b]225# Obtener direcciones IP.
[71643c0]226if [ -n "$OPENGNSYS" ]; then
[16919ef]227    case "$ogprotocol" in
228        nfs)  mount | grep " on $OPENGNSYS " | cut -f1 -d: ;;
229        smb)  mount | grep " on $OPENGNSYS " | cut -f3 -d/ ;;
230    esac
231fi
[fb8c54b]232}
233
Note: See TracBrowser for help on using the repository browser.