source: client/engine/Net.lib @ 5b825b50

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 5b825b50 was d891c09, checked in by irina <irinagomez@…>, 9 years ago

#724 En el nuevo cliente el inicio de la primera partición logica es el de la extendida más 4x512

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

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