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

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 d7f8305 was 802fcc6, checked in by adv <adv@…>, 13 years ago

#460 #456 oginit ro images - ogprotocol nfs

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

  • Property mode set to 100644
File size: 18.7 KB
Line 
1#@file    ogfunctions.lib
2#@brief   Librería o clase para la gestion del sistema operativo de los clientes OpenGnsys
3#@class   client
4#@brief   Librería o clase para la gestion del sistema operativo de los clientes OpenGnsys
5#@version 0.91
6#@warning License: GNU GPLv3+
7
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#*/ ##
18ogExportKernelParameters ()
19{
20        GLOBAL="cat /proc/cmdline"
21        for i in `${GLOBAL}`
22        do
23                echo $i | grep "=" > /dev/null && export $i
24        done
25        return 0
26}
27
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#*/ ##
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
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#*/ ##
105ogConfigureRamfs ()
106{
107        mkdir -p $DSTOGLIVE     
108        mkdir -p $OGLIVERAMFS   
109        mkdir -p $OGLIVEROOTFS                           
110        mkdir -p $OGLIVEUNIONFS
111}
112
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#*/ ##
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
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#*/ ##
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
170        #echo "ogLive1.0.2" > /etc/debian_chroot
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
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
181
182}
183
184
185#/**
186#     ogGetROOTSERVER
187#@brief   Determina los puntos de accesos a los distintos recursos.
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.
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#*/ ##
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
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               
232        return 0
233}
234
235
236
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        TYPE=$(blkid | grep CACHE | awk -F"TYPE=" '{print $2}' | tr -d \")
252        mount -t $TYPE LABEL=CACHE /tmp/cache || return
253        mkdir /tmp/cache/boot
254       
255       
256        # comparamos los del server
257        busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
258        busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
259        SERVERVMLINUZ=`cat ogvmlinuz.sum`
260        SERVERINITRD=`cat oginitrd.img.sum`
261
262       
263        #comparamos los de la cache
264        CACHEVMLINUZ=`cat /tmp/cache/boot/ogvmlinuz.sum`
265        CACHEINITRD=`cat /tmp/cache/boot/oginitrd.img.sum`
266       
267        echo "MD5 on SERVER: $SERVERVMLINUZ $SERVERINITRD"
268        echo "MD5  on CACHE: $CACHEVMLINUZ $CACHEINITRD"
269       
270        cd /tmp/cache/boot
271       
272        if [ "$CACHEVMLINUZ" != "$SERVERVMLINUZ" ]
273        then           
274                echo "ogvmlinuz updating"
275                busybox tftp -g -r ogvmlinuz $ROOTSERVER
276                busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
277                DOREBOOT=true
278        fi
279        if [ "$CACHEINITRD" != "$SERVERINITRD" ]
280        then
281                echo "oginitrd updating"
282                busybox tftp -g -r oginitrd.img $ROOTSERVER
283                busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
284                DOREBOOT=true
285        fi
286
287        cd /; umount /tmp/cache
288
289        [ "$DOREBOOT" == "true" ] && busybox reboot -f
290
291}
292
293#/**
294#       ogConnect
295#@brief   Conecta con los recursos necesarios para opengnsys
296#@param1 ip del servidor TODO:dns
297#@param2 protocolo
298#@param3 punto de acceso remoto
299#@param4  punto de montaje local
300#@param5 acceso de lectura tipo ",ro"
301#@return 
302#@exception OG_ERR_FORMAT    Formato incorrecto.
303#@version 0.9
304#@author Antonio J. Doblas. Universidad de Malaga.
305#@date    2011/05/24
306#*/ ##
307   
308ogConnect ()
309{
310        SERVER=$1
311        PROTOCOL=$2
312        SRC=$3
313        DST=$4
314        READONLY=$5
315       
316        case "$PROTOCOL" in
317                nfs)
318                        nfsmount  ${SERVER}:${SRC} ${DST} -o nolock${READONLY} 2> /dev/null || mount.nfs ${SERVER}:${SRC} ${DST} -o nolock${READONLY}
319                ;;
320                smb)
321                        mount.cifs //${SERVER}/${SRC} ${DST} ${OPTIONS}${READONLY}             
322                ;;
323        esac
324}
325
326
327#/**
328#       ogConnectOgLive
329#@brief   Conecta con el recurso para usar el sistema raiz externo, remoto o local
330#@param1
331#@return 
332#@exception OG_ERR_FORMAT    Formato incorrecto.
333#@version 0.9
334#@author Antonio J. Doblas. Universidad de Malaga.
335#@date    2011/05/24   
336ogConnectOgLive ()
337{
338# Si ogprotocol=local, la funcion ogExportVar => SRCOGLIVE=local
339        if [ "$SRCOGLIVE" == "local" ]
340        then           
341                echo  "Montar imagen del sistema root desde dispositivo local"
342                for i in $(blkid /dev/s* | grep $OGLIVELABEL  | awk -F: '{print $2}' | tr -d \"); do export $i; done
343                mount -t $TYPE LABEL=$LABEL $DSTOGLIVE 
344                if [ $? != 0 ]
345                then
346                        mount LABEL=CACHE $DSTOGLIVE
347                        export LOCALMEDIA=CACHE
348                fi
349        else
350# Si ogprotocol es remoto.    TODO en smb rw y en nfs ro??
351        ogConnect $OGSERVERLIVE $OGPROTOCOL $SRCOGLIVE $DSTOGLIVE               
352        fi             
353# Si el montaje ha sido correcto, tanto en local como en remoto. Procedemos con la union
354        ogMergeLive
355}
356
357
358#/**
359#       ogMergeLive
360#@brief   Metafuncion para fusionar el initrd con el sistema raiz.
361#@param1
362#@return 
363#@exception OG_ERR_FORMAT    Formato incorrecto.
364#@version 0.9
365#@author Antonio J. Doblas. Universidad de Malaga.
366#@date    2011/05/24   
367ogMergeLive()
368{
369#Si existe en el punto de acceso del del oglive el fichero ogclient.sqfs       
370if [ -f $DSTOGLIVE/ogclient/ogclient.sqfs ]
371then   
372        cat /proc/mounts > /tmp/mtab.preunion
373        if [ "$og2nd" == "img" ]
374        then
375                #Montamos el ROOTFS tipo  img, para desarrolladores
376                #TODO: comprobar que se tiene acceso de escritura
377                losetup /dev/loop0 $DSTOGLIVE/ogclient/ogclient.img -o 32256
378                mount /dev/loop0 $OGLIVEROOTFS
379        else
380                ## Montamos el ROOTFS tipo squashfs
381                mount $DSTOGLIVE/ogclient/ogclient.sqfs $OGLIVEROOTFS -t squashfs -o loop
382        fi
383# Realizamos la union entre el ogliveram(initrd) y el ogliverootfs(ogclient.sqfs)       
384        for i in etc var lib bin sbin usr root boot; do
385                ogUnionLiveDir $i
386        done
387        cat /tmp/mtab.preunion > /etc/mtab
388else
389        echo "Fichero imagen del cliente no encontrado"
390        return 1
391fi
392}
393
394
395
396#/**
397#       ogUnionLiveDir
398#@brief  fusiona dos directorios con unionfs
399#@param1
400#@return 
401#@exception OG_ERR_FORMAT    Formato incorrecto.
402#@version 0.9
403#@author Antonio J. Doblas. Universidad de Malaga.
404#@date    2011/05/24
405ogUnionLiveDir()
406{
407        TMPDIR=/$1              #dir
408        FUSE_OPT="-o default_permissions -o allow_other -o use_ino -o nonempty -o suid"
409        UNION_OPT="-o cow -o noinitgroups"
410        UBIN="unionfs-fuse"
411
412        mkdir -p $OGLIVERAMFS$TMPDIR
413        U1STDIR="${OGLIVERAMFS}${TMPDIR}=RW"
414        U2NDDIR="${OGLIVEROOTFS}${TMPDIR}=RO"
415        UNIONDIR=${OGLIVEUNIONFS}${TMPDIR}
416        mkdir -p $UNIONDIR
417        $UBIN $FUSE_OPT $UNION_OPT ${U1STDIR}:${U2NDDIR} $UNIONDIR
418        mount --bind  $UNIONDIR $TMPDIR
419}
420
421
422
423#/**
424#     ogConfigureLoopback
425#@brief   Configura la interfaz loopback para cliente torrent
426#@param   
427#@return 
428#@exception OG_ERR_FORMAT    Formato incorrecto.
429#@version 0.9   Usando funciones generales de ubuntu
430#@author Antonio J. Doblas. Universidad de Malaga.
431#@date    2010/05/24
432#@version 1.0.1   Deteccion automatica de interfaz con enlace activo.
433#@author Antonio J. Doblas. Universidad de Malaga.
434#@date    2011/05/24
435#*/ ##
436ogConfigureLoopback()
437{
438        # for the portmapper we need localhost
439        ifconfig lo 127.0.0.1
440        #/etc/init.d/portmap start
441}
442
443#/**
444#    ogConfigureNetworking
445#@brief   Configura la interfaz de red usada en el pxe
446#@param   
447#@return 
448#@exception OG_ERR_FORMAT    Formato incorrecto.
449#@version 0.9
450#@author Antonio J. Doblas. Universidad de Malaga.
451#@date    2010/05/24
452#*/ ##
453ogConfigureNetworking()
454{
455#echo "ogConfigureNetworking: Buscando interfaz a configurar DEVICE"
456if [ -n "${BOOTIF}" ]
457then
458        #echo " variable BOOTIF exportada con pxelinux.0 con valor $BOOTIF"
459        IP=$IPOPTS
460        temp_mac=${BOOTIF#*-}
461        # convert to typical mac address format by replacing "-" with ":"
462        bootif_mac=""
463        IFS='-'
464        for x in $temp_mac ; do
465                if [ -z "$bootif_mac" ]; then
466        bootif_mac="$x"
467        else
468                bootif_mac="$x:$bootif_mac"
469        fi
470        done
471        unset IFS
472        # look for devices with matching mac address, and set DEVICE to
473        # appropriate value if match is found.
474        for device in /sys/class/net/* ; do
475                if [ -f "$device/address" ]; then
476                        current_mac=$(cat "$device/address")
477                        if [ "$bootif_mac" = "$current_mac" ]; then
478                                DEVICE=${device##*/}
479                                break
480                        fi
481                fi
482        done
483else
484        #echo "variable BOOTIF no exportada, intentamos detectar que interfaz se ha iniciado"
485        IP=$ip
486        #TODO Detectar que interfaz se ha iniciado
487        case ${IP} in
488                none|off)
489           return 0
490        ;;
491        ""|on|any)
492          # Bring up device
493          DEVICE=eth0
494        ;;
495        dhcp|bootp|rarp|both)
496          DEVICE=eth0
497        ;;
498        *)
499          DEVICE=`echo $IP | cut -f6 -d:`
500        ;;
501        esac
502fi
503if [ -z "${DEVICE}" ]; then
504        echo "variable DEVICE con valor $DEVICE no encontrada, llamamos de nuevo a ogconfigure_networking"
505        ogConfigureNetworking
506fi
507
508[ -n "${DEVICE}" ] && [ -e /tmp/net-"${DEVICE}".conf ] && return 0
509#if [ -n "${DEVICE}" ] && [ -e /tmp/net-"${DEVICE}".conf ]; then
510#       echo "variable DEVICE con valor $DEVICE  y fichero /tmp/net-$DEVICE encontrados"
511#       return 0
512#else
513#       echo "variable DEVICE con valor $DEVICE encontrada, procedemos a configurala y a crear el fichero /tmp/net-$DEVICE"
514#fi
515
516# Activamos la interfaz antes de configurar.
517ip address flush $DEVICE
518ip link set dev $DEVICE up
519# Si no se detecta señal portadora volver a configurar.
520sleep 1
521CARRIER=$(cat /sys/class/net/${DEVICE}/carrier)
522if [ "$CARRIER" != "1" ]
523then
524        ogConfigureNetworking
525fi
526
527# support ip options see linux sources
528# Documentation/filesystems/nfsroot.txt
529# Documentation/frv/booting.txt
530for ROUNDTTT in 2 3 4 6 9 16 25 36 64 100; do
531        # The NIC is to be configured if this file does not exist.
532        # Ip-Config tries to create this file and when it succeds
533        # creating the file, ipconfig is not run again.
534        if [ -e /tmp/net-"${DEVICE}".conf ]; then
535                break;
536        fi
537        case ${IP} in
538                none|off)
539                        return 0
540                ;;
541                ""|on|any)
542                        # Bring up device
543                        echo "Setting $DEVICE  with option:on|any and Variable IP= $IP: ipconfig -t ${ROUNDTTT} ${DEVICE} "
544                        ipconfig -t ${ROUNDTTT} ${DEVICE}
545                ;;
546                dhcp|bootp|rarp|both)
547                        echo "Setting $DEVICE with option:dhcp|bootp|rarp|both and Variable IP=  $IP: ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE} "
548                        ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE}
549                ;;
550                *)
551                        echo "Setting $DEVICE with option *  and Variable IP= $IP: ipconfig -t ${ROUNDTTT} -d $IP  "
552                        ipconfig -t ${ROUNDTTT} -d $IP
553                        # grab device entry from ip option
554                        NEW_DEVICE=${IP#*:*:*:*:*:*}
555                        if [ "${NEW_DEVICE}" != "${IP}" ]; then
556                                NEW_DEVICE=${NEW_DEVICE%:*}
557                        else
558                                # wrong parse, possibly only a partial string
559                                NEW_DEVICE=
560                        fi
561                        if [ -n "${NEW_DEVICE}" ]; then
562                                DEVICE="${NEW_DEVICE}"
563                        fi
564                ;;
565        esac
566done
567
568# source ipconfig output
569if [ -n "${DEVICE}" ]; then     
570    . /tmp/net-${DEVICE}.conf
571    DEVICECFG="/tmp/net-${DEVICE}.conf"
572        export DEVICECFG
573        export DEVICE
574        echo "DEVICE=$DEVICE" >> $CFGINITRD
575        echo "DEVICECFG=$DEVICECFG" >> $CFGINITRD
576        echo "exportando variable DEVICE con valor = $DEVICE y el DEVICECFG con valor $DEVICECFG"   
577else
578    # source any interface as not exaclty specified
579    . /tmp/net-*.conf
580fi
581}
582
583
584#/**
585#    ogYesNo
586#@brief   Gestion de peticiones de usuario en modo ogdebug=true
587#@param1  OPTIONS    --timeout N    --default ANSWER
588#@param1 Questions   
589#@return  1=yes 0=no
590#@exception OG_ERR_FORMAT    Formato incorrecto.
591#@version 0.9
592#@author: 
593#@date    2010/05/24
594#*/ ##
595ogYesNo()
596{
597    local ans
598    local ok=0
599    local timeout=0
600    local default
601    local t
602
603    while [[ "$1" ]]
604    do
605        case "$1" in
606        --default)
607            shift
608            default=$1
609            if [[ ! "$default" ]]; then error "Missing default value"; fi
610            t=$(echo $default | tr '[:upper:]' '[:lower:]')
611
612            if [[ "$t" != 'y'  &&  "$t" != 'yes'  &&  "$t" != 'n'  &&  "$t" != 'no' ]]; then
613                error "Illegal default answer: $default"
614            fi
615            default=$t
616            shift
617            ;;
618
619        --timeout)
620            shift
621            timeout=$1
622            if [[ ! "$timeout" ]]; then error "Missing timeout value"; fi
623            #if [[ ! "$timeout" =~ ^[0-9][0-9]*$ ]]; then error "Illegal timeout value: $timeout"; fi
624            shift
625            ;;
626
627        -*)
628            error "Unrecognized option: $1"
629            ;;
630
631        *)
632            break
633            ;;
634        esac
635    done
636
637    if [[ $timeout -ne 0  &&  ! "$default" ]]; then
638        error "Non-zero timeout requires a default answer"
639    fi
640
641    if [[ ! "$*" ]]; then error "Missing question"; fi
642
643    while [[ $ok -eq 0 ]]
644    do
645        if [[ $timeout -ne 0 ]]; then
646            if ! read -t $timeout -p "$*" ans; then
647                ans=$default
648            else
649                # Turn off timeout if answer entered.
650                timeout=0
651                if [[ ! "$ans" ]]; then ans=$default; fi
652            fi
653        else
654            read -p "$*" ans
655            if [[ ! "$ans" ]]; then
656                ans=$default
657            else
658                ans=$(echo $ans | tr '[:upper:]' '[:lower:]')
659            fi
660        fi
661
662        if [[ "$ans" == 'y'  ||  "$ans" == 'yes'  ||  "$ans" == 'n'  ||  "$ans" == 'no' ]]; then
663            ok=1
664        fi
665
666        if [[ $ok -eq 0 ]]; then warning "Valid answers are: yes y no n"; fi
667    done
668    [[ "$ans" = "y" || "$ans" == "yes" ]]
669}
670 
Note: See TracBrowser for help on using the repository browser.