source: client/engine/Net.lib @ cd95622

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 cd95622 was 71b9d337, checked in by adv <adv@…>, 14 years ago

version 1.0.2 #423 ver changeset:2134 - (cambio sugerido por Migual Angel de Vega, UHU)

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

  • Property mode set to 100755
File size: 4.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#         ogGetHostname
14#@brief   Muestra el nombre del cliente.
15#@return  str_host - nombre de máquina
16#@version 0.10 - Integración en OpenGnSys 0.10
17#@author  Ramon Gomez, ETSII Universidad de Sevilla
18#@date    2010-02-11
19#*/ ##
20function ogGetHostname ()
21{
22local HOST
23# Tomar nombre de la variable HOSTNAME
24HOST="$HOSTNAME"
25# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
26[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
27                                   END {print host}
28                                  ' /var/lib/dhcp3/dhclient.leases)
29# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
30[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
31                              $1~/hostname/ {print $2}' /proc/cmdline)
32[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
33echo $HOST
34}
35
36
37#/**
38#         ogGetNetInterface
39#@brief   Muestra la interfaz de red del sistema
40#@return  str_interface - interfaz de red
41#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
42#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
43#@author  Antonio J. Doblas Viso. Universidad de Malaga.
44#@date    2011-02-24
45#*/ ##
46function ogGetNetInterface ()
47{
48echo $DEVICE
49}
50
51
52#/**
53#         ogGetIpAddress
54#@brief   Muestra la dirección IP del sistema
55#@return  str_ip - Dirección IP
56#@version 0.10 - Integración en OpenGnSys 0.10
57#@author  Ramon Gomez, ETSII Universidad de Sevilla
58#@date    2010-02-11
59#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
60#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
61#@author  Antonio J. Doblas Viso. Universidad de Malaga.
62#@date    2011-02-24
63#@version 1.0.2 - Soporte para varias tarjetas de red
64#@author  Ramon Gomez, ETSII Universidad de Sevilla
65#@date    2011-06-17
66#*/ ##
67function ogGetIpAddress ()
68{
69local IP
70if [ -n $IPV4ADDR ]; then
71     IP=$IPV4ADDR
72else
73    # Obtener direcciones IP.
74    if [ -n "$DEVICE" ]; then
75        IP=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{if ($3~/inet$/) {printf ("%s ", $4)}}')
76    else
77        IP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
78    fi
79fi
80# Mostrar solo la primera.
81echo ${IP%%/*}       # (comentario para Doxygen) */
82}
83
84
85#/**
86#         ogGetMacAddress
87#@brief   Muestra la dirección Ethernet del cliente.
88#@return  str_ether - Dirección Ethernet
89#@version 0.10 - Integración en OpenGnSys 0.10
90#@author  Ramon Gomez, ETSII Universidad de Sevilla
91#@date    2010-02-11
92#@version 1.0.2 - Soporte para varias tarjetas de red
93#@author  Ramon Gomez, ETSII Universidad de Sevilla
94#@date    2011-06-17
95#*/ ##
96function ogGetMacAddress ()
97{
98local MAC
99# Obtener direcciones Ethernet.
100if [ -n "$DEVICE" ]; then
101    MAC=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
102else
103    MAC=$(ip -o address show up | awk '$2!~/lo/ {sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
104fi
105# Mostrar sólo la primera.
106echo ${MAC%% *}
107}
108
109
110#/**
111#         ogGetRepoIp
112#@brief   Muestra la dirección IP del repositorio de datos.
113#@return  str_ip - Dirección IP
114#@version 0.10 - Integración en OpenGnSys 0.10
115#@author  Ramon Gomez, ETSII Universidad de Sevilla
116#@date    2011-01-13
117#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
118#@note   Comprobacion segun protocolo de conexion al Repo
119#@author  Antonio J. Doblas Viso. Universidad de Malaga.
120#@date    2011-02-24
121#*/ ##
122function ogGetRepoIp ()
123{
124# Obtener direcciones IP, segun el protocolo de montaje
125if [ -n "$OGIMG" ]; then
126    case "$ogprotocol" in
127        nfs)  mount | grep " on $OGIMG " | cut -f1 -d: ;;
128        smb)  mount | grep " on $OGIMG " | cut -f3 -d/ ;;
129    esac
130fi
131}
132
133
134#/**
135#         ogGetServerIp
136#@brief   Muestra la dirección IP del Servidor de OpenGnSys.
137#@return  str_ip - Dirección IP
138#@version 0.10 - Integración en OpenGnSys 0.10
139#@author  Ramon Gomez, ETSII Universidad de Sevilla
140#@date    2011-01-13
141#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
142#@note   Comprobacion segun protocolo de conexion al Repo
143#@author  Antonio J. Doblas Viso. Universidad de Malaga.
144#@date    2011-02-24
145#*/ ##
146function ogGetServerIp ()
147{
148# Obtener direcciones IP.
149if [ -n "$OPENGNSYS" ]; then
150    case "$ogprotocol" in
151        nfs)  mount | grep " on $OPENGNSYS " | cut -f1 -d: ;;
152        smb)  mount | grep " on $OPENGNSYS " | cut -f3 -d/ ;;
153    esac
154fi
155}
156
Note: See TracBrowser for help on using the repository browser.