source: client/engine/Net.lib @ a37e5fc4

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 a37e5fc4 was 1928687, checked in by irina <irinagomez@…>, 7 years ago

#678 Con directorios de OU separados se resuelve errata de r5447 por la que al crear imagen en modo usuario no permite montar el repo en modo escritura.

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

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