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

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 e087194 was 10972ea, checked in by adv <adv@…>, 13 years ago

#547 oglive 1.0.4 resolv.conf > resolv.conf.d/tail

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

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