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

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 b6e2f16 was 88f66f2, checked in by ramon <ramongomez@…>, 8 years ago

#768: ogLive usa subdirectorio por defecto si no encuentra el solicitado en la variable del kernel oglivedir.

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

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