source: client/engine/Net.lib @ 62ff8b7

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 62ff8b7 was fe6843b, checked in by irina <irinagomez@…>, 10 years ago

#679 Cambio Repo: script de clonación y librerías de imagenes monolíticas comprobados con todos los protocolos

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

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