source: client/engine/Net.lib @ 744ecd6

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 744ecd6 was f864c82, checked in by irina <irinagomez@…>, 8 years ago

#786 #678 #781 Adaptación al cliente ogLive-precise-3.2.0: en ogMcastSyntax se modifican opciones de udp-receiver y en ogChangeRepo de df.

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

  • Property mode set to 100755
File size: 9.6 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.
[aab6c6e]7#@version  1.0.6
[e0f3634]8#@warning  License: GNU GPLv3+
9#*/
10
11
12#/**
[fe6843b]13# ogChangeRepo  IPREPO [ OgUnit ]
14#@brief   Cambia el repositorio para el recurso remoto images.
15#@param 1 Ip Repositorio
16#@param 2 Abreviatura Unidad Organizativa
17#@return  Cambio recurso remoto en OGIMG.
18#@version 1.1 - Primera versión para OpenGnSys.
19#@author  Irina Gomez, ETSII Universidad de Sevilla
20#@date    2015-06-16
21#*/
22function ogChangeRepo {
[1e30a64]23local SRCIMG NEWREPO REPO OGUNIT
[fe6843b]24
25if [ "$*" == "help" ]; then
26    ogHelp "$FUNCNAME" "$FUNCNAME IPREPO [ OgUnit ]" \
27           "$FUNCNAME 10.1.120.3" \
28           "$FUNCNAME 10.1.120.3 cdc"
29    return
30fi
31
32
33if [ $# -lt 1 ]; then
34    ogRaiseError $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME IPREPO [ OgUnit ]"
35    return $?
36fi
37
38
[1e30a64]39# Si REPO tomamos el repositorio y la unidad organizativa actual
40REPO=$(ogGetRepoIp)
[f864c82]41OGUNIT="$(df | awk -F " " '/oglog/ {sub("//.*/oglog","",$1); sub("/","",$1);  print $1}')"
[1e30a64]42
43# Parametros de entrada. Si $1 = "REPO" dejo el repositorio actual
44[ "${1^^}" == "REPO" ] && NEWREPO="$REPO" || NEWREPO="${1}"
45
[cead9e3]46# Si $1 y $2 son el repositorio y la OU actual me salgo
[1e30a64]47[ "$NEWREPO" == "$REPO" ] && [ "$2" == "$OGUNIT" ]  && return 0
[cead9e3]48
[fe6843b]49source /scripts/functions
50source /scripts/ogfunctions
51umount $OGIMG
52[ "$2" == "" ] && SRCIMG="ogimages" || SRCIMG="ogimages/$2"
53eval $(grep "OPTIONS=" /scripts/ogfunctions)
54[ "$ogactiveadmin" == "true" ] && RW=",rw" || RW=",ro"
[cead9e3]55
[1e30a64]56ogEcho session log "$MSG_HELP_ogChangeRepo $NEWREPO ${2%/}"
57ogConnect $NEWREPO $ogprotocol $SRCIMG $OGIMG $RW
[fe6843b]58
[cead9e3]59# Si da error volvemos a montar el inicial
60if [ $? -ne 0 ]; then
[1e30a64]61    ogConnect $REPO $ogprotocol $SRCIMG $OGIMG $RW
62    ogRaiseError session $OG_ERR_REPO "$NEWREPO"
[cead9e3]63    return $?
64fi
65
[fe6843b]66}
67
68
69#/**
[fea70bf]70#         ogGetGroupDir [ str_repo ]
[d891c09]71#@brief   Devuelve el camino del directorio para el grupo del cliente.
[fea70bf]72#@param   str_repo     repositorio de imágenes (opcional)
73#@return  path_dir  -  Camino al directorio del grupo.
74#@note    repo = { REPO, CACHE }     REPO por defecto
75#@exception OG_ERR_FORMAT    formato incorrecto.
76#@version 1.0.2 - Primera versión para OpenGnSys.
77#@author  Ramon Gomez, ETSII Universidad de Sevilla
78#@date    2011-10-03
79#*/
80function ogGetGroupDir ()
81{
82local REPO DIR GROUP
83if [ "$*" == "help" ]; then
84    ogHelp "$FUNCNAME" "$FUNCNAME str_repo" \
85           "$FUNCNAME REPO  ==>  /opt/opengnsys/images/groups/Grupo1"
86    return
87fi
88# Error si se recibe más de 1 parámetro.
89case $# in
90    0)  REPO="REPO" ;;
91    1)  REPO="$1" ;;
92    *)  ogRaiseError $OG_ERR_FORMAT "$*"
93        return $? ;;
94esac
95
96GROUP="$(ogGetGroupName)"
97if [ -n "$GROUP" ]; then
98    DIR=$(ogGetPath "$REPO" "/groups/$GROUP" 2>/dev/null)
99    [ -d "$DIR" ] && echo "$DIR"
100fi
[d891c09]101# Para que no haya error al fallar la condición anterior
102return 0
[fea70bf]103}
104
105
106#/**
107#         ogGetGroupName
108#@brief   Devuelve el nombre del grupo al que pertenece el cliente.
109#@return  str_group - Nombre de grupo.
110#@version 1.0.2 - Primera versión para OpenGnSys.
111#@author  Ramon Gomez, ETSII Universidad de Sevilla
112#@date    2011-10-03
113#*/
114function ogGetGroupName ()
115{
[e4dafd6]116if [ "$*" == "help" ]; then
[1cd64e6]117    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  Grupo1"
[e4dafd6]118    return
119fi
[fea70bf]120[ -n "$group" ] && echo "$group"
121}
122
123
124#/**
[e0f3634]125#         ogGetHostname
126#@brief   Muestra el nombre del cliente.
127#@return  str_host - nombre de máquina
[fb8c54b]128#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]129#@author  Ramon Gomez, ETSII Universidad de Sevilla
130#@date    2010-02-11
131#*/ ##
132function ogGetHostname ()
133{
134local HOST
[1cd64e6]135if [ "$*" == "help" ]; then
136    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  pc1"
137    return
138fi
[0bfbbe1]139# Tomar nombre de la variable HOSTNAME
[e0f3634]140HOST="$HOSTNAME"
[0bfbbe1]141# Si no, tomar del DHCP, opción host-name       /* (comentario para Doxygen)
[e0f3634]142[ -z "$HOST" ] && HOST=$(awk -F\" '/option host-name/ {gsub(/;/,""); host=$2}
143                                   END {print host}
144                                  ' /var/lib/dhcp3/dhclient.leases)
[0bfbbe1]145# Si no, leer el parámetro del kernel hostname  (comentario para Doxygen) */
[e0f3634]146[ -z "$HOST" ] && HOST=$(awk 'BEGIN {RS=""; FS="="}
147                              $1~/hostname/ {print $2}' /proc/cmdline)
148[ "$HOSTNAME" != "$HOST" ] && export HOSTNAME="$HOST"
[fea70bf]149[ -n "$HOST" ] && echo $HOST
[e0f3634]150}
151
152
153#/**
154#         ogGetIpAddress
155#@brief   Muestra la dirección IP del sistema
156#@return  str_ip - Dirección IP
[fb8c54b]157#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]158#@author  Ramon Gomez, ETSII Universidad de Sevilla
159#@date    2010-02-11
[8368c0d]160#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
[bd27de2]161#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
[8368c0d]162#@author  Antonio J. Doblas Viso. Universidad de Malaga.
163#@date    2011-02-24
[f48b8f9]164#@version 1.0.2 - Soporte para varias tarjetas de red
165#@author  Ramon Gomez, ETSII Universidad de Sevilla
166#@date    2011-06-17
[e0f3634]167#*/ ##
168function ogGetIpAddress ()
169{
170local IP
[1cd64e6]171if [ "$*" == "help" ]; then
172    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.10"
173    return
174fi
[c6afc2d]175if [ -n "$IPV4ADDR" ]; then
176     IP="$IPV4ADDR"
[8368c0d]177else
[f48b8f9]178    # Obtener direcciones IP.
179    if [ -n "$DEVICE" ]; then
180        IP=$(ip -o address show up dev "$DEVICE" 2>/dev/null | awk '{if ($3~/inet$/) {printf ("%s ", $4)}}')
181    else
182        IP=$(ip -o address show up | awk '$2!~/lo/ {if ($3~/inet$/) {printf ("%s ", $4)}}')
183    fi
[8368c0d]184fi
[f48b8f9]185# Mostrar solo la primera.
[c6afc2d]186echo "${IP%%/*}"       # (comentario para Doxygen) */
[e0f3634]187}
188
189
190#/**
191#         ogGetMacAddress
192#@brief   Muestra la dirección Ethernet del cliente.
193#@return  str_ether - Dirección Ethernet
[fb8c54b]194#@version 0.10 - Integración en OpenGnSys 0.10
[e0f3634]195#@author  Ramon Gomez, ETSII Universidad de Sevilla
196#@date    2010-02-11
[f48b8f9]197#@version 1.0.2 - Soporte para varias tarjetas de red
198#@author  Ramon Gomez, ETSII Universidad de Sevilla
199#@date    2011-06-17
[e0f3634]200#*/ ##
201function ogGetMacAddress ()
202{
203local MAC
[1cd64e6]204if [ "$*" == "help" ]; then
205    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  00:11:22:33:44:55"
206    return
207fi
[e0f3634]208# Obtener direcciones Ethernet.
[f48b8f9]209if [ -n "$DEVICE" ]; then
[336557d]210    MAC=$(ip -o link show up dev "$DEVICE" 2>/dev/null | awk '{sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
[f48b8f9]211else
[336557d]212    MAC=$(ip -o link show up | awk '$2!~/lo/ {sub (/.*\\/, ""); if ($1~/ether/) printf ("%s ", toupper($2));}')
[f48b8f9]213fi
[e0f3634]214# Mostrar sólo la primera.
215echo ${MAC%% *}
216}
217
[fb8c54b]218
219#/**
[c6afc2d]220#         ogGetNetInterface
221#@brief   Muestra la interfaz de red del sistema
222#@return  str_interface - interfaz de red
223#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
224#@note    Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
225#@author  Antonio J. Doblas Viso. Universidad de Malaga.
226#@date    2011-02-24
227#*/ ##
228function ogGetNetInterface ()
229{
230if [ "$*" == "help" ]; then
231    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  eth0"
232    return
233fi
234[ -n "$DEVICE" ] && echo "$DEVICE"
235}
236
237
238#/**
[fb8c54b]239#         ogGetRepoIp
240#@brief   Muestra la dirección IP del repositorio de datos.
241#@return  str_ip - Dirección IP
242#@version 0.10 - Integración en OpenGnSys 0.10
243#@author  Ramon Gomez, ETSII Universidad de Sevilla
244#@date    2011-01-13
[bd27de2]245#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
246#@note   Comprobacion segun protocolo de conexion al Repo
247#@author  Antonio J. Doblas Viso. Universidad de Malaga.
248#@date    2011-02-24
[aab6c6e]249#@version 1.0.6 - Obtener datos del punto de montaje, evitando fallo si $ogprotocol está vacía.
250#@author  Ramon Gomez, ETSII Universidad de Sevilla
251#@date    2014-08-27
[fb8c54b]252#*/ ##
253function ogGetRepoIp ()
254{
[aab6c6e]255# Variables locales.
256local SOURCE FSTYPE
257
258# Mostrar ayuda.
[1cd64e6]259if [ "$*" == "help" ]; then
260    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
261    return
262fi
[aab6c6e]263
264# Obtener direcciones IP, según el tipo de montaje.
265eval $(findmnt -P -o SOURCE,FSTYPE $OGIMG)
266case "$FSTYPE" in
267    nfs)   echo "$SOURCE" | cut -f1 -d: ;;
268    cifs)  echo "$SOURCE" | cut -f3 -d/ ;;
269esac
[fb8c54b]270}
271
272
273#/**
274#         ogGetServerIp
275#@brief   Muestra la dirección IP del Servidor de OpenGnSys.
276#@return  str_ip - Dirección IP
277#@version 0.10 - Integración en OpenGnSys 0.10
278#@author  Ramon Gomez, ETSII Universidad de Sevilla
279#@date    2011-01-13
[bd27de2]280#@version 1.0 - Integración OpenGnSys 0.10 Opengnsys 0.10-testing
281#@note   Comprobacion segun protocolo de conexion al Repo
282#@author  Antonio J. Doblas Viso. Universidad de Malaga.
283#@date    2011-02-24
[aab6c6e]284#@version 1.0.6 - Obtener datos del punto de montaje, evitando fallo si $ogprotocol está vacía.
285#@author  Ramon Gomez, ETSII Universidad de Sevilla
286#@date    2014-08-27
[fb8c54b]287#*/ ##
288function ogGetServerIp ()
289{
[aab6c6e]290# Variables locales.
291local SOURCE FSTYPE
292
293# Mostrar ayuda.
[1cd64e6]294if [ "$*" == "help" ]; then
295    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME  =>  192.168.0.2"
296    return
297fi
[aab6c6e]298
299# Obtener direcciones IP, según el tipo de montaje.
300eval $(findmnt -P -o SOURCE,FSTYPE $OPENGNSYS)
301case "$FSTYPE" in
302    nfs)   echo "$SOURCE" | cut -f1 -d: ;;
303    cifs)  echo "$SOURCE" | cut -f3 -d/ ;;
304esac
[fb8c54b]305}
306
[336557d]307
308#/**
309#         ogMakeGroupDir [ str_repo ]
310#@brief   Crea el directorio para el grupo del cliente.
311#@param   str_repo     repositorio de imágenes (opcional)
312#@return  (nada)
313#@note    repo = { REPO, CACHE }     REPO por defecto
314#@exception OG_ERR_FORMAT    formato incorrecto.
315#@version 1.0.5 - Primera versión para OpenGnSys.
316#@author  Ramon Gomez, ETSII Universidad de Sevilla
317#@date    2013-09-26
318#*/
319function ogMakeGroupDir ()
320{
321local REPO DIR GROUP
322if [ "$*" == "help" ]; then
323    ogHelp "$FUNCNAME" "$FUNCNAME str_repo" \
324           "$FUNCNAME" "$FUNCNAME REPO"
325    return
326fi
327# Error si se recibe más de 1 parámetro.
328case $# in
329    0)  REPO="REPO" ;;
330    1)  REPO="$1" ;;
331    *)  ogRaiseError $OG_ERR_FORMAT "$*"
332        return $? ;;
333esac
334# Comprobar tipo de repositorio.
335DIR=$(ogGetPath "$REPO" / 2>/dev/null)
336[ -n "$DIR" ] || ogRaiseError $OG_ERR_FORMAT "$1"
337GROUP="$(ogGetGroupName)"
338if [ -n "$GROUP" ]; then
339    mkdir -p "$DIR/groups/$GROUP" 2>/dev/null
340fi
341}
342
Note: See TracBrowser for help on using the repository browser.