source: client/boot-tools/includes/etc/initramfs-tools/scripts/ogfunctions @ ea7314e

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 ea7314e was 11694ea, checked in by ramon <ramongomez@…>, 11 years ago

Corregir errata al crear cliente ogLive cuando el fichero de configuración de red está en /tmp e instalar nuevos paquetes.

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

  • Property mode set to 100644
File size: 20.3 KB
Line 
1#/**
2#@file    ogfunctions.lib
3#@brief   Librería o clase para la gestion del sistema operativo de los clientes OpenGnSys.
4#@class   client
5#@version 1.0.5
6#@warning License: GNU GPLv3+
7#*/ ##
8
9
10#/**
11#        ogExportKernelParameters
12#@brief   Exporta los parametros pasados al kernel
13#@param   
14#@return 
15#@exception OG_ERR_FORMAT    Formato incorrecto.
16#@version 0.7 -
17#@author Antonio J. Doblas. Universidad de Malaga.
18#@date    2010/05/24
19#*/ ##
20ogExportKernelParameters ()
21{
22        GLOBAL="cat /proc/cmdline"
23        for i in `${GLOBAL}`
24        do
25                echo $i | grep "=" > /dev/null && export $i
26        done
27        return 0
28}
29
30
31#/**
32#         ogChangeVideoResolution
33#@brief   Cambia la resolución de vídeo utilizando el parámetro "video" del Kernel
34#         (sustituye al parámetro "vga").
35#@note    Formato del parámetro vídeo:    video=DRIVER:RESXxRESY-BITS
36#@note    El valor por defecto es:        video=uvesafb:640x480-16
37#@todo    Control de errores en el foramto de la variable "video".
38#@version 1.0.5 - Primera versión de la función.
39#@author  Ramón Gómez, ETSII Universidad de Sevilla
40#@date    2013/02/18
41#*/ ##
42ogChangeVideoResolution ()
43{
44# Variables locales.
45local DRIVER MODE
46# Obtener driver y resolución.
47DRIVER="$(echo $video|cut -f1 -d:)"
48MODE="$(echo $video|cut -f2 -d:)"
49case "$DRIVER" in
50        # Cambiar resolución para driver "uvesafb".
51        uvesafb)
52                grep ":$(echo $MODE|cut -f1 -d-)p" /sys/class/graphics/fb0/modes | head -1 > /sys/class/graphics/fb0/mode 2>&1 || MODE="640x480-16"
53                echo "$(echo $MODE|cut -f2 -d-)" > /sys/class/graphics/fb0/bits_per_pixel 2>&1
54                echo "Screen mode: $(cat /sys/class/graphics/fb0/mode),$(cat /sys/class/graphics/fb0/bits_per_pixel)bpp."
55        ;;
56        # Resolución por defecto para el resto de casos.
57        *)      echo "Unknown video driver, using default mode."
58        ;;
59esac
60}
61
62
63#/**
64#       ogExportVarEnvironment
65#@brief   Exporta las variables usadas en el proceso de inicio OpenGnsys y las almacena en /tmp
66#@param   
67#@return 
68#@exception OG_ERR_FORMAT    Formato incorrecto.
69#@version 0.9
70#@author Antonio J. Doblas. Universidad de Malaga.
71#@date    2011/05/24
72#*/ ##
73ogExportVarEnvironment ()
74{
75        export CFGINITRD="/tmp/initrd.cfg"     
76        OGPROTOCOL="${ogprotocol:-smb}"
77        case "$OGPROTOCOL" in
78                nfs|NFS)                       
79                        export SRCOGLIVE="/var/lib/tftpboot" && echo "SRCOGLIVE=$SRCOGLIVE" >> $CFGINITRD       
80                        export SRCOGSHARE="/opt/opengnsys/client" && echo "SRCOGSHARE=$SRCOGSHARE" >> $CFGINITRD
81                        export SRCOGLOG="/opt/opengnsys/log/clients" && echo "SRCOGLOG=$SRCOGLOG" >> $CFGINITRD
82                        export SRCOGIMAGES="/opt/opengnsys/images" && echo "SRCOGIMAGES=$SRCOGIMAGES" >> $CFGINITRD     
83                ;;
84                smb|SMB|cifs|CIFS|samba|SAMBA)
85                        export OPTIONS=" -o user=opengnsys,pass=og"
86                        export SRCOGLIVE="tftpboot"  && echo "SRCOGLIVE=$SRCOGLIVE" >> $CFGINITRD
87                        export SRCOGSHARE="ogclient" && echo "SRCOGSHARE=$SRCOGSHARE" >> $CFGINITRD
88                        export SRCOGLOG="oglog" && echo "SRCOGLOG=$SRCOGLOG" >> $CFGINITRD     
89                        export SRCOGIMAGES="ogimages" && echo "SRCOGIMAGES=$SRCOGIMAGES" >> $CFGINITRD
90                ;;
91                local|LOCAL)
92                        export SRCOGLIVE="local"
93                ;;
94        esac
95        #punto de acceso al boot-tools live
96        export DSTOGLIVE="/opt/oglive/tftpboot"
97        #punto de montaje para unionfs
98        export OGLIVERAMFS="/opt/oglive/ramfs" && echo "OGLIVERAMFS=$OGLIVERAMFS" >> $CFGINITRD
99        #punto de montaje donde se accede al 2nd FS mediante loop
100        export OGLIVEROOTFS="/opt/oglive/rootfs" && echo "OGLIVEROOTFS=$OGLIVEROOTFS" >> $CFGINITRD
101        #punto de union entre LOCALROOTIMG y LOCALROOTRAM
102        export OGLIVEUNIONFS="/opt/oglive/unionfs" && echo "OGLIVEUNIONFS=$OGLIVEUNIONFS" >> $CFGINITRD
103        #etiquta para los dispositivos offline
104        export OGLIVELABEL="ogClient"
105       
106        #echo "puntos de montajes para los demas accesos"
107        #echo "acceso al client, engine, scritps, interfaz"
108        export DSTOGSHARE="/opt/opengnsys" && echo "DSTOGSHARE=$DSTOGSHARE" >> $CFGINITRD               
109        export DSTOGLOG="/opt/opengnsys/log" && echo "DSTOGLOG=$DSTOGLOG" >> $CFGINITRD
110        export DSTOGIMAGES="/opt/opengnsys/images" && echo "DSTOGIMAGES=$DSTOGIMAGES" >> $CFGINITRD
111               
112        ##INFORMACION DE OTRAS VARIABLES OBTENDIAS EN OTRAS FUNCIONES ogConfigureNetwork.
113                #DEVICE
114                #IPV4DDR
115                #IPV4BROADCAST
116                #IPV4NETMASK
117                #IPV4GATEWAY
118                #HOSTNAME
119    #INFORMACION de otras variasbles obteneidas desde ogGetROOTSERVER
120                #ROOTSERVER  si ip=dhcp -> ROOTSERVER=NEXT-SERVER; si ip=host:rootserver:gw:mask:hostname:interfaz -> ROOTSERVER=rootserver
121                #BOOTIF -> si el gestor remoto es pxelinux.0 y se añade una linea más tipo "IPAPPEND 2" esta variable tendrá la mac de la interfaz.
122                #$OGSERVERLIVE
123                #$OGSERVERSHARE
124                #$OGSERVERLOG
125                #$OGSERVERIMAGES
126        return 0
127}
128
129
130#/**
131#       ogConfigureRamfs
132#@brief   Configura el initrd para adaptarlo al sistema raiz.
133#@param   
134#@return 
135#@exception OG_ERR_FORMAT    Formato incorrecto.
136#@version 0.9
137#@author Antonio J. Doblas. Universidad de Malaga.
138#@date    2010/05/24
139#*/ ##
140ogConfigureRamfs ()
141{
142        mkdir -p $DSTOGLIVE     
143        mkdir -p $OGLIVERAMFS   
144        mkdir -p $OGLIVEROOTFS                           
145        mkdir -p $OGLIVEUNIONFS
146
147        touch /etc/fstab
148}
149
150
151#/**
152#       ogLoadNetModule
153#@brief   Carga en un demerminado modulo de red, requiere compilación previo del modulo
154#@param   
155#@return 
156#@exception OG_ERR_FORMAT    Formato incorrecto.
157#@version 0.9
158#@author Antonio J. Doblas. Universidad de Malaga.
159#@date    2010/05/24
160#*/ ##
161ogLoadNetModule ()
162{
163        if [ -n "$ognetmodule" ]
164        then
165                echo "Cargando modulo de red $ognetmodule"
166                modprobe ${ognetmodule}
167        fi
168}
169
170
171#/**
172#      ogPostConfigureFS
173#@brief   Configura el sistema raiz, para independizarlo entre los clientes.
174#@param   
175#@return 
176#@exception OG_ERR_FORMAT    Formato incorrecto.
177#@version 0.9
178#@author Antonio J. Doblas. Universidad de Malaga.
179#@date    2010/05/24
180#*/ ##
181ogPostConfigureFS()
182{
183        # configuramos el /etc/hostname.
184        echo $HOSTNAME > /etc/hostname
185       
186        #configuramos el /etc/hosts
187        echo "127.0.0.1 localhost" > /etc/hosts
188        echo "$IPV4ADDR $HOSTNAME" >> /etc/hosts
189       
190        #configuramos el host.conf
191        echo "order hosts,bind" > /etc/host.conf
192        echo "multi on" >> /etc/host.conf
193       
194        #configuramos el dns anterior ubuntu 12.04 (parámetro del Kernel "ogdns=IP_DNS")
195        if [ -n "$ogdns" ]; then
196                mkdir -p /run/resolvconf
197                echo "nameserver $ogdns" > /run/resolvconf/resolv.conf
198        fi
199       
200        #configuramos el uso del servicio http proxy (parámetro del Kernel "ogproxy=URL_Proxy")
201        [ -n "${ogproxy}" ] && export http_proxy="$ogproxy"     
202       
203        # configuramos el /etc/networks
204        #read -e NETIP NETDEFAULT <<<$(route -n | grep eth0 | awk -F" " '{print $1}')
205        NETIP=$(route -n | grep eth0 | awk -F" " '{print $1}') && NETIP=$(echo $NETIP | cut -f1 -d" ")
206        echo "default 0.0.0.0" > /etc/networks
207        echo "loopback 127.0.0.0" >> /etc/networks
208        echo "link-local 169.254.0.0" >> /etc/networks
209        echo "localnet $NETIP" >> /etc/networks
210        #route
211
212        #echo "ogLive1.0.2" > /etc/debian_chroot
213
214        #enlace si iniciamos desde ogprotocolo=local { cdrom, usb, cache } .
215        # monta el raiz del dispositivo local en /opt/og2fs/tftpboot  - acceso al fichero .sqfs
216        # y monta el sistema root sqfs en /opt/og2fs/2ndfs
217        [ "$LOCALMEDIA" == "CACHE" ] && ln -s $DSTOGLIVE /opt/opengnsys/cache
218        [ "$ogprotocol" == "local" ] &&  ln -s ${OGLIVEROOTFS}/opt/opengnsys/* /opt/opengnsys/
219
220        #Montamos un directorio temporal para el apt-get
221        mount tmpfs /var/cache/apt/archives -t tmpfs -o size=15M
222        mkdir -p /var/cache/apt/archives/partial
223}
224
225
226#/**
227#     ogGetROOTSERVER
228#@brief   Determina los puntos de accesos a los distintos recursos.
229#Requiere ogConfigureNetworking.
230#Exporta ROOTSERVER
231# si la red ha sido configurada con dhcp el valor de ROOTSERVER será el valor de next-server del dhcp
232# si la red ha sido configurada con el parametro de kernel ip, será el segundo valor.
233## ip=iphost:ipnext-server:ipgateway:netmask:hostname:iface:none
234## ip=172.17.36.21:62.36.225.150:172.17.36.254:255.255.255.0:prueba1:eth0:none
235#@param   
236#@return 
237#@exception OG_ERR_FORMAT    Formato incorrecto.
238#@version 0.9
239#@author Antonio J. Doblas. Universidad de Malaga.
240#@date    2010/05/24
241#*/ ##
242ogGetROOTSERVER ()
243{
244        # get nfs root from dhcp
245        if [ "x${NFSROOT}" = "xauto" ]; then
246                # check if server ip is part of dhcp root-path
247                if [ "${ROOTPATH#*:}" = "${ROOTPATH}" ]; then
248                        NFSROOT=${ROOTSERVER}:${ROOTPATH}
249                else
250                        NFSROOT=${ROOTPATH}
251                fi
252
253        # nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
254        elif [ -n "${NFSROOT}" ]; then
255                # nfs options are an optional arg
256                if [ "${NFSROOT#*,}" != "${NFSROOT}" ]; then
257                        NFSOPTS="-o ${NFSROOT#*,}"
258                fi
259                NFSROOT=${NFSROOT%%,*}
260                if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
261                        NFSROOT=${ROOTSERVER}:${NFSROOT}
262                fi
263        fi
264        export ROOTSERVER
265        echo "ROOTSERVER=$ROOTSERVER" >> $CFGINITRD
266       
267        #si oglive no oglive=R
268        export OGSERVERIMAGES="${ogrepo:-$ROOTSERVER}" && echo "OGSERVERIMAGES=$OGSERVERIMAGES" >> $CFGINITRD
269        export OGSERVERSHARE="${ogshare:-$ROOTSERVER}" && echo "OGSERVERSHARE=$OGSERVERSHARE" >> $CFGINITRD
270        export OGSERVERLOG="${oglog:-$ROOTSERVER}" && echo "OGSERVERLOG=$OGSERVERLOG" >> $CFGINITRD
271        export OGSERVERLIVE="${oglive:-$OGSERVERIMAGES}" && echo "OGSERVERLIVE=$OGSERVERLIVE" >> $CFGINITRD
272               
273        return 0
274}
275
276
277
278#       ogUpdateInitrd
279#@brief   Actualiza el intird de la cache desde el servidor. Si el arranque ha disdo desde cache, compueba desde el servidor nueva version del initird.
280#@param1
281#@return 
282#@exception OG_ERR_FORMAT    Formato incorrecto.
283#@version 0.9
284#@author Antonio J. Doblas. Universidad de Malaga.
285#@date    2011/05/24
286#*/ ##
287
288ogUpdateInitrd ()
289{
290        cd /tmp
291        mkdir /tmp/cache
292        TYPE=$(blkid | grep CACHE | awk -F"TYPE=" '{print $2}' | tr -d \")
293        mount -t $TYPE LABEL=CACHE /tmp/cache || return
294        mkdir /tmp/cache/boot
295       
296       
297        # comparamos los del server
298        busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
299        busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
300        SERVERVMLINUZ=`cat ogvmlinuz.sum`
301        SERVERINITRD=`cat oginitrd.img.sum`
302
303       
304        #comparamos los de la cache
305        CACHEVMLINUZ=`cat /tmp/cache/boot/ogvmlinuz.sum`
306        CACHEINITRD=`cat /tmp/cache/boot/oginitrd.img.sum`
307       
308        echo "MD5 on SERVER: $SERVERVMLINUZ $SERVERINITRD"
309        echo "MD5  on CACHE: $CACHEVMLINUZ $CACHEINITRD"
310       
311        cd /tmp/cache/boot
312       
313        if [ "$CACHEVMLINUZ" != "$SERVERVMLINUZ" ]
314        then           
315                echo "ogvmlinuz updating"
316                busybox tftp -g -r ogvmlinuz $ROOTSERVER
317                busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
318                DOREBOOT=true
319        fi
320        if [ "$CACHEINITRD" != "$SERVERINITRD" ]
321        then
322                echo "oginitrd updating"
323                busybox tftp -g -r oginitrd.img $ROOTSERVER
324                busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
325                DOREBOOT=true
326        fi
327
328        cd /; umount /tmp/cache
329
330        [ "$DOREBOOT" == "true" ] && reboot -f
331
332}
333
334#/**
335#       ogConnect
336#@brief   Conecta con los recursos necesarios para opengnsys
337#@param1 ip del servidor TODO:dns
338#@param2 protocolo
339#@param3 punto de acceso remoto
340#@param4  punto de montaje local
341#@param5 acceso de lectura tipo ",ro"
342#@return 
343#@exception OG_ERR_FORMAT    Formato incorrecto.
344#@version 0.9
345#@author Antonio J. Doblas. Universidad de Malaga.
346#@date    2011/05/24
347#*/ ##
348   
349ogConnect ()
350{
351        SERVER=$1
352        PROTOCOL=$2
353        SRC=$3
354        DST=$4
355        READONLY=$5
356       
357        case "$PROTOCOL" in
358                nfs)
359                        nfsmount  ${SERVER}:${SRC} ${DST} -o nolock${READONLY} 2> /dev/null || mount.nfs ${SERVER}:${SRC} ${DST} -o nolock${READONLY}
360                ;;
361                smb)
362                        mount.cifs //${SERVER}/${SRC} ${DST} ${OPTIONS}${READONLY}             
363                ;;
364        esac
365}
366
367
368#/**
369#       ogConnectOgLive
370#@brief   Conecta con el recurso para usar el sistema raiz externo, remoto o local
371#@param1
372#@return 
373#@exception OG_ERR_FORMAT    Formato incorrecto.
374#@version 0.9
375#@author Antonio J. Doblas. Universidad de Malaga.
376#@date    2011/05/24   
377ogConnectOgLive ()
378{
379# Si ogprotocol=local, la funcion ogExportVar => SRCOGLIVE=local
380        if [ "$SRCOGLIVE" == "local" ]
381        then           
382                echo  "Montar imagen del sistema root desde dispositivo local"
383                for i in $(blkid /dev/s* | grep $OGLIVELABEL  | awk -F: '{print $2}' | tr -d \"); do export $i; done
384                # si local usb| cd con partcion es identificada como label $OGLIVELABEL         
385                mount -t $TYPE LABEL=$OGLIVELABEL $DSTOGLIVE 
386                if [ $? != 0 ]
387                then
388                        # Si local es particion CACHE es identificada como CACHE
389                        mount LABEL=CACHE $DSTOGLIVE
390                        export LOCALMEDIA=CACHE
391                fi
392        else
393# Si ogprotocol es remoto.    TODO en smb rw y en nfs ro??
394        ogConnect $OGSERVERLIVE $OGPROTOCOL $SRCOGLIVE $DSTOGLIVE               
395        fi             
396# Si el montaje ha sido correcto, tanto en local como en remoto. Procedemos con la union
397        ogMergeLive
398}
399
400
401#/**
402#       ogMergeLive
403#@brief   Metafuncion para fusionar el initrd con el sistema raiz.
404#@param1
405#@return 
406#@exception OG_ERR_FORMAT    Formato incorrecto.
407#@version 0.9
408#@author Antonio J. Doblas. Universidad de Malaga.
409#@date    2011/05/24   
410ogMergeLive()
411{
412#Si existe en el punto de acceso del del oglive el fichero ogclient.sqfs       
413if [ -f $DSTOGLIVE/ogclient/ogclient.sqfs ]
414then   
415        cat /proc/mounts > /tmp/mtab.preunion
416        if [ "$og2nd" == "img" ]
417        then
418                #Montamos el ROOTFS tipo  img, para desarrolladores
419                #TODO: comprobar que se tiene acceso de escritura
420                losetup /dev/loop0 $DSTOGLIVE/ogclient/ogclient.img -o 32256
421                mount /dev/loop0 $OGLIVEROOTFS
422        else
423                ## Montamos el ROOTFS tipo squashfs
424                mount $DSTOGLIVE/ogclient/ogclient.sqfs $OGLIVEROOTFS -t squashfs -o loop
425        fi
426# Realizamos la union entre el ogliveram(initrd) y el ogliverootfs(ogclient.sqfs)       
427        for i in etc var lib bin sbin usr root boot; do
428                ogUnionLiveDir $i
429        done
430        cat /tmp/mtab.preunion > /etc/mtab
431else
432        echo "Fichero imagen del cliente no encontrado"
433        return 1
434fi
435}
436
437
438
439#/**
440#       ogUnionLiveDir
441#@brief  fusiona dos directorios con unionfs
442#@param1
443#@return 
444#@exception OG_ERR_FORMAT    Formato incorrecto.
445#@version 0.9
446#@author Antonio J. Doblas. Universidad de Malaga.
447#@date    2011/05/24
448ogUnionLiveDir()
449{
450        TMPDIR=/$1              #dir
451        FUSE_OPT="-o default_permissions -o allow_other -o use_ino -o nonempty -o suid"
452        UNION_OPT="-o cow -o noinitgroups"
453        UBIN="unionfs-fuse"
454
455        mkdir -p $OGLIVERAMFS$TMPDIR
456        U1STDIR="${OGLIVERAMFS}${TMPDIR}=RW"
457        U2NDDIR="${OGLIVEROOTFS}${TMPDIR}=RO"
458        UNIONDIR=${OGLIVEUNIONFS}${TMPDIR}
459        mkdir -p $UNIONDIR
460        $UBIN $FUSE_OPT $UNION_OPT ${U1STDIR}:${U2NDDIR} $UNIONDIR
461        mount --bind  $UNIONDIR $TMPDIR
462}
463
464
465
466#/**
467#     ogConfigureLoopback
468#@brief   Configura la interfaz loopback para cliente torrent
469#@param   
470#@return 
471#@exception OG_ERR_FORMAT    Formato incorrecto.
472#@version 0.9   Usando funciones generales de ubuntu
473#@author Antonio J. Doblas. Universidad de Malaga.
474#@date    2010/05/24
475#@version 1.0.1   Deteccion automatica de interfaz con enlace activo.
476#@author Antonio J. Doblas. Universidad de Malaga.
477#@date    2011/05/24
478#*/ ##
479ogConfigureLoopback()
480{
481        # for the portmapper we need localhost
482        ifconfig lo 127.0.0.1
483        #/etc/init.d/portmap start
484}
485
486#/**
487#    ogConfigureNetworking
488#@brief   Configura la interfaz de red usada en el pxe
489#@param   
490#@return 
491#@exception OG_ERR_FORMAT    Formato incorrecto.
492#@version 0.9
493#@author Antonio J. Doblas. Universidad de Malaga.
494#@date    2010/05/24
495#*/ ##
496ogConfigureNetworking()
497{
498#echo "ogConfigureNetworking: Buscando interfaz a configurar DEVICE"
499if [ -n "${BOOTIF}" ]
500then
501        #echo " variable BOOTIF exportada con pxelinux.0 con valor $BOOTIF"
502        IP=$IPOPTS
503        temp_mac=${BOOTIF#*-}
504        # convert to typical mac address format by replacing "-" with ":"
505        bootif_mac=""
506        IFS='-'
507        for x in $temp_mac ; do
508                if [ -z "$bootif_mac" ]; then
509        bootif_mac="$x"
510        else
511                bootif_mac="$x:$bootif_mac"
512        fi
513        done
514        unset IFS
515        # look for devices with matching mac address, and set DEVICE to
516        # appropriate value if match is found.
517        for device in /sys/class/net/* ; do
518                if [ -f "$device/address" ]; then
519                        current_mac=$(cat "$device/address")
520                        if [ "$bootif_mac" = "$current_mac" ]; then
521                                DEVICE=${device##*/}
522                                break
523                        fi
524                fi
525        done
526else
527        #echo "variable BOOTIF no exportada, intentamos detectar que interfaz se ha iniciado"
528        IP=$ip
529        #TODO Detectar que interfaz se ha iniciado
530        case "$IP" in
531                none|off)
532                        return 0
533                        ;;
534                ""|on|any)
535                        # Bring up device
536                        DEVICE=eth0
537                        ;;
538                dhcp|bootp|rarp|both)
539                        DEVICE=eth0
540                        ;;
541                *)
542                        DEVICE=`echo $IP | cut -f6 -d:`
543                        ;;
544        esac
545fi
546if [ -z "${DEVICE}" ]; then
547        echo "variable DEVICE con valor $DEVICE no encontrada, llamamos de nuevo a ogconfigure_networking"
548        ogConfigureNetworking
549fi
550
551[ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ] && return 0
552#if [ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ]; then
553#       echo "variable DEVICE con valor $DEVICE  y fichero /run/net-$DEVICE encontrados"
554#       return 0
555#else
556#       echo "variable DEVICE con valor $DEVICE encontrada, procedemos a configurala y a crear el fichero /run/net-$DEVICE"
557#fi
558
559# Activamos la interfaz antes de configurar.
560ip address flush $DEVICE
561ip link set dev $DEVICE up
562# Si no se detecta señal portadora volver a configurar.
563sleep 1
564CARRIER=$(cat /sys/class/net/${DEVICE}/carrier)
565if [ "$CARRIER" != "1" ]
566then
567        ogConfigureNetworking
568fi
569
570# support ip options see linux sources
571# Documentation/filesystems/nfsroot.txt
572# Documentation/frv/booting.txt
573for ROUNDTTT in 2 3 4 6 9 16 25 36 64 100; do
574        # The NIC is to be configured if this file does not exist.
575        # Ip-Config tries to create this file and when it succeds
576        # creating the file, ipconfig is not run again.
577        if [ -e /run/net-"${DEVICE}".conf ]; then
578                break;
579        fi
580        case "$IP" in
581                none|off)
582                        return 0
583                ;;
584                ""|on|any)
585                        # Bring up device
586                        echo "Setting $DEVICE  with option:on|any and Variable IP= $IP: ipconfig -t ${ROUNDTTT} ${DEVICE} "
587                        ipconfig -t ${ROUNDTTT} ${DEVICE}
588                ;;
589                dhcp|bootp|rarp|both)
590                        echo "Setting $DEVICE with option:dhcp|bootp|rarp|both and Variable IP=  $IP: ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE} "
591                        ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE}
592                ;;
593                *)
594                        echo "Setting $DEVICE with option *  and Variable IP= $IP: ipconfig -t ${ROUNDTTT} -d $IP  "
595                        ipconfig -t ${ROUNDTTT} -d $IP
596                        # grab device entry from ip option
597                        NEW_DEVICE=${IP#*:*:*:*:*:*}
598                        if [ "${NEW_DEVICE}" != "${IP}" ]; then
599                                NEW_DEVICE=${NEW_DEVICE%:*}
600                        else
601                                # wrong parse, possibly only a partial string
602                                NEW_DEVICE=
603                        fi
604                        if [ -n "${NEW_DEVICE}" ]; then
605                                DEVICE="${NEW_DEVICE}"
606                        fi
607                ;;
608        esac
609done
610
611# source ipconfig output
612if [ -n "${DEVICE}" ]; then     
613        export DEVICE
614        export DEVICECFG="/run/net-${DEVICE}.conf"
615        # En algunos casos, el fichero de configuración está en /tmp.
616        [ ! -f $DEVICECFG -a -f ${DEVICECFG/run/tmp} ] && mv ${DEVICECFG/run/tmp} $DEVICECFG
617        source $DEVICECFG
618        echo "DEVICE=$DEVICE" >> $CFGINITRD
619        echo "DEVICECFG=$DEVICECFG" >> $CFGINITRD
620        echo "exportando variable DEVICE con valor = $DEVICE y DEVICECFG con valor $DEVICECFG"
621        # Compatibilidad con versiones anteriores.
622        ln -fs $DEVICECFG /tmp
623else
624        # source any interface as not exaclty specified
625        source /run/net-*.conf
626fi
627}
628
629
630#/**
631#    ogYesNo
632#@brief   Gestion de peticiones de usuario en modo ogdebug=true
633#@param1  OPTIONS    --timeout N    --default ANSWER
634#@param1 Questions   
635#@return  1=yes 0=no
636#@exception OG_ERR_FORMAT    Formato incorrecto.
637#@version 0.9
638#@author: 
639#@date    2010/05/24
640#*/ ##
641ogYesNo()
642{
643    local ans
644    local ok=0
645    local timeout=0
646    local default
647    local t
648
649    while [[ "$1" ]]
650    do
651        case "$1" in
652        --default)
653            shift
654            default=$1
655            if [[ ! "$default" ]]; then error "Missing default value"; fi
656            t=$(echo $default | tr '[:upper:]' '[:lower:]')
657
658            if [[ "$t" != 'y'  &&  "$t" != 'yes'  &&  "$t" != 'n'  &&  "$t" != 'no' ]]; then
659                error "Illegal default answer: $default"
660            fi
661            default=$t
662            shift
663            ;;
664
665        --timeout)
666            shift
667            timeout=$1
668            if [[ ! "$timeout" ]]; then error "Missing timeout value"; fi
669            #if [[ ! "$timeout" =~ ^[0-9][0-9]*$ ]]; then error "Illegal timeout value: $timeout"; fi
670            shift
671            ;;
672
673        -*)
674            error "Unrecognized option: $1"
675            ;;
676
677        *)
678            break
679            ;;
680        esac
681    done
682
683    if [[ $timeout -ne 0  &&  ! "$default" ]]; then
684        error "Non-zero timeout requires a default answer"
685    fi
686
687    if [[ ! "$*" ]]; then error "Missing question"; fi
688
689    while [[ $ok -eq 0 ]]
690    do
691        if [[ $timeout -ne 0 ]]; then
692            if ! read -t $timeout -p "$*" ans; then
693                ans=$default
694            else
695                # Turn off timeout if answer entered.
696                timeout=0
697                if [[ ! "$ans" ]]; then ans=$default; fi
698            fi
699        else
700            read -p "$*" ans
701            if [[ ! "$ans" ]]; then
702                ans=$default
703            else
704                ans=$(echo $ans | tr '[:upper:]' '[:lower:]')
705            fi
706        fi
707
708        if [[ "$ans" == 'y'  ||  "$ans" == 'yes'  ||  "$ans" == 'n'  ||  "$ans" == 'no' ]]; then
709            ok=1
710        fi
711
712        if [[ $ok -eq 0 ]]; then warning "Valid answers are: yes y no n"; fi
713    done
714    [[ "$ans" = "y" || "$ans" == "yes" ]]
715}
716 
Note: See TracBrowser for help on using the repository browser.