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

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 da6a7cf was 025bd24, checked in by ramon <ramongomez@…>, 9 years ago

#724 #730: Problemas resueltos:

  • Detección correcta de caché en ogLive basado en Ubuntu 15.10.
  • Dejar de montar sistema de archivos temporal para APT en ogLive.
  • Cálculo correcto de tamaño en KB en función ogGetPartitionSize.

Actualizar lista de tickets resueltos.

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

  • Property mode set to 100644
File size: 23.6 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
297
298#/**
299#     ogGetROOTSERVER
300#@brief   Determina los puntos de accesos a los distintos recursos.
301#Requiere ogConfigureNetworking.
302#Exporta ROOTSERVER
303# si la red ha sido configurada con dhcp el valor de ROOTSERVER será el valor de next-server del dhcp
304# si la red ha sido configurada con el parametro de kernel ip, será el segundo valor.
305## ip=iphost:ipnext-server:ipgateway:netmask:hostname:iface:none
306## ip=172.17.36.21:62.36.225.150:172.17.36.254:255.255.255.0:prueba1:eth0:none
307#@param   
308#@return 
309#@exception OG_ERR_FORMAT    Formato incorrecto.
310#@version 0.9
311#@author Antonio J. Doblas. Universidad de Malaga.
312#@date    2010/05/24
313#*/ ##
314ogGetROOTSERVER ()
315{
316        # get nfs root from dhcp
317        if [ "x${NFSROOT}" = "xauto" ]; then
318                # check if server ip is part of dhcp root-path
319                if [ "${ROOTPATH#*:}" = "${ROOTPATH}" ]; then
320                        NFSROOT=${ROOTSERVER}:${ROOTPATH}
321                else
322                        NFSROOT=${ROOTPATH}
323                fi
324
325        # nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
326        elif [ -n "${NFSROOT}" ]; then
327                # nfs options are an optional arg
328                if [ "${NFSROOT#*,}" != "${NFSROOT}" ]; then
329                        NFSOPTS="-o ${NFSROOT#*,}"
330                fi
331                NFSROOT=${NFSROOT%%,*}
332                if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
333                        NFSROOT=${ROOTSERVER}:${NFSROOT}
334                fi
335        fi
336        export ROOTSERVER
337        echo "ROOTSERVER=$ROOTSERVER" >> $CFGINITRD
338       
339        #si oglive no oglive=R
340        export OGSERVERIMAGES="${ogrepo:-$ROOTSERVER}" && echo "OGSERVERIMAGES=$OGSERVERIMAGES" >> $CFGINITRD
341        export OGSERVERSHARE="${ogshare:-$ROOTSERVER}" && echo "OGSERVERSHARE=$OGSERVERSHARE" >> $CFGINITRD
342        export OGSERVERLOG="${oglog:-$ROOTSERVER}" && echo "OGSERVERLOG=$OGSERVERLOG" >> $CFGINITRD
343        export OGSERVERLIVE="${oglive:-$OGSERVERIMAGES}" && echo "OGSERVERLIVE=$OGSERVERLIVE" >> $CFGINITRD
344               
345        return 0
346}
347
348
349
350#       ogUpdateInitrd
351#@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.
352#@param1
353#@return 
354#@exception OG_ERR_FORMAT    Formato incorrecto.
355#@version 0.9
356#@author Antonio J. Doblas. Universidad de Malaga.
357#@date    2011/05/24
358#*/ ##
359
360ogUpdateInitrd ()
361{
362        cd /tmp
363        mkdir /tmp/cache
364        TYPE=$(blkid -po export $(blkid -L CACHE) 2>/dev/null | awk -F= '$1=="TYPE" { print $2}')
365        # Salir si no se detecta caché.
366        [ -z "$TYPE" ] && return
367        mount -t $TYPE LABEL=CACHE /tmp/cache || return
368        mkdir -p /tmp/cache/boot
369       
370       
371        # comparamos los del server
372        busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
373        busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
374        SERVERVMLINUZ=`cat ogvmlinuz.sum`
375        SERVERINITRD=`cat oginitrd.img.sum`
376
377       
378        #comparamos los de la cache
379        CACHEVMLINUZ=`cat /tmp/cache/boot/ogvmlinuz.sum`
380        CACHEINITRD=`cat /tmp/cache/boot/oginitrd.img.sum`
381       
382        echo "MD5 on SERVER: $SERVERVMLINUZ $SERVERINITRD"
383        echo "MD5 on  CACHE: $CACHEVMLINUZ $CACHEINITRD"
384       
385        cd /tmp/cache/boot
386       
387        if [ "$CACHEVMLINUZ" != "$SERVERVMLINUZ" ]
388        then           
389                echo "ogvmlinuz updating"
390                busybox tftp -g -r ogvmlinuz $ROOTSERVER
391                busybox tftp -g -r ogvmlinuz.sum $ROOTSERVER
392                DOREBOOT=true
393        fi
394        if [ "$CACHEINITRD" != "$SERVERINITRD" ]
395        then
396                echo "oginitrd updating"
397                busybox tftp -g -r oginitrd.img $ROOTSERVER
398                busybox tftp -g -r oginitrd.img.sum $ROOTSERVER
399                DOREBOOT=true
400        fi
401
402        cd /; umount /tmp/cache
403
404        [ "$DOREBOOT" == "true" ] && reboot -f
405
406}
407
408#/**
409#       ogConnect
410#@brief   Conecta con los recursos necesarios para opengnsys
411#@param1 ip del servidor TODO:dns
412#@param2 protocolo
413#@param3 punto de acceso remoto
414#@param4  punto de montaje local
415#@param5 acceso de lectura tipo ",ro"
416#@return 
417#@exception OG_ERR_FORMAT    Formato incorrecto.
418#@version 0.9
419#@author Antonio J. Doblas. Universidad de Malaga.
420#@date    2011/05/24
421#*/ ##
422   
423ogConnect ()
424{
425        SERVER=$1
426        PROTOCOL=$2
427        SRC=$3
428        DST=$4
429        READONLY=$5
430       
431        case "$PROTOCOL" in
432                nfs)
433                        nfsmount  ${SERVER}:${SRC} ${DST} -o nolock${READONLY} 2> /dev/null || mount.nfs ${SERVER}:${SRC} ${DST} -o nolock${READONLY}
434                ;;
435                smb)
436                        mount.cifs //${SERVER}/${SRC} ${DST} ${OPTIONS}${READONLY}             
437                ;;
438                local)
439                   # Comprobamos que estatus sea online y que la variable del server no esta vacia.
440                   if [ "$ogstatus" != "offline" -a "$SERVER" != "" -a "$SRC" != "" ]; then
441                        # Comprobamos que existe un servicio de samba.
442                        smbclient -L $SERVER -N &>/dev/null
443                        if [ $? -eq 0 ]; then
444                           mount.cifs //${SERVER}/og${SRC} ${DST} ${OPTIONS}${READONLY}
445                        fi
446                        # TODO: buscar condicion para NFS
447                   fi
448                ;;
449        esac
450}
451
452
453#/**
454#       ogConnectOgLive
455#@brief   Conecta con el recurso para usar el sistema raiz externo, remoto o local
456#@param1
457#@return 
458#@exception OG_ERR_FORMAT    Formato incorrecto.
459#@version 0.9
460#@author Antonio J. Doblas. Universidad de Malaga.
461#@date    2011/05/24   
462ogConnectOgLive ()
463{
464# Si ogprotocol=local, la funcion ogExportVar => SRCOGLIVE=local
465        if [ "$SRCOGLIVE" == "local" ]
466        then           
467                echo  "Montar imagen del sistema root desde dispositivo local"
468                for i in $(blkid /dev/s* | grep $OGLIVELABEL  | awk -F: '{print $2}' | tr -d \"); do export $i; done
469                # si local usb| cd con partcion es identificada como label $OGLIVELABEL         
470                mount -t $TYPE LABEL=$OGLIVELABEL $DSTOGLIVE 
471                if [ $? != 0 ]
472                then
473                        # Si local es particion CACHE es identificada como CACHE
474                        mount LABEL=CACHE $DSTOGLIVE
475                        #export LOCALMEDIA=CACHE
476                fi
477        else
478                # Si ogprotocol es remoto.    TODO en smb rw y en nfs ro??
479                ogConnect $OGSERVERLIVE $OGPROTOCOL $SRCOGLIVE $DSTOGLIVE               
480        fi             
481# Si el montaje ha sido correcto, tanto en local como en remoto. Procedemos con la union
482        ogMergeLive
483}
484
485
486#/**
487#       ogMergeLive
488#@brief   Metafuncion para fusionar el initrd con el sistema raiz.
489#@param1
490#@return 
491#@exception OG_ERR_FORMAT    Formato incorrecto.
492#@version 0.9
493#@author Antonio J. Doblas. Universidad de Malaga.
494#@date    2011/05/24   
495ogMergeLive()
496{
497#Si existe en el punto de acceso del del oglive el fichero ogclient.sqfs       
498if [ -f $DSTOGLIVE/ogclient/ogclient.sqfs ]
499then   
500        cat /proc/mounts > /tmp/mtab.preunion
501        if [ "$og2nd" == "img" ]
502        then
503                #Montamos el ROOTFS tipo  img, para desarrolladores
504                #TODO: comprobar que se tiene acceso de escritura
505                losetup /dev/loop0 $DSTOGLIVE/ogclient/ogclient.img -o 32256
506                mount /dev/loop0 $OGLIVEROOTFS
507        else
508                ## Montamos el ROOTFS tipo squashfs
509                mount $DSTOGLIVE/ogclient/ogclient.sqfs $OGLIVEROOTFS -t squashfs -o loop
510        fi
511# Realizamos la union entre el ogliveram(initrd) y el ogliverootfs(ogclient.sqfs)       
512# Nota: el orden es muy importante para evitar errores de montaje.
513        for i in bin sbin etc var lib usr root boot; do
514                ogUnionLiveDir $i
515        done
516        cat /tmp/mtab.preunion > /etc/mtab
517else
518        echo "Fichero imagen del cliente no encontrado"
519        return 1
520fi
521}
522
523
524
525#/**
526#       ogUnionLiveDir
527#@brief  fusiona dos directorios con unionfs
528#@param1
529#@return 
530#@exception OG_ERR_FORMAT    Formato incorrecto.
531#@version 0.9
532#@author Antonio J. Doblas. Universidad de Malaga.
533#@date    2011/05/24
534ogUnionLiveDir()
535{
536        TMPDIR=/$1              #dir
537        FUSE_OPT="-o default_permissions -o allow_other -o use_ino -o nonempty -o suid"
538        UNION_OPT="-o cow -o noinitgroups"
539        UBIN="unionfs-fuse"
540
541        mkdir -p $OGLIVERAMFS$TMPDIR
542        U1STDIR="${OGLIVERAMFS}${TMPDIR}=RW"
543        U2NDDIR="${OGLIVEROOTFS}${TMPDIR}=RO"
544        UNIONDIR=${OGLIVEUNIONFS}${TMPDIR}
545        mkdir -p $UNIONDIR
546        $UBIN $FUSE_OPT $UNION_OPT ${U1STDIR}:${U2NDDIR} $UNIONDIR
547        mount --bind  $UNIONDIR $TMPDIR
548}
549
550
551
552#/**
553#     ogConfigureLoopback
554#@brief   Configura la interfaz loopback para cliente torrent
555#@param   
556#@return 
557#@exception OG_ERR_FORMAT    Formato incorrecto.
558#@version 0.9   Usando funciones generales de ubuntu
559#@author Antonio J. Doblas. Universidad de Malaga.
560#@date    2010/05/24
561#@version 1.0.1   Deteccion automatica de interfaz con enlace activo.
562#@author Antonio J. Doblas. Universidad de Malaga.
563#@date    2011/05/24
564#*/ ##
565ogConfigureLoopback()
566{
567        # for the portmapper we need localhost
568        ifconfig lo 127.0.0.1
569        #/etc/init.d/portmap start
570}
571
572#/**
573#    ogConfigureNetworking
574#@brief   Configura la interfaz de red usada en el pxe
575#@param   
576#@return 
577#@exception OG_ERR_FORMAT    Formato incorrecto.
578#@version 0.9
579#@author Antonio J. Doblas. Universidad de Malaga.
580#@date    2010/05/24
581#*/ ##
582ogConfigureNetworking()
583{
584#echo "ogConfigureNetworking: Buscando interfaz a configurar DEVICE"
585if [ -n "${BOOTIF}" ]
586then
587        #echo " variable BOOTIF exportada con pxelinux.0 con valor $BOOTIF"
588        IP=$IPOPTS
589        temp_mac=${BOOTIF#*-}
590        # convert to typical mac address format by replacing "-" with ":"
591        bootif_mac=""
592        IFS='-'
593        for x in $temp_mac ; do
594                if [ -z "$bootif_mac" ]; then
595        bootif_mac="$x"
596        else
597                bootif_mac="$x:$bootif_mac"
598        fi
599        done
600        unset IFS
601        # look for devices with matching mac address, and set DEVICE to
602        # appropriate value if match is found.
603        for device in /sys/class/net/* ; do
604                if [ -f "$device/address" ]; then
605                        current_mac=$(cat "$device/address")
606                        if [ "$bootif_mac" = "$current_mac" ]; then
607                                DEVICE=${device##*/}
608                                break
609                        fi
610                fi
611        done
612else
613        #echo "variable BOOTIF no exportada, intentamos detectar que interfaz se ha iniciado"
614        IP=$ip
615        #TODO Detectar que interfaz se ha iniciado
616        case "$IP" in
617                none|off)
618                        return 0
619                        ;;
620                ""|on|any)
621                        # Bring up device
622                        DEVICE=1
623                        ;;
624                dhcp|bootp|rarp|both)
625                        DEVICE=1
626                        ;;
627                *)
628                        DEVICE=`echo $IP | cut -f6 -d:`
629                        ;;
630        esac
631fi
632DEVICE=$(ogGetNetworkDevice $DEVICE)
633if [ -z "${DEVICE}" ]; then
634        echo "variable DEVICE con valor $DEVICE no encontrada, llamamos de nuevo a ogconfigure_networking"
635        ogConfigureNetworking
636fi
637
638[ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ] && return 0
639#if [ -n "${DEVICE}" ] && [ -e /run/net-"${DEVICE}".conf ]; then
640#       echo "variable DEVICE con valor $DEVICE  y fichero /run/net-$DEVICE encontrados"
641#       return 0
642#else
643#       echo "variable DEVICE con valor $DEVICE encontrada, procedemos a configurala y a crear el fichero /run/net-$DEVICE"
644#fi
645
646# Activamos la interfaz antes de configurar.
647ip address flush $DEVICE
648ip link set dev $DEVICE up
649# Si no se detecta señal portadora volver a configurar.
650sleep 1
651CARRIER=$(cat /sys/class/net/${DEVICE}/carrier)
652if [ "$CARRIER" != "1" ]
653then
654        ogConfigureNetworking
655fi
656
657# support ip options see linux sources
658# Documentation/filesystems/nfsroot.txt
659# Documentation/frv/booting.txt
660for ROUNDTTT in 2 3 4 6 9 16 25 36 64 100; do
661        # The NIC is to be configured if this file does not exist.
662        # Ip-Config tries to create this file and when it succeds
663        # creating the file, ipconfig is not run again.
664        if [ -e /run/net-"${DEVICE}".conf ]; then
665                break;
666        fi
667        case "$IP" in
668                none|off)
669                        return 0
670                ;;
671                ""|on|any)
672                        # Bring up device
673                        echo "Setting $DEVICE  with option:on|any and Variable IP= $IP: ipconfig -t ${ROUNDTTT} ${DEVICE} "
674                        ipconfig -t ${ROUNDTTT} ${DEVICE}
675                ;;
676                dhcp|bootp|rarp|both)
677                        echo "Setting $DEVICE with option:dhcp|bootp|rarp|both and Variable IP=  $IP: ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE} "
678                        ipconfig -t ${ROUNDTTT} -c ${IP} -d ${DEVICE}
679                ;;
680                *)
681                        echo "Setting $DEVICE with option *  and Variable IP= $IP: ipconfig -t ${ROUNDTTT} -d $IP  "
682                        ipconfig -t ${ROUNDTTT} -d $IP
683                        # grab device entry from ip option
684                        NEW_DEVICE=${IP#*:*:*:*:*:*}
685                        if [ "${NEW_DEVICE}" != "${IP}" ]; then
686                                NEW_DEVICE=${NEW_DEVICE%:*}
687                        else
688                                # wrong parse, possibly only a partial string
689                                NEW_DEVICE=
690                        fi
691                        if [ -n "${NEW_DEVICE}" ]; then
692                                DEVICE="${NEW_DEVICE}"
693                        fi
694                ;;
695        esac
696done
697
698# source ipconfig output
699if [ -n "${DEVICE}" ]; then     
700        export DEVICE
701        export DEVICECFG="/run/net-${DEVICE}.conf"
702        # En algunos casos, el fichero de configuración está en /tmp.
703        [ ! -f $DEVICECFG -a -f ${DEVICECFG/run/tmp} ] && mv ${DEVICECFG/run/tmp} $DEVICECFG
704        source $DEVICECFG
705        echo "DEVICE=$DEVICE" >> $CFGINITRD
706        echo "DEVICECFG=$DEVICECFG" >> $CFGINITRD
707        echo "exportando variable DEVICE con valor = $DEVICE y DEVICECFG con valor $DEVICECFG"
708        # Compatibilidad con versiones anteriores.
709        ln -fs $DEVICECFG /tmp
710else
711        # source any interface as not exaclty specified
712        source /run/net-*.conf
713fi
714}
715
716
717#/**
718#    ogYesNo
719#@brief   Gestion de peticiones de usuario en modo ogdebug=true
720#@param1  OPTIONS    --timeout N    --default ANSWER
721#@param1 Questions   
722#@return  1=yes 0=no
723#@exception OG_ERR_FORMAT    Formato incorrecto.
724#@version 0.9
725#@author: 
726#@date    2010/05/24
727#*/ ##
728ogYesNo()
729{
730    local ans
731    local ok=0
732    local timeout=0
733    local default
734    local t
735
736    while [[ "$1" ]]
737    do
738        case "$1" in
739        --default)
740            shift
741            default=$1
742            if [[ ! "$default" ]]; then error "Missing default value"; fi
743            t=$(echo $default | tr '[:upper:]' '[:lower:]')
744
745            if [[ "$t" != 'y'  &&  "$t" != 'yes'  &&  "$t" != 'n'  &&  "$t" != 'no' ]]; then
746                error "Illegal default answer: $default"
747            fi
748            default=$t
749            shift
750            ;;
751
752        --timeout)
753            shift
754            timeout=$1
755            if [[ ! "$timeout" ]]; then error "Missing timeout value"; fi
756            #if [[ ! "$timeout" =~ ^[0-9][0-9]*$ ]]; then error "Illegal timeout value: $timeout"; fi
757            shift
758            ;;
759
760        -*)
761            error "Unrecognized option: $1"
762            ;;
763
764        *)
765            break
766            ;;
767        esac
768    done
769
770    if [[ $timeout -ne 0  &&  ! "$default" ]]; then
771        error "Non-zero timeout requires a default answer"
772    fi
773
774    if [[ ! "$*" ]]; then error "Missing question"; fi
775
776    while [[ $ok -eq 0 ]]
777    do
778        if [[ $timeout -ne 0 ]]; then
779            if ! read -t $timeout -p "$*" ans; then
780                ans=$default
781            else
782                # Turn off timeout if answer entered.
783                timeout=0
784                if [[ ! "$ans" ]]; then ans=$default; fi
785            fi
786        else
787            read -p "$*" ans
788            if [[ ! "$ans" ]]; then
789                ans=$default
790            else
791                ans=$(echo $ans | tr '[:upper:]' '[:lower:]')
792            fi
793        fi
794
795        if [[ "$ans" == 'y'  ||  "$ans" == 'yes'  ||  "$ans" == 'n'  ||  "$ans" == 'no' ]]; then
796            ok=1
797        fi
798
799        if [[ $ok -eq 0 ]]; then warning "Valid answers are: yes y no n"; fi
800    done
801    [[ "$ans" = "y" || "$ans" == "yes" ]]
802}
803 
Note: See TracBrowser for help on using the repository browser.