source: client/engine/Net.lib @ e4dafd6

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

Versión 1.0.2: continuar revisando variables locales y ayudas de las funciones del motor de clonación (modifica #446).

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

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