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

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 28d0df2 was 3e0afdd, checked in by ramon <ramongomez@…>, 9 years ago

#724: Adaptar la generación de ogLive a la nueva asignación de nombres de los dispositivos de red que realiza Ubuntu 15.10 (deja de utilizar ethN).

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

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