source: client/engine/Net.lib @ 46f7d6f

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 46f7d6f was 336557d, checked in by ramon <ramongomez@…>, 12 years ago

Solucionada una errata de función ogGetMacAddress; nueva función ogMakeGroupDir para crear en repositorio el directorio común para los clientes del mismo grupo.

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

  • Property mode set to 100755
File size: 7.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#         ogGetIpAddress
96#@brief   Muestra la dirección IP del sistema
97#@return  str_ip - Dirección IP
98#@version 0.10 - Integración en OpenGnSys 0.10
99#@author  Ramon Gomez, ETSII Universidad de Sevilla
100#@date    2010-02-11
101#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
102#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
103#@author  Antonio J. Doblas Viso. Universidad de Malaga.
104#@date    2011-02-24
105#@version 1.0.2 - Soporte para varias tarjetas de red
106#@author  Ramon Gomez, ETSII Universidad de Sevilla
107#@date    2011-06-17
108#*/ ##
109function ogGetIpAddress ()
110{
111local IP
112if [ "$*" == "help" ]; then
113    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.10"
114    return
115fi
116if [ -n "$IPV4ADDR" ]; then
117     IP="$IPV4ADDR"
118else
119    # Obtener direcciones IP.
120    if [ -n "$DEVICE" ]; then
121        IP=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{if ($3~/inet$/) {printf ("%s ", $4)}}')
122    else
123        IP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
124    fi
125fi
126# Mostrar solo la primera.
127echo "${IP%%/*}"       # (comentario para Doxygen) */
128}
129
130
131#/**
132#         ogGetMacAddress
133#@brief   Muestra la dirección Ethernet del cliente.
134#@return  str_ether - Dirección Ethernet
135#@version 0.10 - Integración en OpenGnSys 0.10
136#@author  Ramon Gomez, ETSII Universidad de Sevilla
137#@date    2010-02-11
138#@version 1.0.2 - Soporte para varias tarjetas de red
139#@author  Ramon Gomez, ETSII Universidad de Sevilla
140#@date    2011-06-17
141#*/ ##
142function ogGetMacAddress ()
143{
144local MAC
145if [ "$*" == "help" ]; then
146    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  00:11:22:33:44:55"
147    return
148fi
149# Obtener direcciones Ethernet.
150if [ -n "$DEVICE" ]; then
151    MAC=$(ip -o link show up dev "$DEVICE" 2>/dev/null | awk '{sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
152else
153    MAC=$(ip -o link show up | awk '$2!~/lo/ {sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
154fi
155# Mostrar sólo la primera.
156echo ${MAC%% *}
157}
158
159
160#/**
161#         ogGetNetInterface
162#@brief   Muestra la interfaz de red del sistema
163#@return  str_interface - interfaz de red
164#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
165#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
166#@author  Antonio J. Doblas Viso. Universidad de Malaga.
167#@date    2011-02-24
168#*/ ##
169function ogGetNetInterface ()
170{
171if [ "$*" == "help" ]; then
172    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  eth0"
173    return
174fi
175[ -n "$DEVICE" ] && echo "$DEVICE"
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
234
235#/**
236#         ogMakeGroupDir [ str_repo ]
237#@brief   Crea el directorio para el grupo del cliente.
238#@param   str_repo     repositorio de imágenes (opcional)
239#@return  (nada)
240#@note    repo = { REPO, CACHE }     REPO por defecto
241#@exception OG_ERR_FORMAT    formato incorrecto.
242#@version 1.0.5 - Primera versión para OpenGnSys.
243#@author  Ramon Gomez, ETSII Universidad de Sevilla
244#@date    2013-09-26
245#*/
246function ogMakeGroupDir ()
247{
248local REPO DIR GROUP
249if [ "$*" == "help" ]; then
250    ogHelp "$FUNCNAME" "$FUNCNAME str_repo" \
251           "$FUNCNAME" "$FUNCNAME REPO"
252    return
253fi
254# Error si se recibe más de 1 parámetro.
255case $# in
256    0)  REPO="REPO" ;;
257    1)  REPO="$1" ;;
258    *)  ogRaiseError $OG_ERR_FORMAT "$*"
259        return $? ;;
260esac
261# Comprobar tipo de repositorio.
262DIR=$(ogGetPath "$REPO" / 2>/dev/null)
263[ -n "$DIR" ] || ogRaiseError $OG_ERR_FORMAT "$1"
264GROUP="$(ogGetGroupName)"
265if [ -n "$GROUP" ]; then
266    mkdir -p "$DIR/groups/$GROUP" 2>/dev/null
267fi
268}
269
Note: See TracBrowser for help on using the repository browser.