source: client/engine/Net.lib @ a0da76f

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

Versión 1.0.2: Continuar depurando el motor de clonación:

  • Revisar variables locales.
  • Ayudas de las funciones.
  • Incluir fecha y hora en mensajes de logs.

Modifica ticket #446.

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

  • Property mode set to 100755
File size: 6.6 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
76if [ "$*" == "help" ]; then
77    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  pc1"
78    return
79fi
80# Tomar nombre de la variable HOSTNAME
81HOST="$HOSTNAME"
82# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
83[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
84                                   END {print host}
85                                  ' /var/lib/dhcp3/dhclient.leases)
86# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
87[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
88                              $1~/hostname/ {print $2}' /proc/cmdline)
89[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
90[ -n "$HOST" ] && echo $HOST
91}
92
93
94#/**
95#         ogGetNetInterface
96#@brief   Muestra la interfaz de red del sistema
97#@return  str_interface - interfaz de red
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{
105if [ "$*" == "help" ]; then
106    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  eth0"
107    return
108fi
109[ -n "$DEVICE" ] && echo "$DEVICE"
110}
111
112
113#/**
114#         ogGetIpAddress
115#@brief   Muestra la dirección IP del sistema
116#@return  str_ip - Dirección IP
117#@version 0.10 - Integración en OpenGnSys 0.10
118#@author  Ramon Gomez, ETSII Universidad de Sevilla
119#@date    2010-02-11
120#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
121#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
122#@author  Antonio J. Doblas Viso. Universidad de Malaga.
123#@date    2011-02-24
124#@version 1.0.2 - Soporte para varias tarjetas de red
125#@author  Ramon Gomez, ETSII Universidad de Sevilla
126#@date    2011-06-17
127#*/ ##
128function ogGetIpAddress ()
129{
130local IP
131if [ "$*" == "help" ]; then
132    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.10"
133    return
134fi
135if [ -n $IPV4ADDR ]; then
136     IP=$IPV4ADDR
137else
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
144fi
145# Mostrar solo la primera.
146echo ${IP%%/*}       # (comentario para Doxygen) */
147}
148
149
150#/**
151#         ogGetMacAddress
152#@brief   Muestra la dirección Ethernet del cliente.
153#@return  str_ether - Dirección Ethernet
154#@version 0.10 - Integración en OpenGnSys 0.10
155#@author  Ramon Gomez, ETSII Universidad de Sevilla
156#@date    2010-02-11
157#@version 1.0.2 - Soporte para varias tarjetas de red
158#@author  Ramon Gomez, ETSII Universidad de Sevilla
159#@date    2011-06-17
160#*/ ##
161function ogGetMacAddress ()
162{
163local MAC
164if [ "$*" == "help" ]; then
165    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  00:11:22:33:44:55"
166    return
167fi
168# Obtener direcciones Ethernet.
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
174# Mostrar sólo la primera.
175echo ${MAC%% *}
176}
177
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
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
190#*/ ##
191function ogGetRepoIp ()
192{
193if [ "$*" == "help" ]; then
194    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
195    return
196fi
197# Obtener direcciones IP, segun el protocolo de montaje
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
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
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
218#*/ ##
219function ogGetServerIp ()
220{
221if [ "$*" == "help" ]; then
222    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
223    return
224fi
225# Obtener direcciones IP.
226if [ -n "$OPENGNSYS" ]; then
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
232}
233
Note: See TracBrowser for help on using the repository browser.