source: client/engine/Net.lib @ 99d1786

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 99d1786 was fea70bf, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: nuevas funciones ogGetGroupName y ogGetGroupDir; corregir pequeña errata en comando setclientmode (modifica #427 y #444)

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

  • Property mode set to 100755
File size: 5.9 KB
Line 
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.
7#@version  1.0.2
8#@warning  License: GNU GPLv3+
9#*/
10
11
12#/**
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{
57[ -n "$group" ] && echo "$group"
58}
59
60
61#/**
62#         ogGetHostname
63#@brief   Muestra el nombre del cliente.
64#@return  str_host - nombre de máquina
65#@version 0.10 - Integración en OpenGnSys 0.10
66#@author  Ramon Gomez, ETSII Universidad de Sevilla
67#@date    2010-02-11
68#*/ ##
69function ogGetHostname ()
70{
71local HOST
72# Tomar nombre de la variable HOSTNAME
73HOST="$HOSTNAME"
74# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
75[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
76                                   END {print host}
77                                  ' /var/lib/dhcp3/dhclient.leases)
78# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
79[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
80                              $1~/hostname/ {print $2}' /proc/cmdline)
81[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
82[ -n "$HOST" ] && echo $HOST
83}
84
85
86#/**
87#         ogGetNetInterface
88#@brief   Muestra la interfaz de red del sistema
89#@return  str_interface - interfaz de red
90#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
91#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
92#@author  Antonio J. Doblas Viso. Universidad de Malaga.
93#@date    2011-02-24
94#*/ ##
95function ogGetNetInterface ()
96{
97[ -n "$DEVICE" ] && echo $DEVICE
98}
99
100
101#/**
102#         ogGetIpAddress
103#@brief   Muestra la dirección IP del sistema
104#@return  str_ip - Dirección IP
105#@version 0.10 - Integración en OpenGnSys 0.10
106#@author  Ramon Gomez, ETSII Universidad de Sevilla
107#@date    2010-02-11
108#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
109#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
110#@author  Antonio J. Doblas Viso. Universidad de Malaga.
111#@date    2011-02-24
112#@version 1.0.2 - Soporte para varias tarjetas de red
113#@author  Ramon Gomez, ETSII Universidad de Sevilla
114#@date    2011-06-17
115#*/ ##
116function ogGetIpAddress ()
117{
118local IP
119if [ -n $IPV4ADDR ]; then
120     IP=$IPV4ADDR
121else
122    # Obtener direcciones IP.
123    if [ -n "$DEVICE" ]; then
124        IP=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{if ($3~/inet$/) {printf ("%s ", $4)}}')
125    else
126        IP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
127    fi
128fi
129# Mostrar solo la primera.
130echo ${IP%%/*}       # (comentario para Doxygen) */
131}
132
133
134#/**
135#         ogGetMacAddress
136#@brief   Muestra la dirección Ethernet del cliente.
137#@return  str_ether - Dirección Ethernet
138#@version 0.10 - Integración en OpenGnSys 0.10
139#@author  Ramon Gomez, ETSII Universidad de Sevilla
140#@date    2010-02-11
141#@version 1.0.2 - Soporte para varias tarjetas de red
142#@author  Ramon Gomez, ETSII Universidad de Sevilla
143#@date    2011-06-17
144#*/ ##
145function ogGetMacAddress ()
146{
147local MAC
148# Obtener direcciones Ethernet.
149if [ -n "$DEVICE" ]; then
150    MAC=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
151else
152    MAC=$(ip -o address show up | awk '$2!~/lo/ {sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
153fi
154# Mostrar sólo la primera.
155echo ${MAC%% *}
156}
157
158
159#/**
160#         ogGetRepoIp
161#@brief   Muestra la dirección IP del repositorio de datos.
162#@return  str_ip - Dirección IP
163#@version 0.10 - Integración en OpenGnSys 0.10
164#@author  Ramon Gomez, ETSII Universidad de Sevilla
165#@date    2011-01-13
166#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
167#@note   Comprobacion segun protocolo de conexion al Repo
168#@author  Antonio J. Doblas Viso. Universidad de Malaga.
169#@date    2011-02-24
170#*/ ##
171function ogGetRepoIp ()
172{
173# Obtener direcciones IP, segun el protocolo de montaje
174if [ -n "$OGIMG" ]; then
175    case "$ogprotocol" in
176        nfs)  mount | grep " on $OGIMG " | cut -f1 -d: ;;
177        smb)  mount | grep " on $OGIMG " | cut -f3 -d/ ;;
178    esac
179fi
180}
181
182
183#/**
184#         ogGetServerIp
185#@brief   Muestra la dirección IP del Servidor de OpenGnSys.
186#@return  str_ip - Dirección IP
187#@version 0.10 - Integración en OpenGnSys 0.10
188#@author  Ramon Gomez, ETSII Universidad de Sevilla
189#@date    2011-01-13
190#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
191#@note   Comprobacion segun protocolo de conexion al Repo
192#@author  Antonio J. Doblas Viso. Universidad de Malaga.
193#@date    2011-02-24
194#*/ ##
195function ogGetServerIp ()
196{
197# Obtener direcciones IP.
198if [ -n "$OPENGNSYS" ]; then
199    case "$ogprotocol" in
200        nfs)  mount | grep " on $OPENGNSYS " | cut -f1 -d: ;;
201        smb)  mount | grep " on $OPENGNSYS " | cut -f3 -d/ ;;
202    esac
203fi
204}
205
Note: See TracBrowser for help on using the repository browser.