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

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 d9905b9 was 82ae131, checked in by adv <adv@…>, 14 years ago

version 1.0.2 boot-tools #404 #420 #393 #429 #430 #431 #423

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

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