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
RevLine 
[e0f3634]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.
[f48b8f9]7#@version  1.0.2
[e0f3634]8#@warning  License: GNU GPLv3+
9#*/
10
11
12#/**
[fea70bf]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{
[e4dafd6]57if [ "$*" == "help" ]; then
58    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME Grupo1"
59    return
60fi
[fea70bf]61[ -n "$group" ] && echo "$group"
62}
63
64
65#/**
[e0f3634]66#         ogGetHostname
67#@brief   Muestra el nombre del cliente.
68#@return  str_host - nombre de máquina
[fb8c54b]69#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]70#@author  Ramon Gomez, ETSII Universidad de Sevilla
71#@date    2010-02-11
72#*/ ##
73function ogGetHostname ()
74{
75local HOST
[0bfbbe1]76# Tomar nombre de la variable HOSTNAME
[e0f3634]77HOST="$HOSTNAME"
[0bfbbe1]78# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
[e0f3634]79[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
80                                   END {print host}
81                                  ' /var/lib/dhcp3/dhclient.leases)
[0bfbbe1]82# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
[e0f3634]83[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
84                              $1~/hostname/ {print $2}' /proc/cmdline)
85[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
[fea70bf]86[ -n "$HOST" ] && echo $HOST
[e0f3634]87}
88
89
90#/**
[bd27de2]91#         ogGetNetInterface
92#@brief   Muestra la interfaz de red del sistema
[f48b8f9]93#@return  str_interface - interfaz de red
[bd27de2]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{
[fea70bf]101[ -n "$DEVICE" ] && echo $DEVICE
[bd27de2]102}
103
104
105#/**
[e0f3634]106#         ogGetIpAddress
107#@brief   Muestra la dirección IP del sistema
108#@return  str_ip - Dirección IP
[fb8c54b]109#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]110#@author  Ramon Gomez, ETSII Universidad de Sevilla
111#@date    2010-02-11
[8368c0d]112#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
[bd27de2]113#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
[8368c0d]114#@author  Antonio J. Doblas Viso. Universidad de Malaga.
115#@date    2011-02-24
[f48b8f9]116#@version 1.0.2 - Soporte para varias tarjetas de red
117#@author  Ramon Gomez, ETSII Universidad de Sevilla
118#@date    2011-06-17
[e0f3634]119#*/ ##
120function ogGetIpAddress ()
121{
122local IP
[f48b8f9]123if [ -n $IPV4ADDR ]; then
124     IP=$IPV4ADDR
[8368c0d]125else
[f48b8f9]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
[8368c0d]132fi
[f48b8f9]133# Mostrar solo la primera.
134echo ${IP%%/*}       # (comentario para Doxygen) */
[e0f3634]135}
136
137
138#/**
139#         ogGetMacAddress
140#@brief   Muestra la dirección Ethernet del cliente.
141#@return  str_ether - Dirección Ethernet
[fb8c54b]142#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]143#@author  Ramon Gomez, ETSII Universidad de Sevilla
144#@date    2010-02-11
[f48b8f9]145#@version 1.0.2 - Soporte para varias tarjetas de red
146#@author  Ramon Gomez, ETSII Universidad de Sevilla
147#@date    2011-06-17
[e0f3634]148#*/ ##
149function ogGetMacAddress ()
150{
151local MAC
152# Obtener direcciones Ethernet.
[f48b8f9]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
[e0f3634]158# Mostrar sólo la primera.
159echo ${MAC%% *}
160}
161
[fb8c54b]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
[bd27de2]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
[fb8c54b]174#*/ ##
175function ogGetRepoIp ()
176{
[bd27de2]177# Obtener direcciones IP, segun el protocolo de montaje
[16919ef]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
[fb8c54b]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
[bd27de2]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
[fb8c54b]198#*/ ##
199function ogGetServerIp ()
200{
201# Obtener direcciones IP.
[71b9d337]202if [ -n "$OPENGNSYS" ]; then
[16919ef]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
[fb8c54b]208}
209
Note: See TracBrowser for help on using the repository browser.