source: client/engine/Boot.lib @ fc57da8

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 fc57da8 was 872b044, checked in by adv <adv@…>, 7 years ago

#853 Adapting Boot.lib library for doxygen

  • Property mode set to 100755
File size: 79.0 KB
RevLine 
[b094c59]1#!/bin/bash
2#/**
3#@file    Boot.lib
4#@brief   Librería o clase Boot
5#@class   Boot
6#@brief   Funciones para arranque y post-configuración de sistemas de archivos.
[16360e4]7#@version 1.1.0
[b094c59]8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
[dc4eac6]13#         ogBoot int_ndisk int_nfilesys [str_kernel str_initrd str_krnlparams]
[b094c59]14#@brief   Inicia el proceso de arranque de un sistema de archivos.
[42669ebf]15#@param   int_ndisk      nº de orden del disco
[16360e4]16#@param   int_nfilesys   nº de orden del sistema de archivos
17#@param   str_krnlparams parámetros de arranque del kernel (opcional)
[b094c59]18#@return  (activar el sistema de archivos).
19#@exception OG_ERR_FORMAT    Formato incorrecto.
20#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
21#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
22#@exception OG_ERR_NOTOS     La partición no tiene instalado un sistema operativo.
[16360e4]23#@note    En Linux, si no se indican los parámetros de arranque se detectan de la opción por defecto del cargador GRUB.
[f5432db7]24#@note    En Linux, debe arrancarse la partición del directorio \c /boot
[3915005]25#@version 0.1 - Integración para OpenGnSys. - EAC: HDboot; BootLinuxEX en Boot.lib 
[985bef0]26#@author  Antonio J. Doblas Viso, Universidad de Malaga
[e05993a]27#@date    2008-10-27
[3915005]28#@version 0.9 - Adaptación para OpenGnSys.
[b094c59]29#@author  Ramon Gomez, ETSII Universidad de Sevilla
30#@date    2009-09-11
[40ad2e8d]31#@version 1.0.4 - Soporta modo de arranque Windows (parámetro de inicio "winboot").
32#@author  Ramon Gomez, ETSII Universidad de Sevilla
33#@date    2012-04-12
[8fc2631]34#@version 1.0.6 - Selección a partir de tipo de sistema operativo (en vez de S.F.) y arrancar Linux con /boot separado.
[2b2f533]35#@author  Ramon Gomez, ETSII Universidad de Sevilla
[8fc2631]36#@date    2015-06-05
[16360e4]37#@version 1.1.0 - Nuevo parámetro opcional con opciones de arranque del Kernel.
38#@author  Ramon Gomez, ETSII Universidad de Sevilla
39#@date    2015-07-15
[1e7eaab]40#*/ ##
[42669ebf]41function ogBoot ()
42{
[b094c59]43# Variables locales.
[40ad2e8d]44local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER f
[6893030]45local EFIDISK EFIPART EFIDIR BOOTLABEL BOOTNO
[b094c59]46
[1e7eaab]47# Si se solicita, mostrar ayuda.
[b094c59]48if [ "$*" == "help" ]; then
[dc4eac6]49    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_kernel str_initrd str_kernelparams]" \
50           "$FUNCNAME 1 1" "$FUNCNAME 1 2 \"/boot/vmlinuz /boot/initrd.img root=/dev/sda2 ro\""
[b094c59]51    return
52fi
[16360e4]53# Error si no se reciben 2 o 3 parámetros.
54[ $# == 2 ] || [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[b094c59]55
[1e7eaab]56# Detectar tipo de sistema de archivos y montarlo.
[049eadbe]57PART=$(ogDiskToDev $1 $2) || return $?
[2b2f533]58TYPE=$(ogGetOsType $1 $2) || return $?
[a73649d]59# Error si no puede montar sistema de archivos.
[5962edd]60MNTDIR=$(ogMount $1 $2) || return $?
[b094c59]61
62case "$TYPE" in
[2b2f533]63    Linux|Android)
[16360e4]64        # Si no se indican, obtiene los parámetros de arranque para Linux.
[da82642]65        PARAMS="${3:-$(ogLinuxBootParameters $1 $2 2>/dev/null)}"
[21815bd5]66        # Si no existe, buscar sistema de archivo /boot en /etc/fstab.
67        if [ -z "$PARAMS" -a -e $MNTDIR/etc/fstab ]; then
68            # Localizar S.F. /boot en /etc/fstab del S.F. actual.
[da82642]69            PART=$(ogDevToDisk $(awk '$1!="#" && $2=="/boot" {print $1}' $MNTDIR/etc/fstab))
[8fc2631]70            # Montar S.F. de /boot.
71            MNTDIR=$(ogMount $PART) || return $?
[21815bd5]72            # Buscar los datos de arranque.
73            PARAMS=$(ogLinuxBootParameters $PART) || exit $?
74        fi
[f5432db7]75        read -e KERNEL INITRD APPEND <<<"$PARAMS"
[1e7eaab]76        # Si no hay kernel, no hay sistema operativo.
[6893030]77        [ -n "$KERNEL" -a -e "$MNTDIR/$KERNEL" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE)" || return $?
[1e7eaab]78        # Arrancar de partición distinta a la original.
[049eadbe]79        [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}')
[6893030]80        # Comprobar tipo de sistema.
81        if ogIsEfiActive; then
82            # Obtener parcición EFI.
83            read -e EFIDISK EFIPART <<<"$(ogGetEsp)"
84            [ -n "$EFIPART" ] || ogRaiseError $OG_ERR_PARTITION "ESP" || return $?
85            # Comprobar si el Kernel está firmado.
[d2a274a]86            if ! file -k "$MNTDIR/$KERNEL" | grep -q "EFI app"; then
[b242c72]87                ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE, EFI)"
[6893030]88                return $?
89            fi
90            # Crear directorio para el cargador y copiar los ficheros.
91            EFIDIR=$(ogMount $EFIDISK $EFIPART) || exit $?
92            BOOTLABEL=$(printf "Part-%02d-%02d" $1 $2)
93            mkdir -p $EFIDIR/EFI/$BOOTLABEL
94            cp $MNTDIR/$KERNEL $EFIDIR/EFI/$BOOTLABEL/vmlinuz.efi
95            cp $MNTDIR/$INITRD $EFIDIR/EFI/$BOOTLABEL/initrd.img
96            # Borrar cargador guardado con la misma etiqueta.
97            BOOTNO=$(efibootmgr -v | awk -v L=$BOOTLABEL '{if ($2==L) print $1}')
98            [ -n "$BOOTNO" ] && efibootmgr -B -b ${BOOTNO:4:4}
99            # Crear orden de arranque (con unos valores por defecto).
100            efibootmgr -C -d $(ogDiskToDev $EFIDISK) -p $EFIPART -L "$BOOTLABEL" -l /EFI/$BOOTLABEL/vmlinuz.efi -u "initrd=/EFI/$BOOTLABEL/initrd.img $APPEND"
101            # Marcar próximo arranque y reiniciar.
102            BOOTNO=$(efibootmgr -v | awk -v L="$BOOTLABEL" '{if ($2==L) print $1}')
103            [ -n "$BOOTNO" ] && efibootmgr -n ${BOOTNO:4:4}
104            reboot
105        else
106            # Arranque BIOS: configurar kernel Linux con los parámetros leídos de su GRUB.
107            kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}"
[40ad2e8d]108            kexec -e &
[6893030]109        fi
110        ;;
111    Windows)
112        # Comprobar tipo de sistema.
113        if ogIsEfiActive; then
114            # Obtener parcición EFI.
115            read -e EFIDISK EFIPART <<<"$(ogGetEsp)"
116            [ -n "$EFIPART" ] || ogRaiseError $OG_ERR_PARTITION "ESP" || return $?
117            EFIDIR=$(ogMount $EFIDISK $EFIPART) || exit $?
[b242c72]118            # Comprobar cargador (si no existe buscar por defecto en ESP).
119            LOADER=$(ogGetPath $1 $2 /Boot/bootmgfw.efi)
120            [ -z "$LOADER" ] && LOADER=$(ogGetPath $EFIDIR/EFI/Microsoft/Boot/bootmgfw.efi)
121            [ -n "$LOADER" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE, EFI)" || return $?
122            # Crear directorio para el cargador y copiar los ficheros.
[6893030]123            BOOTLABEL=$(printf "Part-%02d-%02d" $1 $2)
124            mkdir -p $EFIDIR/EFI/$BOOTLABEL
125            cp -a $(dirname "$LOADER") $EFIDIR/EFI/$BOOTLABEL
126            # Borrar cargador guardado con la misma etiqueta.
127            BOOTNO=$(efibootmgr -v | awk -v L=$BOOTLABEL '{if ($2==L) print $1}')
128            [ -n "$BOOTNO" ] && efibootmgr -B -b ${BOOTNO:4:4}
129            # Crear orden de arranque (con unos valores por defecto).
130            efibootmgr -C -d $(ogDiskToDev $EFIDISK) -p $EFIPART -L "$BOOTLABEL" -l "/EFI/$BOOTLABEL/Boot/BOOTMGFW.EFI"
131            # Marcar próximo arranque y reiniciar.
132            BOOTNO=$(efibootmgr -v | awk -v L="$BOOTLABEL" '{if ($2==L) print $1}')
133            [ -n "$BOOTNO" ] && efibootmgr -n ${BOOTNO:4:4}
134            reboot
[40ad2e8d]135        else
[6893030]136            # Arranque BIOS: compruebar si hay un cargador de Windows.
137            for f in io.sys ntldr bootmgr; do
138                FILE="$(ogGetPath $1 $2 $f 2>/dev/null)"
139                [ -n "$FILE" ] && LOADER="$f"
140            done
141            [ -n "$LOADER" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE)" || return $?
142            if [ "$winboot" == "kexec" ]; then
143                # Modo de arranque en caliente (con kexec).
144                cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
145                kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
146                kexec -e &
147            else
148                # Modo de arranque por reinicio (con reboot).
149                dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3
150                dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3
151                dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3
152                if  [ -z "$(ogGetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleannboot')" ]; then
153                    ogAddRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot'
154                    ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot' "cmd /c del c:\ogboot.*"
155                fi
156                # Activar la partición.
157                ogSetPartitionActive $1 $2
158                reboot
[fc65d8d9]159            fi
[75a296b]160        fi
[f5432db7]161        ;;
[2b2f533]162    MacOS)
163        # Modo de arranque por reinicio.
164        # Nota: el cliente tiene que tener configurado correctamente Grub.
165        touch ${MNTDIR}/boot.mac &>/dev/null
166        reboot
167        ;;
168    GrubLoader)
169        # Reiniciar.
170        reboot
171        ;;
[477ba42]172    *)  ogRaiseError $OG_ERR_NOTOS "$1 $2 ${TYPE:+($TYPE)}"
[326cec3]173        return $?
[f5432db7]174        ;;
[b094c59]175esac
176}
177
178
179#/**
[16360e4]180#         ogGetWindowsName int_ndisk int_nfilesys
[3e1561d]181#@brief   Muestra el nombre del equipo en el registro de Windows.
[42669ebf]182#@param   int_ndisk      nº de orden del disco
[16360e4]183#@param   int_nfilesys   nº de orden del sistema de archivos
[3e1561d]184#@return  str_name - nombre del equipo
185#@exception OG_ERR_FORMAT    Formato incorrecto.
186#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
187#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]188#@version 0.9 - Adaptación para OpenGnSys.
[3e1561d]189#@author  Ramon Gomez, ETSII Universidad de Sevilla
190#@date    2009-09-23
[1e7eaab]191#*/ ##
[42669ebf]192function ogGetWindowsName ()
193{
[3e1561d]194# Variables locales.
[c198e60]195local MNTDIR
[3e1561d]196
[1e7eaab]197# Si se solicita, mostrar ayuda.
[3e1561d]198if [ "$*" == "help" ]; then
199    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
200           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
201    return
202fi
[1e7eaab]203# Error si no se reciben 2 parámetros.
[3e1561d]204[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
205
[1e7eaab]206# Montar el sistema de archivos.
[5962edd]207MNTDIR=$(ogMount $1 $2) || return $?
[3e1561d]208
[1e7eaab]209# Obtener dato del valor de registro.
[3e1561d]210ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
211}
212
213
214#/**
[b94c497]215#         ogLinuxBootParameters int_ndisk int_nfilesys
[b094c59]216#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
[42669ebf]217#@param   int_ndisk      nº de orden del disco
[b94c497]218#@param   int_nfilesys   nº de orden del sistema de archivos
[42669ebf]219#@return  str_kernel str_initrd str_parameters ...
[b094c59]220#@exception OG_ERR_FORMAT    Formato incorrecto.
221#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
222#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[055adcf]223#@warning Función básica usada por \c ogBoot
[3915005]224#@version 0.9 - Primera adaptación para OpenGnSys.
[b094c59]225#@author  Ramon Gomez, ETSII Universidad de Sevilla
226#@date    2009-09-11
[199bdf3]227#@version 0.9.2 - Soporta partición /boot independiente.
228#@author  Ramon Gomez, ETSII Universidad de Sevilla
229#@date    2010-07-20
[b94c497]230#@version 1.0.5 - Mejoras en tratamiento de GRUB2.
231#@author  Ramon Gomez, ETSII Universidad de Sevilla
232#@date    2013-05-14
[6647a20]233#@version 1.0.6 - Detectar instalaciones sobre EFI.
234#@author  Ramon Gomez, ETSII Universidad de Sevilla
235#@date    2014-09-15
[1e7eaab]236#*/ ##
[42669ebf]237function ogLinuxBootParameters ()
238{
[b094c59]239# Variables locales.
[6647a20]240local MNTDIR CONFDIR CONFFILE f
[b094c59]241
[1e7eaab]242# Si se solicita, mostrar ayuda.
[b094c59]243if [ "$*" == "help" ]; then
[b94c497]244    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
245           "$FUNCNAME 1 2  ==>  /vmlinuz-3.5.0-21-generic /initrd.img-3.5.0-21-generic root=/dev/sda2 ro splash"
[b094c59]246    return
247fi
[1e7eaab]248# Error si no se reciben 2 parámetros.
[b094c59]249[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
250
[1e7eaab]251# Detectar id. de tipo de partición y codificar al mnemonico.
[5962edd]252MNTDIR=$(ogMount $1 $2) || return $?
[b094c59]253
254# Fichero de configuración de GRUB.
[6647a20]255CONFDIR=$MNTDIR                               # Sistema de archivos de arranque (/boot).
256[ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot   # Sist. archivos raíz con directorio boot.
[d7ffbfc]257for f in $MNTDIR/{,boot/}{{grubMBR,grubPARTITION}/boot/,}{grub{,2},{,efi/}EFI/*}/{menu.lst,grub.cfg}; do
[6647a20]258    [ -r $f ] && CONFFILE=$f
259done
[cf8a0ae]260[ -n "$CONFFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" || return $?
[b094c59]261
[1e7eaab]262# Toma del fichero de configuracion los valores del kernel, initrd
[ee4a96e]263#       y parámetros de arranque usando las cláusulas por defecto
264#       ("default" en GRUB1, "set default" en GRUB2)
265#       y los formatea para que sean compatibles con \c kexec .  */
[1e7eaab]266# /* (comentario Doxygen)
[b094c59]267awk 'BEGIN {cont=-1;}
[b94c497]268     $1~/^default$/     {sub(/=/," "); def=$2;}
[6647a20]269     $1~/^set$/ && $2~/^default/ { gsub(/[="]/," "); def=$3;
[b94c497]270                                   if (def ~ /saved_entry/) def=0;
[6647a20]271                                 }
[b94c497]272     $1~/^(title|menuentry)$/ {cont++}
[529c585]273     $1~/^set$/ && $2~/^root=.\(hd'$[1-1]',(msdos|gpt)'$2'\).$/ { if (def==0) def=cont; }
[8fc2631]274     $1~/^(kernel|linux(16|efi)?)$/ { if (def==cont) {
[6647a20]275                                       kern=$2;
276                                       sub($1,""); sub($1,""); sub(/^[ \t]*/,""); app=$0
[8fc2631]277                                      } # /* (comentario Doxygen)
278                                    }
279     $1~/^initrd(16|efi)?$/ {if (def==cont) init=$2}
[b094c59]280     END {if (kern!="") printf("%s %s %s", kern,init,app)}
[199bdf3]281    ' $CONFFILE
[1e7eaab]282# */ (comentario Doxygen)
[b094c59]283}
284
[3e1561d]285
286#/**
[e538e62]287#         ogSetWindowsName int_ndisk int_nfilesys str_name
[3e1561d]288#@brief   Establece el nombre del equipo en el registro de Windows.
[42669ebf]289#@param   int_ndisk      nº de orden del disco
[e538e62]290#@param   int_nfilesys   nº de orden del sistema de archivos
[42669ebf]291#@param   str_name       nombre asignado
[3e1561d]292#@return  (nada)
[e538e62]293#@exception OG_ERR_FORMAT     Formato incorrecto.
294#@exception OG_ERR_NOTFOUND   Disco o particion no corresponden con un dispositivo.
295#@exception OG_ERR_PARTITION  Tipo de partición desconocido o no se puede montar.
296#@exception OG_ERR_OUTOFLIMIT Nombre Netbios con más de 15 caracteres.
[3915005]297#@version 0.9 - Adaptación a OpenGnSys.
[3e1561d]298#@author  Ramon Gomez, ETSII Universidad de Sevilla
299#@date    2009-09-24
[e538e62]300#@version 1.0.5 - Establecer restricción de tamaño de nombre Netbios.
301#@author  Ramon Gomez, ETSII Universidad de Sevilla
302#@date    2013-03-20
[1e7eaab]303#*/ ##
[42669ebf]304function ogSetWindowsName ()
305{
[3e1561d]306# Variables locales.
307local PART MNTDIR NAME
308
[1e7eaab]309# Si se solicita, mostrar ayuda.
[3e1561d]310if [ "$*" == "help" ]; then
[e538e62]311    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys str_name" \
[3e1561d]312           "$FUNCNAME 1 1 PRACTICA-PC"
313    return
314fi
[1e7eaab]315# Error si no se reciben 3 parámetros.
[3e1561d]316[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[e538e62]317# Error si el nombre supera los 15 caracteres.
318[ ${#3} -le 15 ] || ogRaiseError $OG_ERR_OUTOFLIMIT "\"${3:0:15}...\"" || return $?
[3e1561d]319
[42669ebf]320# Montar el sistema de archivos.
[5962edd]321MNTDIR=$(ogMount $1 $2) || return $?
322
323# Asignar nombre.
[3e1561d]324NAME="$3"
325
[1e7eaab]326# Modificar datos de los valores de registro.
[4b9cdda]327ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null
328ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
[42e8020]329ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\HostName' "$NAME" 2>/dev/null
[4b9cdda]330ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
331ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
[42e8020]332ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV HostName' "$NAME" 2>/dev/null
[4b9cdda]333ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
[3e1561d]334}
335
[f5432db7]336
[4b9cdda]337#/**
338#         ogSetWinlogonUser int_ndisk int_npartition str_username
339#@brief   Establece el nombre de usuario por defecto en la entrada de Windows.
340#@param   int_ndisk      nº de orden del disco
341#@param   int_npartition nº de orden de la partición
342#@param   str_username   nombre de usuario por defecto
343#@return  (nada)
344#@exception OG_ERR_FORMAT    Formato incorrecto.
345#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
346#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]347#@version 0.9.2 - Adaptación a OpenGnSys.
[4b9cdda]348#@author  Ramon Gomez, ETSII Universidad de Sevilla
349#@date    2010-07-20
350#*/ ##
351function ogSetWinlogonUser ()
352{
353# Variables locales.
354local PART MNTDIR NAME
355
356# Si se solicita, mostrar ayuda.
357if [ "$*" == "help" ]; then
358    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \
359           "$FUNCNAME 1 1 USUARIO"
360    return
361fi
362# Error si no se reciben 3 parámetros.
363[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
364
365# Montar el sistema de archivos.
[5962edd]366MNTDIR=$(ogMount $1 $2) || return $?
367
368# Asignar nombre.
[4b9cdda]369NAME="$3"
370
371# Modificar datos en el registro.
372ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3"
373}
374
[38231e9]375
376#/**
[9e8773c]377#         ogBootMbrXP int_ndisk
[38231e9]378#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
[42669ebf]379#@param   int_ndisk      nº de orden del disco
[945b003]380#@return  salida del programa my-sys
[38231e9]381#@exception OG_ERR_FORMAT    Formato incorrecto.
382#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]383#@version 0.9 - Adaptación a OpenGnSys.
[38231e9]384#@author  Antonio J. Doblas Viso. Universidad de Málaga
385#@date    2009-09-24
386#*/ ##
387
[9e8773c]388function ogBootMbrXP ()
[e05993a]389{
[38231e9]390# Variables locales.
[a73649d]391local DISK
[38231e9]392
393# Si se solicita, mostrar ayuda.
394if [ "$*" == "help" ]; then
395    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
[a73649d]396           "$FUNCNAME 1"
[38231e9]397    return
[945b003]398fi
[a73649d]399# Error si no se recibe 1 parámetro.
[38231e9]400[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
401
[a73649d]402DISK="$(ogDiskToDev $1)" || return $?
403ms-sys -z -f $DISK
404ms-sys -m -f $DISK
[945b003]405}
[42669ebf]406
[fdad5a6]407
[9e8773c]408#/**
409#         ogBootMbrGeneric int_ndisk
410#@brief   Genera un nuevo Codigo de arranque en el MBR del disco indicado, compatible con los SO tipo Windows, Linux.
411#@param   int_ndisk      nº de orden del disco
412#@return  salida del programa my-sys
413#@exception OG_ERR_FORMAT    Formato incorrecto.
414#@exception OG_ERR_NOTFOUND Tipo de partición desconocido o no se puede montar.
[3915005]415#@version 0.9 - Adaptación a OpenGnSys.
[9e8773c]416#@author  Antonio J. Doblas Viso. Universidad de Málaga
417#@date    2009-09-24
418#*/ ##
419
420function ogBootMbrGeneric ()
421{
422# Variables locales.
[a73649d]423local DISK
[9e8773c]424
425# Si se solicita, mostrar ayuda.
426if [ "$*" == "help" ]; then
427    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
428           "$FUNCNAME 1 "
429    return
430fi
[a73649d]431# Error si no se recibe 1 parámetro.
[9e8773c]432[ $# == 1 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
433
[a73649d]434DISK="$(ogDiskToDev $1)" || return $?
435ms-sys -z -f $DISK
436ms-sys -s -f $DISK
[9e8773c]437}
438
439
440
[fdad5a6]441
442#/**
443#         ogFixBootSector int_ndisk int_parition
444#@brief   Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs
445#@param   int_ndisk      nº de orden del disco
446#@param   int_partition     nº de particion
447#@return 
448#@exception OG_ERR_FORMAT    Formato incorrecto.
449#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]450#@version 0.9 - Adaptación a OpenGnSys.
[fdad5a6]451#@author  Antonio J. Doblas Viso. Universidad de Málaga
452#@date    2009-09-24
453#*/ ##
454
455function ogFixBootSector ()
456{
457# Variables locales.
[1cd64e6]458local PARTYPE DISK PART FILE
[fdad5a6]459
460# Si se solicita, mostrar ayuda.
461if [ "$*" == "help" ]; then
462    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
463           "$FUNCNAME 1 1 "
464    return
465fi
466
467# Error si no se reciben 2 parámetros.
468[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
469
470#TODO, solo si la particion existe
471#TODO, solo si es ntfs o fat
472PARTYPE=$(ogGetPartitionId $1 $2)
[3915005]473case "$PARTYPE" in
[0a7f5c9]474        1|4|6|7|b|c|e|f|17|700)
[fdad5a6]475        ;;
476        *)
477        return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
478        ;;
479esac
480
481ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
482
483#Preparando instruccion
484let DISK=$1-1   
485PART=$2
[1cd64e6]486FILE=/tmp/temp$$
[fdad5a6]487cat > $FILE <<EOF
488disk=$DISK
489main_part=$PART
490fix_first_sector=yes
491EOF
492
[5fde4bc]493spartlnx.run -cui -nm -a -f $FILE &
494sleep 5
495ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
[1cd64e6]496rm -f $FILE
[fdad5a6]497}
498
499
500
501#/**
502#         ogWindowsBootParameters int_ndisk int_parition
[78b5dfe7]503#@brief   Configura el gestor de arranque de windows 7 / vista / XP / 2000
[fdad5a6]504#@param   int_ndisk      nº de orden del disco
505#@param   int_partition     nº de particion
506#@return 
507#@exception OG_ERR_FORMAT    Formato incorrecto.
508#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]509#@version 0.9 - Integración desde EAC para OpenGnSys.
[fdad5a6]510#@author  Antonio J. Doblas Viso. Universidad de Málaga
511#@date    2009-09-24
[78b5dfe7]512#@version 1.0.1 - Adapatacion para OpenGnsys.
513#@author  Antonio J. Doblas Viso. Universidad de Málaga
514#@date    2011-05-20
[e763190]515#@version 1.0.5 - Soporte para Windows 8 y Windows 8.1.
516#@author  Ramon Gomez, ETSII Universidad de Sevilla
517#@date    2014-01-28
[b6971f1]518#@version 1.1.0 - Soporte para Windows 10.
519#@author  Ramon Gomez, ETSII Universidad de Sevilla
520#@date    2016-01-19
[fdad5a6]521#*/ ##
522
523function ogWindowsBootParameters ()
524{
525# Variables locales.
[ccf1fa0]526local PART DISK FILE WINVER MOUNT
[fdad5a6]527
528# Si se solicita, mostrar ayuda.
529if [ "$*" == "help" ]; then
530    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
531           "$FUNCNAME 1 1 "
532    return
533fi
534
535# Error si no se reciben 2 parámetros.
536[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
537
538ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
539
[e763190]540#Preparando variables adaptadas a sintaxis windows.
541let DISK=$1-1
542PART=$2
543FILE=/tmp/temp$$
544
[ccf1fa0]545# Obtener versión de Windows.
[1e4000f]546WINVER=$(ogGetOsVersion $1 $2 | awk -F"[: ]" '$1=="Windows" {if ($3=="Server") print $2,$3,$4; else print $2,$3;}')
[ccf1fa0]547[ -z "$WINVER" ] && return $(ogRaiseError $OG_ERR_NOTOS "Windows"; echo $?)
548
549# Acciones para Windows XP.
550if [[ "$WINVER" =~ "XP" ]]; then
551    MOUNT=$(ogMount $1 $2)
552    [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTFOUND "boot.ini"; echo $?)
553    cat ${MOUNT}/boot.ini | sed s/partition\([0-9]\)/partition\($PART\)/g | sed s/rdisk\([0-9]\)/rdisk\($DISK\)/g > ${MOUNT}/tmp.boot.ini; mv ${MOUNT}/tmp.boot.ini ${MOUNT}/boot.ini
554    return 0
[fdad5a6]555fi
556
557ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
[78b5dfe7]558
[fdad5a6]559
560#Preparando instruccion Windows Resume Application
561cat > $FILE <<EOF
562boot_disk=$DISK
563boot_main_part=$PART
564disk=$DISK
565main_part=$PART
566boot_entry=Windows Resume Application
567EOF
[5fde4bc]568spartlnx.run -cui -nm -w -f $FILE &
569sleep 5
570ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
571
572 
[fdad5a6]573
574#Preparando instruccion tipo windows
575cat > $FILE <<EOF
576boot_disk=$DISK
577boot_main_part=$PART
578disk=$DISK
579main_part=$PART
580boot_entry=$WINVER
581EOF
[5fde4bc]582spartlnx.run -cui -nm -w -f $FILE &
583sleep 5
584ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
585
[fdad5a6]586
[250742d]587##Preparando instruccion        Ramdisk Options
[5fde4bc]588cat > $FILE <<EOF
589boot_disk=$DISK
590boot_main_part=$PART
591disk=$DISK
592main_part=$PART
593boot_entry=Ramdisk Options
594EOF
595spartlnx.run -cui -nm -w -f $FILE &
596sleep 5
597ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
598
[fdad5a6]599
600#Preparando instruccion Windows Boot Manager
601cat > $FILE <<EOF
602boot_disk=$DISK
603boot_main_part=$PART
604disk=$DISK
605main_part=$PART
606boot_entry=Windows Boot Manager
607EOF
[5fde4bc]608spartlnx.run -cui -nm -w -f $FILE &
609sleep 5
610ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
611
[fdad5a6]612
613#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
[5fde4bc]614cat > $FILE <<EOF
615boot_disk=$DISK
616boot_main_part=$PART
617disk=$DISK
618main_part=$PART
619boot_entry=Herramienta de diagnóstico de memoria de Windows
620EOF
621spartlnx.run -cui -nm -w -f $FILE &
622sleep 5
623ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
[fdad5a6]624
625}
[3915005]626
[fdad5a6]627
[872b044]628
629#/**
[78b5dfe7]630#         ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition
[fdad5a6]631#@brief   Registra una partición en windows con un determinado volumen.
632#@param   int_ndisk      nº de orden del disco a registrar
633#@param   int_partition     nº de particion a registrar
634#@param   str_volumen      volumen a resgistar
635#@param   int_ndisk_windows      nº de orden del disco donde esta windows
636#@param   int_partition_windows     nº de particion donde esta windows
637#@return 
638#@exception OG_ERR_FORMAT    Formato incorrecto.
639#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]640#@version 0.9 - Adaptación a OpenGnSys.
[fdad5a6]641#@author  Antonio J. Doblas Viso. Universidad de Málaga
642#@date    2009-09-24
643#*/ ##
[78b5dfe7]644function ogWindowsRegisterPartition ()
[3915005]645{
[fdad5a6]646# Variables locales.
[3915005]647local PART DISK FILE REGISTREDDISK REGISTREDPART REGISTREDVOL VERSION SYSTEMROOT
[fdad5a6]648
649# Si se solicita, mostrar ayuda.
650if [ "$*" == "help" ]; then
651    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
652           "$FUNCNAME 1 1 c: 1 1"
653    return
654fi
655
656# Error si no se reciben 5 parámetros.
657[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
658
659REGISTREDDISK=$1
660REGISTREDPART=$2
661REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
662DISK=$4
663PART=$5
[3915005]664FILE=/tmp/temp$$
[fdad5a6]665
666ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
667ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
668
669ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
670
671VERSION=$(ogGetOsVersion $DISK $PART)
672
673#Systemroot
674
675if ogGetPath $DISK $PART WINDOWS
676then
677        SYSTEMROOT="Windows"
678elif ogGetPath $DISK $PART WINNT
679then
680        SYSTEMROOT="winnt"
681else
682        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
683fi
684
685ogUnmount $DISK $PART
686let DISK=$DISK-1
687let REGISTREDDISK=$REGISTREDDISK-1
688#Preparando instruccion Windows Boot Manager
689cat > $FILE <<EOF
690windows_disk=$DISK
691windows_main_part=$PART
692windows_dir=$SYSTEMROOT
693disk=$REGISTREDDISK
694main_part=$REGISTREDPART
695;ext_part
696part_letter=$REGISTREDVOL
697EOF
[5fde4bc]698spartlnx.run -cui -nm -u -f $FILE &
699sleep 5
700ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
701
[e0c0d93]702}
[ab82469]703
[872b044]704#/**
[59c5b66]705#         ogGrubInstallMbr  int_disk_GRUBCFG  int_partition_GRUBCFG 
706#@brief   Instala el grub el el MBR del primer disco duro (FIRSTSTAGE). El fichero de configuración grub.cfg ubicado según parametros disk y part(SECONDSTAGE). Admite sistemas Windows.
[9c535e0]707#@param   int_disk_SecondStage     
708#@param   int_part_SecondStage     
709#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
[ab82469]710#@return 
711#@exception OG_ERR_FORMAT    Formato incorrecto.
712#@version 1.0.2 - Primeras pruebas.
713#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
714#@date    2011-10-29
[9c535e0]715#@version 1.0.3 - Soporte para linux de 32 y 64 bits
716#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
717#@date    2012-03-13
718#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la primera etapa
719#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
720#@date    2012-03-13
[59c5b66]721#@version 1.1.0 - #791 El FIRSTSTAGE(MBR) siempre será el primer disco duro. EL SECONDSTAGE(grub.cfg) estára en el DISK y PART indicados en los parámetros.
722#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
723#@date    2017-06-19
[59cebeed]724#@version 1.1.0 - #827 Entrada para el ogLive si el equipo tiene partición cache.
725#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
726#@date    2018-01-21
[ab82469]727#*/ ##
728
[d2c8674]729function ogGrubInstallMbr ()
730{
[ab82469]731
732# Variables locales.
[1c69be8]733local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[ab82469]734
735# Si se solicita, mostrar ayuda.
736if [ "$*" == "help" ]; then
[9c535e0]737    ogHelp "$FUNCNAME" "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \"  " \
738           "$FUNCNAME 1 1 FALSE " \
739           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
[ab82469]740    return
[9c535e0]741fi 
[ab82469]742
743# Error si no se reciben 2 parámetros.
[9c535e0]744[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
[ab82469]745
746
[9c535e0]747DISK=$1; PART=$2;
748CHECKOS=${3:-"FALSE"}
749KERNELPARAM=$4
[1c69be8]750BACKUPNAME=".backup.og"
[ab82469]751
[9c535e0]752#Error si no es linux.
753#TODO: comprobar si se puede utilizar la particion windows como contenedor de grub.
[a4b1e2a]754#VERSION=$(ogGetOsVersion $DISK $PART)
755#echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
[ab82469]756
[59c5b66]757#La primera etapa del grub se fija en el primer disco duro
758FIRSTSTAGE=$(ogDiskToDev 1)
[ab82469]759
[9c535e0]760#localizar disco segunda etapa del grub
761SECONDSTAGE=$(ogMount $DISK $PART)
[ab82469]762
[a4b1e2a]763# prepara el directorio principal de la segunda etapa
764[ -d ${SECONDSTAGE}/boot/grub/ ]  || mkdir -p ${SECONDSTAGE}/boot/grub/
765
[9c535e0]766#Localizar directorio segunda etapa del grub   
767PREFIXSECONDSTAGE="/boot/grubMBR"
[ab82469]768
[9c535e0]769# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]770if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]771then
772    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
773    then
[1c69be8]774        # Si no se reconfigura se utiliza el grub.cfg orginal
775        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
776                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
777        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
778        # Reactivamos el grub con el grub.cfg original.
[9c535e0]779        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
780        return $?
781    fi
782fi
783
784# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
[52b9a3f]785
786#llamada a updateBootCache para que aloje la primera fase del ogLive
787updateBootCache
788
[9c535e0]789#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
790echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
791echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
[ab82469]792
[9c535e0]793#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup
[1c69be8]794[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]795
796#Preparar configuración segunda etapa: crear ubicacion
797mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
[09803ea]798#Preparar configuración segunda etapa: crear cabecera del fichero (ignorar errores)
799sed -i 's/^set -e/#set -e/' /etc/grub.d/00_header
800/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg 2>/dev/null
[9c535e0]801#Preparar configuración segunda etapa: crear entrada del sistema operativo
802grubSyntax "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
803
804#Instalar el grub
805grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
806}
[ab82469]807
808
[872b044]809#/**
[9c535e0]810#         ogGrubInstallPartition int_disk_SECONDSTAGE  int_partition_SECONDSTAGE bolean_Check_Os_installed_and_Configure_2ndStage
811#@brief   Instala y actualiza el gestor grub en el bootsector de la particion indicada
812#@param   int_disk_SecondStage     
813#@param   int_part_SecondStage     
814#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
815#@param   str "kernel param "   
816#@return 
817#@exception OG_ERR_FORMAT    Formato incorrecto.
818#@version 1.0.2 - Primeras pruebas.
819#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
820#@date    2011-10-29
821#@version 1.0.3 - Soporte para linux de 32 y 64 bits
822#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
823#@date    2012-03-13
824#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la priemra etapa
825#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
826#@date    2012-03-13
827#*/ ##
[ab82469]828
[d2c8674]829function ogGrubInstallPartition ()
830{
[ab82469]831
[9c535e0]832# Variables locales.
[1c69be8]833local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[9c535e0]834
835# Si se solicita, mostrar ayuda.
836if [ "$*" == "help" ]; then
837    ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \" " \
838           "$FUNCNAME 1 1 FALSE " \
839           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
840    return
841fi 
842
843# Error si no se reciben 2 parámetros.
844[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
845
846DISK=$1; PART=$2;
847CHECKOS=${3:-"FALSE"}
848KERNELPARAM=$4
[1c69be8]849BACKUPNAME=".backup.og"
[9c535e0]850
851#error si no es linux.
852VERSION=$(ogGetOsVersion $DISK $PART)
853echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
854
855#Localizar primera etapa del grub
856FIRSTSTAGE=$(ogDiskToDev $DISK $PART)
857
858#localizar disco segunda etapa del grub
859SECONDSTAGE=$(ogMount $DISK $PART)
860
861#Localizar directorio segunda etapa del grub   
862PREFIXSECONDSTAGE="/boot/grubPARTITION"
863
864# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]865if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]866then
867    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
868    then
[1c69be8]869        # Si no se reconfigura se utiliza el grub.cfg orginal
870        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
871                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
872        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
873        # Reactivamos el grub con el grub.cfg original.
[9c535e0]874        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
875        return $?
876    fi
877fi
878
879# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
880#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
881echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
882echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
883
[1c69be8]884#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup.og
885[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]886
887#Preparar configuración segunda etapa: crear ubicacion
888mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
[09803ea]889#Preparar configuración segunda etapa: crear cabecera del fichero (ingnorar errores)
890sed -i 's/^set -e/#set -e/' /etc/grub.d/00_header
891/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg 2>/dev/null
[9c535e0]892#Preparar configuración segunda etapa: crear entrada del sistema operativo
893grubSyntax $DISK $PART "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
894
895#Instalar el grub
896grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
[ab82469]897}
898
[fd0d6e5]899
[00cede9]900#/**
[c9c2f1d1]901#         ogConfigureFstab int_ndisk int_nfilesys
[870619d]902#@brief   Configura el fstab según particiones existentes
[00cede9]903#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]904#@param   int_nfilesys   nº de orden del sistema de archivos
[00cede9]905#@return  (nada)
906#@exception OG_ERR_FORMAT    Formato incorrecto.
[c9c2f1d1]907#@exception OG_ERR_NOTFOUND  No se encuentra el fichero fstab a procesar.
908#@warning Puede haber un error si hay más de 1 partición swap.
[870619d]909#@version 1.0.5 - Primera versión para OpenGnSys. Solo configura la SWAP
910#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
[c9c2f1d1]911#@date    2013-03-21
[870619d]912#@version 1.0.6b - correccion. Si no hay partición fisica para la SWAP, eliminar entrada del fstab. 
913#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
914#@date    2016-11-03
[00cede9]915#*/ ##
[d2c8674]916function ogConfigureFstab ()
917{
[00cede9]918# Variables locales.
[c9c2f1d1]919local FSTAB DEFROOT PARTROOT DEFSWAP PARTSWAP
[00cede9]920
921# Si se solicita, mostrar ayuda.
922if [ "$*" == "help" ]; then
[c9c2f1d1]923    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
924           "$FUNCNAME 1 1"
[00cede9]925    return
926fi
927# Error si no se reciben 2 parámetros.
928[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[c9c2f1d1]929# Error si no se encuentra un fichero  etc/fstab  en el sistema de archivos.
930FSTAB=$(ogGetPath $1 $2 /etc/fstab) 2>/dev/null
931[ -n "$FSTAB" ] || ogRaiseError $OG_ERR_NOTFOUND "$1,$2,/etc/fstab" || return $?
932
933# Hacer copia de seguridad del fichero fstab original.
934cp -a ${FSTAB} ${FSTAB}.backup
935# Dispositivo del raíz en fichero fstab: 1er campo (si no tiene "#") con 2º campo = "/".
936DEFROOT=$(awk '$1!~/#/ && $2=="/" {print $1}' ${FSTAB})
937PARTROOT=$(ogDiskToDev $1 $2)
[200635a]938# Configuración de swap (solo 1ª partición detectada).
939PARTSWAP=$(blkid -t TYPE=swap | awk -F: 'NR==1 {print $1}')
[00cede9]940if [ -n "$PARTSWAP" ]
941then
[c9c2f1d1]942    # Dispositivo de swap en fichero fstab: 1er campo (si no tiene "#") con 3er campo = "swap".
943    DEFSWAP=$(awk '$1!~/#/ && $3=="swap" {print $1}' ${FSTAB})
[00cede9]944    if [ -n "$DEFSWAP" ]
[c9c2f1d1]945    then
[870619d]946        echo "Hay definicion de SWAP en el FSTAB $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP"   # Mensaje temporal.
[c9c2f1d1]947        sed "s|$DEFSWAP|$PARTSWAP|g ; s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
[00cede9]948    else
[870619d]949        echo "No hay definicion de SWAP y si hay partición SWAP -> moficamos fichero"   # Mensaje temporal.
[c9c2f1d1]950        sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
951        echo "$PARTSWAP  none    swap    sw   0  0" >> ${FSTAB}
[00cede9]952    fi 
953else
[870619d]954    echo "No hay partición SWAP -> configuramos FSTAB"  # Mensaje temporal.
955    sed "/swap/d" ${FSTAB}.backup > ${FSTAB}
[00cede9]956fi
957}
[9c535e0]958
[c9c2f1d1]959
[872b044]960
[764f50e]961#/**
[c9c2f1d1]962#         ogSetLinuxName int_ndisk int_nfilesys [str_name]
[764f50e]963#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
964#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]965#@param   int_nfilesys   nº de orden del sistema de archivos
966#@param   str_name       nombre asignado (opcional)
[764f50e]967#@return  (nada)
968#@exception OG_ERR_FORMAT    Formato incorrecto.
969#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
970#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]971#@note    Si no se indica nombre, se asigna un valor por defecto.
972#@version 1.0.5 - Primera versión para OpenGnSys.
973#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
974#@date    2013-03-21
[764f50e]975#*/ ##
976function ogSetLinuxName ()
977{
978# Variables locales.
[c9c2f1d1]979local MNTDIR ETC NAME
[764f50e]980
981# Si se solicita, mostrar ayuda.
982if [ "$*" == "help" ]; then
[c9c2f1d1]983    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_name]" \
984           "$FUNCNAME 1 1" "$FUNCNAME 1 1 practica-pc"
[764f50e]985    return
986fi
[c9c2f1d1]987# Error si no se reciben 2 o 3 parámetros.
988case $# in
989    2)   # Asignar nombre automático (por defecto, "pc").
990         NAME="$(ogGetHostname)"
991         NAME=${NAME:-"pc"} ;;
992    3)   # Asignar nombre del 3er parámetro.
993         NAME="$3" ;;
994    *)   # Formato de ejecución incorrecto.
995         ogRaiseError $OG_ERR_FORMAT
996         return $?
997esac
[764f50e]998
999# Montar el sistema de archivos.
[5962edd]1000MNTDIR=$(ogMount $1 $2) || return $?
[764f50e]1001
1002ETC=$(ogGetPath $1 $2 /etc)
1003
1004if [ -d "$ETC" ]; then
1005        #cambio de nombre en hostname
[c9c2f1d1]1006        echo "$NAME" > $ETC/hostname
[764f50e]1007        #Opcion A para cambio de nombre en hosts
1008        #sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts
[c9c2f1d1]1009        #Opcion B componer fichero de hosts
1010        cat > $ETC/hosts <<EOF
[764f50e]1011127.0.0.1       localhost
1012127.0.1.1       $NAME
1013
1014# The following lines are desirable for IPv6 capable hosts
1015::1     ip6-localhost ip6-loopback
1016fe00::0 ip6-localnet
1017ff00::0 ip6-mcastprefix
1018ff02::1 ip6-allnodes
1019ff02::2 ip6-allrouters
1020EOF
1021fi
1022}
1023
[df814dd0]1024
[fd0d6e5]1025
[df814dd0]1026#/**
[c9c2f1d1]1027#         ogCleanLinuxDevices int_ndisk int_nfilesys
[df814dd0]1028#@brief   Limpia los dispositivos del equipo de referencia. Interfaz de red ...
1029#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]1030#@param   int_nfilesys   nº de orden del sistema de archivos
[df814dd0]1031#@return  (nada)
1032#@exception OG_ERR_FORMAT    Formato incorrecto.
1033#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1034#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]1035#@version 1.0.5 - Primera versión para OpenGnSys.
1036#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1037#@date    2013-03-21
[fd0d6e5]1038#@version 1.0.6b - Elimina fichero resume de hibernacion
1039#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1040#@date    2016-11-07
[df814dd0]1041#*/ ##
1042function ogCleanLinuxDevices ()
1043{
1044# Variables locales.
[c9c2f1d1]1045local MNTDIR
[df814dd0]1046
1047# Si se solicita, mostrar ayuda.
1048if [ "$*" == "help" ]; then
[c9c2f1d1]1049    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
1050           "$FUNCNAME 1 1"
[df814dd0]1051    return
1052fi
1053# Error si no se reciben 2 parámetros.
1054[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1055
1056# Montar el sistema de archivos.
[5962edd]1057MNTDIR=$(ogMount $1 $2) || return $?
[df814dd0]1058
[c9c2f1d1]1059# Eliminar fichero de configuración de udev para dispositivos fijos de red.
[fd0d6e5]1060[ -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules ] && rm -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules
1061# Eliminar fichero resume  (estado previo de hibernación) utilizado por el initrd scripts-premount
1062[ -f ${MNTDIR}/etc/initramfs-tools/conf.d/resume ] && rm -f ${MNTDIR}/etc/initramfs-tools/conf.d/resume
[df814dd0]1063}
1064
[512c692]1065#/**
[e44e88a]1066# ogGrubAddOgLive num_disk num_part [ timeout ] [ offline ]
[512c692]1067#@brief   Crea entrada de menu grub para ogclient, tomando como paramentros del kernel los actuales del cliente.
1068#@param 1 Numero de disco
1069#@param 2 Numero de particion
[1a2fa9d8]1070#@param 3 timeout  Segundos de espera para iniciar el sistema operativo por defecto (opcional)
1071#@param 4 offline  configura el modo offline [offline|online] (opcional)
[512c692]1072#@return  (nada)
1073#@exception OG_ERR_FORMAT    Formato incorrecto.
1074#@exception OG_ERR_NOTFOUND No existe kernel o initrd  en cache.
1075#@exception OG_ERR_NOTFOUND No existe archivo de configuracion del grub.
1076# /// FIXME: Solo para el grub instalado en MBR por Opengnsys, ampliar para más casos.
[e44e88a]1077#@version 1.0.6 - Prmera integración
1078#@author 
1079#@date    2016-11-07
1080#@version 1.1.0 - Se renombra funcion para adaptacion al cambio de nombre de ogclient a ogLive. Soporta varios ogLives en la cache. Se añade el ogLive asignado al cliente.
1081#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1082#@date    2017-06-17
1083#*/ ##
1084
[512c692]1085
[d2c8674]1086function ogGrubAddOgLive ()
1087{
[1a2fa9d8]1088    local TIMEOUT DIRMOUNT GRUBGFC PARTTABLETYPE NUMDISK NUMPART KERNEL STATUS NUMLINE MENUENTRY
[512c692]1089
1090    # Si se solicita, mostrar ayuda.
1091    if [ "$*" == "help" ]; then
[1a2fa9d8]1092        ogHelp  "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [ time_out ] [ offline|online ] " \
1093                "$FUNCNAME 1 1" \
1094                "$FUNCNAME 1 6 15 offline"
[512c692]1095        return
1096    fi
1097
1098    # Error si no se reciben 2 parámetros.
1099    [ $# -lt 2 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part [ timeout ]"; echo $?)
[1a2fa9d8]1100    [[ "$3" =~ ^[0-9]*$ ]] && TIMEOUT="$3"
[512c692]1101
1102    # Error si no existe el kernel y el initrd en la cache.
1103    # Falta crear nuevo codigo de error.
[e44e88a]1104    [ -r $OGCAC/boot/${oglivedir}/ogvmlinuz -a -r $OGCAC/boot/${oglivedir}/oginitrd.img ] || return $(ogRaiseError log session $OG_ERR_NOTFOUND "CACHE: ogvmlinuz, oginitrd.img" 1>&2; echo $?)
[512c692]1105
1106    # Archivo de configuracion del grub
1107    DIRMOUNT=$(ogMount $1 $2)
1108    GRUBGFC="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg"
1109
1110    # Error si no existe archivo del grub
1111    [ -r $GRUBGFC ] || return $(ogRaiseError log session $OG_ERR_NOTFOUND  "$GRUBGFC" 1>&2; echo $?)
1112
[28ffb59]1113    # Si existe la entrada de opengnsys, se borra
1114    grep -q "menuentry Opengnsys" $GRUBGFC && sed -ie "/menuentry Opengnsys/,+6d" $GRUBGFC
[512c692]1115
1116    # Tipo de tabla de particiones
1117    PARTTABLETYPE=$(ogGetPartitionTableType $1 | tr [:upper:] [:lower:])
1118
1119    # Localizacion de la cache
1120    read NUMDISK NUMPART <<< $(ogFindCache)
1121    let NUMDISK=$NUMDISK-1
1122    # kernel y sus opciones. Pasamos a modo usuario
[e44e88a]1123    KERNEL="/boot/${oglivedir}/ogvmlinuz $(sed -e s/^.*linuz//g -e s/ogactiveadmin=[a-z]*//g /proc/cmdline)"
[1a2fa9d8]1124
1125    # Configuracion offline si existe parametro
1126    echo "$@" |grep offline &>/dev/null && STATUS=offline
1127    echo "$@" |grep online  &>/dev/null && STATUS=online
1128    [ -z "$STATUS" ] || KERNEL="$(echo $KERNEL | sed  s/"ogprotocol=[a-z]* "/"ogprotocol=local "/g ) ogstatus=$STATUS"
1129
[512c692]1130    # Numero de línea de la primera entrada del grub.
1131    NUMLINE=$(grep -n -m 1 "^menuentry" $GRUBGFC|cut -d: -f1)
1132    # Texto de la entrada de opengnsys
[e44e88a]1133MENUENTRY="menuentry "OpenGnsys"  --class opengnsys --class gnu --class os { \n \
[512c692]1134\tinsmod part_$PARTTABLETYPE \n \
1135\tinsmod ext2 \n \
1136\tset root='(hd${NUMDISK},$PARTTABLETYPE${NUMPART})' \n \
1137\tlinux $KERNEL \n \
[e44e88a]1138\tinitrd /boot/${oglivedir}/oginitrd.img \n \
[512c692]1139}"
1140
1141
1142    # Insertamos la entrada de opengnsys antes de la primera entrada existente.
1143    sed -i "${NUMLINE}i\ $MENUENTRY" $GRUBGFC
1144
1145    # Ponemos que la entrada por defecto sea la primera.
1146    sed -i s/"set.*default.*$"/"set default=\"0\""/g $GRUBGFC
1147
1148    # Si me dan valor para timeout lo cambio en el grub.
1149    [ $TIMEOUT ] &&  sed -i s/timeout=.*$/timeout=$TIMEOUT/g $GRUBGFC
1150}
1151
1152#/**
1153# ogGrubHidePartitions num_disk num_part
[872b044]1154#@brief ver ogBootLoaderHidePartitions
[8196942]1155#@see ogBootLoaderHidePartitions
[872b044]1156#*/ ##
[d2c8674]1157function ogGrubHidePartitions ()
1158{
[cade8c0]1159    # Si se solicita, mostrar ayuda.
1160    if [ "$*" == "help" ]; then
1161        ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
1162               "$FUNCNAME 1 6"
1163        return
1164    fi
[8196942]1165    ogBootLoaderHidePartitions $@
1166    return $?
1167}
1168
1169#/**
1170# ogBurgHidePartitions num_disk num_part
[872b044]1171#@brief ver ogBootLoaderHidePartitions
[8196942]1172#@see ogBootLoaderHidePartitions
[872b044]1173#*/ ##
[d2c8674]1174function ogBurgHidePartitions ()
1175{
[cade8c0]1176    # Si se solicita, mostrar ayuda.
1177    if [ "$*" == "help" ]; then
1178        ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
1179               "$FUNCNAME 1 6"
1180        return
1181    fi
[8196942]1182    ogBootLoaderHidePartitions $@
1183    return $?
1184}
1185
1186#/**
1187# ogBootLoaderHidePartitions num_disk num_part
1188#@brief Configura el grub/burg para que oculte las particiones de windows que no se esten iniciando.
[512c692]1189#@param 1 Numero de disco
1190#@param 2 Numero de particion
1191#@return  (nada)
1192#@exception OG_ERR_FORMAT    Formato incorrecto.
[8196942]1193#@exception No existe archivo de configuracion del grub/burg.
[e9c3156]1194#@version 1.1 Se comprueban las particiones de Windows con blkid (y no con grub.cfg)
1195#@author  Irina Gomez, ETSII Universidad de Sevilla
1196#@date    2015-11-17
[8196942]1197#@version 1.1 Se generaliza la función para grub y burg
1198#@author  Irina Gomez, ETSII Universidad de Sevilla
1199#@date    2017-10-20
[872b044]1200#@version 1.1.1 Se incluye comentarios en codigo para autodocuemtnacion con Doxygen
1201#@author  Antonio J. Doblas Viso, EVLT Univesidad de Malaga.
1202#@date    2018-07-05
[512c692]1203#*/
[872b044]1204
[d2c8674]1205function ogBootLoaderHidePartitions ()
1206{
[8196942]1207    local FUNC DIRMOUNT GFCFILE PARTTABLETYPE WINENTRY ENTRY PART TEXT LINE2 PART2 HIDDEN
1208
[512c692]1209    # Si se solicita, mostrar ayuda.
1210    if [ "$*" == "help" ]; then
[cade8c0]1211        ogHelp "$FUNCNAME" "$MSG_SEE ogGrubHidePartitions ogBurgHidePartitions"
[512c692]1212        return
1213    fi
1214
[cade8c0]1215    # Nombre de la función que llama a esta.
1216    FUNC="${FUNCNAME[@]:1}"
1217    FUNC="${FUNC%%\ *}"
1218
[512c692]1219    # Error si no se reciben 2 parámetros.
1220    [ $# -lt 2 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part"; echo $?)
1221
1222    # Archivo de configuracion del grub
1223    DIRMOUNT=$(ogMount $1 $2)
[8196942]1224    # La función debe ser llamanda desde ogGrubHidePartitions or ogBurgHidePartitions.
1225    case "$FUNC" in
1226        ogGrubHidePartitions)
1227            CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg"
1228            ;;
1229        ogBurgHidePartitions)
1230            CFGFILE="$DIRMOUNT/boot/burg/burg.cfg"
1231            ;;
1232        *)
1233            ogRaiseError $OG_ERR_FORMAT "Use ogGrubHidePartitions or ogBurgHidePartitions."
1234            return $?
1235            ;;
1236    esac
[512c692]1237
1238    # Error si no existe archivo del grub
[8196942]1239    [ -r $CFGFILE ] || return $(ogRaiseError log session $OG_ERR_NOTFOUND  "$CFGFILE" 1>&2; echo $?)
[512c692]1240
[e9c3156]1241    # Si solo hay una particion de Windows me salgo
[8df5ab7]1242    [ $(fdisk -l $(ogDiskToDev $1) | grep 'NTFS' |wc -l) -eq 1 ] && return 0
[512c692]1243
1244    # Elimino llamadas a parttool, se han incluido en otras ejecuciones de esta funcion.
[8196942]1245    sed -i '/parttool/d' $CFGFILE
[512c692]1246
1247    PARTTABLETYPE=$(ogGetPartitionTableType $1 | tr [:upper:] [:lower:])
[872b044]1248#   /*  (comentario de bloque para  Doxygen)
[512c692]1249    # Entradas de Windows: numero de linea y particion. De mayor a menor.
[8196942]1250    WINENTRY=$(awk '/menuentry.*Windows/ {gsub(/\)\"/, "");  print NR":"$6} ' $CFGFILE | sed -e '1!G;h;$!d' -e s/[a-z\/]//g)
[872b044]1251    #*/ (comentario para bloque Doxygen)
[e9c3156]1252    # Particiones de Windows, pueden no estar en el grub.
[8df5ab7]1253    WINPART=$(fdisk -l $(ogDiskToDev $1)|awk '/NTFS/ {print substr($1,9,1)}' |sed '1!G;h;$!d')
[512c692]1254    # Modifico todas las entradas de Windows.
1255    for ENTRY in $WINENTRY; do
1256        LINE=${ENTRY%:*}
[e9c3156]1257        PART=${ENTRY#*:}
[512c692]1258        # En cada entrada, oculto o muestro cada particion.
1259        TEXT=""
[e9c3156]1260        for PART2 in $WINPART; do
[512c692]1261                # Muestro solo la particion de la entrada actual.
[e9c3156]1262                [ $PART2 -eq $PART ] && HIDDEN="-" || HIDDEN="+"
[512c692]1263
[26255c2]1264                TEXT="\tparttool (hd0,$PARTTABLETYPE$PART2) hidden$HIDDEN \n$TEXT"
[512c692]1265        done
1266       
[8196942]1267        sed -i "${LINE}a\ $TEXT" $CFGFILE
[512c692]1268    done
1269
1270    # Activamos la particion que se inicia en todas las entradas de windows.
[8196942]1271    sed -i "/chainloader/i\\\tparttool \$\{root\} boot+"  $CFGFILE
[512c692]1272
1273}
1274
1275#/**
[be87371]1276# ogGrubDeleteEntry num_disk num_part num_disk_delete num_part_delete
[872b044]1277#@brief ver ogBootLoaderDeleteEntry
1278#@see ogBootLoaderDeleteEntry
[8196942]1279#*/
[d2c8674]1280function ogGrubDeleteEntry ()
1281{
[cade8c0]1282    # Si se solicita, mostrar ayuda.
1283    if [ "$*" == "help" ]; then
[be87371]1284        ogHelp  "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_delete int_npartition_delete" \
1285                "$FUNCNAME 1 6 2 1"
[cade8c0]1286        return
1287    fi
[8196942]1288    ogBootLoaderDeleteEntry $@
1289    return $?
1290}
1291
1292#/**
[be87371]1293# ogBurgDeleteEntry num_disk num_part num_disk_delete num_part_delete
[872b044]1294#@brief ver ogBootLoaderDeleteEntry
[8196942]1295#@see ogBootLoaderDeleteEntry
1296#*/
[d2c8674]1297function ogBurgDeleteEntry ()
1298{
[cade8c0]1299    # Si se solicita, mostrar ayuda.
1300    if [ "$*" == "help" ]; then
[be87371]1301        ogHelp  "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_delete int_npartition_delete" \
1302                "$FUNCNAME 1 6 2 1"
[cade8c0]1303        return
1304    fi
[8196942]1305    ogBootLoaderDeleteEntry $@
1306    return $?
1307}
1308
1309#/**
1310# ogBootLoaderDeleteEntry num_disk num_part num_part_delete
[512c692]1311#@brief Borra en el grub las entradas para el inicio en una particion.
1312#@param 1 Numero de disco donde esta el grub
1313#@param 2 Numero de particion donde esta el grub
[be87371]1314#@param 3 Numero del disco del que borramos las entradas
1315#@param 4 Numero de la particion de la que borramos las entradas
[8196942]1316#@note Tiene que ser llamada desde ogGrubDeleteEntry o ogBurgDeleteEntry
[512c692]1317#@return  (nada)
[8196942]1318#@exception OG_ERR_FORMAT    Use ogGrubDeleteEntry or ogBurgDeleteEntry.
[512c692]1319#@exception OG_ERR_FORMAT    Formato incorrecto.
[8196942]1320#@exception OG_ERR_NOTFOUND  No existe archivo de configuracion del grub.
1321#@version 1.1 Se generaliza la función para grub y burg
1322#@author  Irina Gomez, ETSII Universidad de Sevilla
1323#@date    2017-10-20
[872b044]1324#*/ ##
1325
[d2c8674]1326function ogBootLoaderDeleteEntry ()
1327{
[8196942]1328    local FUNC DIRMOUNT CFGFILE DEVICE MENUENTRY DELETEENTRY ENDENTRY ENTRY
[512c692]1329
[cade8c0]1330    # Si se solicita, mostrar ayuda.
1331    if [ "$*" == "help" ]; then
1332        ogHelp  "$FUNCNAME" "$MSG_SEE ogBurgDeleteEntry ogGrubDeleteEntry"
1333        return
1334    fi
1335
[be87371]1336    # Si el número de parámetros menos que 4 nos salimos
1337    [ $# -lt 4 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part num_disk_delete num_part_delete"; echo $?)
1338 
1339
[8196942]1340    # Nombre de la función que llama a esta.
1341    FUNC="${FUNCNAME[@]:1}"
1342    FUNC="${FUNC%%\ *}"
[512c692]1343
[8196942]1344    # Archivo de configuracion del grub
1345    DIRMOUNT=$(ogMount $1 $2)
1346    # La función debe ser llamanda desde ogGrubDeleteEntry or ogBurgDeleteEntry.
1347    case "$FUNC" in
1348        ogGrubDeleteEntry)
1349            CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg"
1350            ;;
1351        ogBurgDeleteEntry)
1352            CFGFILE="$DIRMOUNT/boot/burg/burg.cfg"
1353            ;;
1354        *)
1355            ogRaiseError $OG_ERR_FORMAT "Use ogGrubDeleteEntry or ogBurgDeleteEntry."
1356            return $?
1357            ;;
1358    esac
[512c692]1359
[8196942]1360    # Dispositivo
[be87371]1361    DEVICE=$(ogDiskToDev $3 $4)
[512c692]1362
1363    # Error si no existe archivo del grub)
[be87371]1364    [ -r $CFGFILE ] || ogRaiseError log session $OG_ERR_NOTFOUND  "$CFGFILE" || return $?
[512c692]1365
[be87371]1366    # Numero de linea de cada entrada.
1367    MENUENTRY="$(grep -n -e menuentry $CFGFILE| cut -d: -f1 | sed '1!G;h;$!d' )"
[512c692]1368
1369    # Entradas que hay que borrar.
[be87371]1370    DELETEENTRY=$(grep -n menuentry.*$DEVICE $CFGFILE| cut -d: -f1)
[8196942]1371
1372    # Si no hay entradas para borrar me salgo con aviso
[be87371]1373    [ "$DELETEENTRY" != "" ] || ogRaiseError log session $OG_ERR_NOTFOUND "Menuentry $DEVICE" || return $?
[512c692]1374
1375    # Recorremos el fichero del final hacia el principio.
[8196942]1376    ENDENTRY="$(wc -l $CFGFILE|cut  -d" " -f1)"
[512c692]1377    for ENTRY in $MENUENTRY; do
1378        # Comprobamos si hay que borrar la entrada.
1379        if  ogCheckStringInGroup $ENTRY "$DELETEENTRY" ; then
1380            let ENDENTRY=$ENDENTRY-1
[8196942]1381            sed -i -e $ENTRY,${ENDENTRY}d  $CFGFILE
[512c692]1382        fi
1383
1384        # Guardamos el número de línea de la entrada, que sera el final de la siguiente.
1385        ENDENTRY=$ENTRY
1386    done
1387}
1388
[872b044]1389#/**
[74e01a7]1390#         ogBurgInstallMbr   int_disk_GRUBCFG  int_partition_GRUBCFG
1391#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
1392#@brief   Instala y actualiza el gestor grub en el MBR del disco duro donde se encuentra el fichero grub.cfg. Admite sistemas Windows.
1393#@param   int_disk_SecondStage     
1394#@param   int_part_SecondStage     
1395#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
1396#@return 
1397#@exception OG_ERR_FORMAT    Formato incorrecto.
[c0fde6d]1398#@exception OG_ERR_PARTITION  Partición no soportada
[74e01a7]1399#@version 1.1.0 - Primeras pruebas instalando BURG. Codigo basado en el ogGrubInstallMBR.
1400#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1401#@date    2017-06-23
[19c9dca]1402#@version 1.1.0 - Redirección del proceso de copiado de archivos y de la instalacion del binario
1403#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1404#@date    2018-01-21
[deacf00]1405#@version 1.1.0 - Refactorizar fichero de configuacion
1406#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1407#@date    2018-01-24
[872b044]1408#@version 1.1.1 - Se incluye comentarios en codigo para autodocuemtnacion con Doxygen
1409#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
1410#@date    2018-07-05
[74e01a7]1411#*/ ##
1412
[d2c8674]1413function ogBurgInstallMbr ()
1414{
[74e01a7]1415 
1416# Variables locales.
1417local PART DISK FIRSTAGE SECONSTAGE PREFIXSECONDSTAGE CHECKOS KERNELPARAM BACKUPNAME FILECFG
1418
1419# Si se solicita, mostrar ayuda.
1420if [ "$*" == "help" ]; then
1421    ogHelp "$FUNCNAME" "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \"  " \
1422           "$FUNCNAME 1 1 FALSE " \
1423           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
1424    return
1425fi 
1426
1427# Error si no se reciben 2 parametros.
1428[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
1429
1430
1431DISK=$1; PART=$2;
1432CHECKOS=${3:-"FALSE"}
1433KERNELPARAM=$4
1434BACKUPNAME=".backup.og"
1435
1436#Error si no es linux.
1437ogCheckStringInGroup $(ogGetFsType $DISK $PART) "CACHE EXT4 EXT3 EXT2" || return $(ogRaiseError $OG_ERR_PARTITION "burg no soporta esta particion"; echo $?)
1438
1439
1440#La primera etapa del grub se fija en el primer disco duro
1441FIRSTSTAGE=$(ogDiskToDev 1)
1442
1443#localizar disco segunda etapa del grub
1444SECONDSTAGE=$(ogMount $DISK $PART)
1445
1446# prepara el directorio principal de la segunda etapa (y copia los binarios)
[872b044]1447[ -d ${SECONDSTAGE}/boot/burg/ ]  || mkdir -p ${SECONDSTAGE}/boot/burg/; cp -prv /boot/burg/*  ${SECONDSTAGE}/boot/burg/ 2>&1>/dev/null; cp -prv $OGLIB/burg/*  ${SECONDSTAGE}/boot/burg/ 2>&1>/dev/null; #*/ ## (comentario Dogygen) #*/ ## (comentario Dogygen)
[74e01a7]1448
1449#Copiamos el tema
1450mkdir -p  ${SECONDSTAGE}/boot/burg/themes/OpenGnsys
[19c9dca]1451cp -prv "$OGLIB/burg/themes" "${SECONDSTAGE}/boot/burg/" 2>&1>/dev/null
[74e01a7]1452
1453#Localizar directorio segunda etapa del grub   
1454#PREFIXSECONDSTAGE="/boot/burg/"
1455
1456# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
1457if [ -f ${SECONDSTAGE}/boot/burg/burg.cfg -o -f ${SECONDSTAGE}/boot/burg/burg.cfg$BACKUPNAME ]
1458then
1459    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
1460    then
[19c9dca]1461        burg-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE 2>&1>/dev/null
[74e01a7]1462        return $?
1463    fi
1464fi
1465
1466# SI Reconfigurar segunda etapa (burg.cfg) == TRUE
1467
1468#llamada a updateBootCache para que aloje la primera fase del ogLive
1469updateBootCache
1470
1471#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
1472echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
1473echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
1474
1475
1476#Preparar configuración segunda etapa: crear ubicacion
1477mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/burg/
1478
1479#Preparar configuración segunda etapa: crear cabecera del fichero
1480#/etc/burg.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/burg/burg.cfg
1481
1482FILECFG=${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/burg/burg.cfg
1483
[872b044]1484#/* ## (comentario Dogygen)
[74e01a7]1485cat > "$FILECFG" << EOF
1486
1487set theme_name=OpenGnsys
1488set gfxmode=1024x768
[deacf00]1489
[74e01a7]1490
1491set locale_dir=(\$root)/boot/burg/locale
1492
1493set default=0
1494set timeout=25
1495set lang=es
1496
1497
1498insmod ext2
1499insmod gettext
1500
1501
[deacf00]1502
1503
[74e01a7]1504if [ -s \$prefix/burgenv ]; then
1505  load_env
1506fi
1507
[deacf00]1508
1509
[74e01a7]1510if [ \${prev_saved_entry} ]; then
1511  set saved_entry=\${prev_saved_entry}
1512  save_env saved_entry
1513  set prev_saved_entry=
1514  save_env prev_saved_entry
1515  set boot_once=true
1516fi
1517
1518function savedefault {
1519  if [ -z \${boot_once} ]; then
1520    saved_entry=\${chosen}
1521    save_env saved_entry
1522  fi
1523}
1524function select_menu {
1525  if menu_popup -t template_popup theme_menu ; then
1526    free_config template_popup template_subitem menu class screen
1527    load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name}
1528    save_env theme_name
1529    menu_refresh
1530  fi
1531}
1532
1533function toggle_fold {
1534  if test -z $theme_fold ; then
1535    set theme_fold=1
1536  else
1537    set theme_fold=
1538  fi
1539  save_env theme_fold
1540  menu_refresh
1541}
1542function select_resolution {
1543  if menu_popup -t template_popup resolution_menu ; then
1544    menu_reload_mode
1545    save_env gfxmode
1546  fi
1547}
1548
1549
1550if test -f \${prefix}/themes/\${theme_name}/theme ; then
1551  insmod coreui
1552  menu_region.text
1553  load_string '+theme_menu { -OpenGnsys { command="set theme_name=OpenGnsys" }}'   
[deacf00]1554  load_config \${prefix}/themes/conf.d/10_hotkey   
[74e01a7]1555  load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name}
1556  insmod vbe
1557  insmod png
1558  insmod jpeg
1559  set gfxfont="Unifont Regular 16"
1560  menu_region.gfx
1561  vmenu resolution_menu
1562  controller.ext
1563fi
1564
1565
1566EOF
[872b044]1567#*/ ## (comentario Dogygen)
[74e01a7]1568
1569#Preparar configuración segunda etapa: crear entrada del sistema operativo
1570grubSyntax "$KERNELPARAM" >> "$FILECFG"
1571
1572
1573#Instalar el burg
[19c9dca]1574burg-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE 2>&1>/dev/null
[74e01a7]1575}
1576
[0d2e65b]1577#/**
[be87371]1578# ogGrubDefaultEntry int_disk_GRUGCFG  int_partition_GRUBCFG int_disk_default_entry int_npartition_default_entry
[872b044]1579#@brief ver ogBootLoaderDefaultEntry
[be87371]1580#@see ogBootLoaderDefaultEntry
[872b044]1581#*/ ##
[d2c8674]1582function ogGrubDefaultEntry ()
1583{
[be87371]1584    # Si se solicita, mostrar ayuda.
1585    if [ "$*" == "help" ]; then
1586        ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_default_entry int_npartition_default_entry" \
1587               "$FUNCNAME 1 6 1 1"
1588        return
1589    fi
1590    ogBootLoaderDefaultEntry $@
1591    return $?
1592}
1593
1594#/**
1595# ogBurgDefaultEntry int_disk_BURGCFG  int_partition_BURGCFG int_disk_default_entry int_npartition_default_entry
[872b044]1596#@brief ver ogBootLoaderDefaultEntry
[be87371]1597#@see ogBootLoaderDefaultEntry
[872b044]1598#*/ ##
[d2c8674]1599function ogBurgDefaultEntry ()
1600{
[be87371]1601    # Si se solicita, mostrar ayuda.
1602    if [ "$*" == "help" ]; then
1603        ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_default_entry int_npartition_default_entry" \
1604               "$FUNCNAME 1 6 1 1"
1605        return
1606    fi
1607    ogBootLoaderDefaultEntry $@
1608    return $?
1609}
1610
1611#/**
1612# ogBootLoaderDefaultEntry   int_disk_CFG  int_partition_CFG int_disk_default_entry int_npartition_default_entry
[0d2e65b]1613#@brief   Configura la entrada por defecto de Burg
1614#@param   int_disk_SecondStage     
1615#@param   int_part_SecondStage     
[be87371]1616#@param   int_disk_default_entry
1617#@param   int_part_default_entry
[0d2e65b]1618#@return 
1619#@exception OG_ERR_FORMAT    Formato incorrecto.
1620#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
1621#@exception OG_ERR_OUTOFLIMIT Param $3 no es entero.
1622#@exception OG_ERR_NOTFOUND   Fichero de configuración no encontrado: burg.cfg.
[be87371]1623#@version 1.1.0 - Define la entrada por defecto del Burg
[0d2e65b]1624#@author  Irina Gomez, ETSII Universidad de Sevilla
1625#@date    2017-08-09
[be87371]1626#@version 1.1 Se generaliza la función para grub y burg
1627#@author  Irina Gomez, ETSII Universidad de Sevilla
1628#@date    2018-01-04
[0d2e65b]1629#*/ ##
[d2c8674]1630function ogBootLoaderDefaultEntry ()
1631{
[0d2e65b]1632
1633# Variables locales.
[be87371]1634local PART CFGFILE DEFAULTENTRY MSG
[0d2e65b]1635
1636# Si se solicita, mostrar ayuda.
1637if [ "$*" == "help" ]; then
[be87371]1638    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubDefaultEntry ogBurgDefaultEntry"
[0d2e65b]1639    return
1640fi 
1641
[be87371]1642# Nombre de la función que llama a esta.
1643FUNC="${FUNCNAME[@]:1}"
1644FUNC="${FUNC%%\ *}"
1645
[0d2e65b]1646# Error si no se reciben 3 parametros.
[be87371]1647[ $# -eq 4 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage int_disk_default_entry int_partitions_default_entry" || return $?
[0d2e65b]1648
1649# Error si no puede montar sistema de archivos.
[be87371]1650DIRMOUNT=$(ogMount $1 $2) || return $?
1651
1652# Comprobamos que exista fichero de configuración
1653# La función debe ser llamanda desde ogGrubDefaultEntry or ogBurgDefaultEntry.
1654case "$FUNC" in
1655    ogGrubDefaultEntry)
1656        CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg"
1657        ;;
1658    ogBurgDefaultEntry)
1659        CFGFILE="$DIRMOUNT/boot/burg/burg.cfg"
1660        ;;
1661    *)
1662        ogRaiseError $OG_ERR_FORMAT "Use ogGrubDefaultEntry or ogBurgDefaultEntry."
1663        return $?
1664        ;;
1665esac
1666
1667# Error si no existe archivo de configuración
1668[ -r $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
1669
1670# Dispositivo
1671DEVICE=$(ogDiskToDev $3 $4)
[0d2e65b]1672
[be87371]1673# Número de línea de la entrada por defecto en CFGFILE (primera de la partición).
1674DEFAULTENTRY=$(grep -n -m 1 menuentry.*$DEVICE $CFGFILE| cut -d: -f1)
[0d2e65b]1675
[be87371]1676# Si no hay entradas para borrar me salgo con aviso
1677[ "$DEFAULTENTRY" != "" ] || ogRaiseError session log $OG_ERR_NOTFOUND "No menuentry $DEVICE" || return $?
[0d2e65b]1678
[be87371]1679# Número de la de linea por defecto en el menú de usuario
1680MENUENTRY="$(grep -n -e menuentry $CFGFILE| cut -d: -f1 | grep -n $DEFAULTENTRY |cut -d: -f1)"
1681# Las líneas empiezan a contar desde cero
1682let MENUENTRY=$MENUENTRY-1
1683sed --regexp-extended -i  s/"set default=\"?[0-9]*\"?"/"set default=\"$MENUENTRY\""/g $CFGFILE
1684MSG="MSG_HELP_$FUNC"
1685echo "${!MSG%%\.}: $@"
[0d2e65b]1686}
1687
1688#/**
[be87371]1689# ogGrubOgliveDefaultEntry num_disk num_part
[872b044]1690#@brief ver ogBootLoaderOgliveDefaultEntry
[be87371]1691#@see ogBootLoaderOgliveDefaultEntry
[872b044]1692#*/ ##
[d2c8674]1693function ogGrubOgliveDefaultEntry ()
1694{
[be87371]1695    # Si se solicita, mostrar ayuda.
1696    if [ "$*" == "help" ]; then
1697        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage" \
1698               "$FUNCNAME 1 6"
1699        return
1700    fi
1701    ogBootLoaderOgliveDefaultEntry $@
1702    return $?
1703}
1704
1705#/**
1706# ogBurgOgliveDefaultEntry num_disk num_part
[872b044]1707#@brief ver ogBootLoaderOgliveDefaultEntry
[be87371]1708#@see ogBootLoaderOgliveDefaultEntry
[872b044]1709#*/ ##
[d2c8674]1710function ogBurgOgliveDefaultEntry ()
1711{
[be87371]1712    # Si se solicita, mostrar ayuda.
1713    if [ "$*" == "help" ]; then
1714        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage" \
1715               "$FUNCNAME 1 6"
1716        return
1717    fi
1718    ogBootLoaderOgliveDefaultEntry $@
1719    return $?
1720}
1721
1722#/**
1723# ogBootLoaderOgliveDefaultEntry
[0d2e65b]1724#@brief   Configura la entrada de ogLive como la entrada por defecto de Burg.
1725#@param   int_disk_SecondStage     
1726#@param   int_part_SecondStage     
1727#@return 
1728#@exception OG_ERR_FORMAT    Formato incorrecto.
1729#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
1730#@exception OG_ERR_NOTFOUND  Fichero de configuración no encontrado: burg.cfg.
1731#@exception OG_ERR_NOTFOUND  Entrada de OgLive no encontrada en burg.cfg.
1732#@version 1.1.0 - Primeras pruebas con Burg
1733#@author  Irina Gomez, ETSII Universidad de Sevilla
1734#@date    2017-08-09
[be87371]1735#@version 1.1 Se generaliza la función para grub y burg
1736#@author  Irina Gomez, ETSII Universidad de Sevilla
1737#@date    2018-01-04
[0d2e65b]1738#*/ ##
[d2c8674]1739function  ogBootLoaderOgliveDefaultEntry ()
1740{
[0d2e65b]1741
1742# Variables locales.
[be87371]1743local FUNC PART CFGFILE NUMENTRY MSG
[0d2e65b]1744
1745# Si se solicita, mostrar ayuda.
1746if [ "$*" == "help" ]; then
[be87371]1747    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubOgliveDefaultEntry ogBurgOgliveDefaultEntry" \
[0d2e65b]1748    return
1749fi 
1750
[be87371]1751# Nombre de la función que llama a esta.
1752FUNC="${FUNCNAME[@]:1}"
1753FUNC="${FUNC%%\ *}"
1754
[0d2e65b]1755# Error si no se reciben 2 parametros.
1756[ $# -eq 2 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage" || return $?
1757
1758# Error si no puede montar sistema de archivos.
1759PART=$(ogMount $1 $2) || return $?
[be87371]1760# La función debe ser llamanda desde ogGrubOgliveDefaultEntry or ogBurgOgliveDefaultEntry.
1761case "$FUNC" in
1762    ogGrubOgliveDefaultEntry)
1763        CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg"
1764        ;;
1765    ogBurgOgliveDefaultEntry)
1766        CFGFILE="$PART/boot/burg/burg.cfg"
1767        ;;
1768    *)
1769        ogRaiseError $OG_ERR_FORMAT "Use ogGrubOgliveDefaultEntry or ogBurgOgliveDefaultEntry."
1770        return $?
1771        ;;
1772esac
[0d2e65b]1773
[be87371]1774# Comprobamos que exista fichero de configuración
1775[ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
[0d2e65b]1776
1777# Detectamos cual es la entrada de ogLive
[be87371]1778NUMENTRY=$(grep ^menuentry $CFGFILE| grep -n "OpenGnsys Live"|cut -d: -f1)
[0d2e65b]1779
1780# Si no existe entrada de ogLive nos salimos
[be87371]1781[ -z "$NUMENTRY" ] && (ogRaiseError $OG_ERR_NOTFOUND "menuentry OpenGnsys Live in $CFGFILE" || return $?)
[0d2e65b]1782
1783let NUMENTRY=$NUMENTRY-1
[f2e6a2e]1784sed --regexp-extended -i  s/"set default=\"?[0-9]+\"?"/"set default=\"$NUMENTRY\""/g $CFGFILE
[0d2e65b]1785
[be87371]1786MSG="MSG_HELP_$FUNC"
1787echo "${!MSG%%\.}: $@"
[0d2e65b]1788}
[74e01a7]1789
[deacf00]1790
1791#/**
1792# ogGrubSetTheme num_disk num_part str_theme
[872b044]1793#@brief ver ogBootLoaderSetTheme
[deacf00]1794#@see ogBootLoaderSetTheme
[872b044]1795#*/ ##
[d2c8674]1796function ogGrubSetTheme ()
1797{
[deacf00]1798    # Si se solicita, mostrar ayuda.
1799    if [ "$*" == "help" ]; then
1800        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_themeName" \
1801               "$FUNCNAME 1 4 ThemeBasic"\
1802               "$FUNCNAME \$(ogFindCache) ThemeBasic"
1803        return
1804    fi
1805    ogBootLoaderSetTheme $@
1806    return $?
1807}
1808
1809#/**
1810# ogBurgSetTheme num_disk num_part str_theme
[872b044]1811#@brief ver ogBootLoaderSetTheme
[deacf00]1812#@see ogBootLoaderSetTheme
[872b044]1813#*/ ##
[d2c8674]1814function ogBurgSetTheme  ()
1815{
[deacf00]1816    # Si se solicita, mostrar ayuda.
1817    if [ "$*" == "help" ]; then
1818        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_themeName" \
1819               "$FUNCNAME 1 4 ThemeBasic" \
1820               "$FUNCNAME \$(ogFindCache) ThemeBasic"
1821        echo "Temas disponibles:\ $(ls $OGCAC/boot/burg/themes/)"
1822               
1823        return
1824    fi
1825    ogBootLoaderSetTheme $@
1826    return $?
1827}
1828
1829
1830
1831#/**
1832# ogBootLoaderSetTheme
1833#@brief   asigna un tema al BURG
1834#@param   int_disk_SecondStage     
1835#@param   int_part_SecondStage 
1836#@param   str_theme_name   
1837#@return 
1838#@exception OG_ERR_FORMAT    Formato incorrecto.
1839#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
1840#@exception OG_ERR_NOTFOUND  Fichero de configuración no encontrado: grub.cfg burg.cfg.
1841#@exception OG_ERR_NOTFOUND  Entrada deltema no encontrada en burg.cfg.
1842#@version 1.1.0 - Primeras pruebas con Burg. grub no soportado.
1843#@author  Antonio J. Doblas Viso. Universidad de Malaga
1844#@date    2018-01-24
1845#*/ ##
[d2c8674]1846function  ogBootLoaderSetTheme ()
1847{
[deacf00]1848
1849# Variables locales.
1850local FUNC PART CFGFILE THEME NEWTHEME BOOTLOADER MSG
1851
1852# Si se solicita, mostrar ayuda.
1853if [ "$*" == "help" ]; then
1854    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetTheme ogBurgSetTheme"
1855    return   
1856fi
1857 
1858
1859NEWTHEME="$3"
1860
1861# Nombre de la función que llama a esta.
1862FUNC="${FUNCNAME[@]:1}"
1863FUNC="${FUNC%%\ *}"
1864
1865
1866
1867# Error si no se reciben 2 parametros.
1868[ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage str_themeName" || return $?
1869
1870# Error si no puede montar sistema de archivos.
1871PART=$(ogMount $1 $2) || return $?
1872# La función debe ser llamanda desde ogGrubSetTheme or ogBurgSetTheme.
1873case "$FUNC" in
1874    ogGrubSetTheme)
1875        BOOTLOADER="grug"
1876        BOOTLOADERDIR="grubMBR"
1877        CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" 
1878        ogRaiseError $OG_ERR_FORMAT "ogGrubSetTheme not sopported"
1879        return $?               
1880        ;;
1881    ogBurgSetTheme)
1882        BOOTLOADER="burg"
1883        BOOTLOADERDIR="burg"
1884        CFGFILE="$PART/boot/burg/burg.cfg"       
1885        ;;
1886    *)
1887        ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetTheme or ogBurgSetTheme."
1888        return $?
1889        ;;
1890esac
1891
1892# Comprobamos que exista fichero de configuración
1893[ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
1894
1895# Detectamos cual es el tema asignado
1896THEME=$(grep "set theme_name=" $CFGFILE | grep ^set | cut -d= -f2)
1897
1898# Si no existe entrada de theme_name  nos salimos
1899[ -z "$THEME" ] && (ogRaiseError $OG_ERR_NOTFOUND "theme_name in $CFGFILE" || return $?)
1900
1901#Actualizamos el tema del servidor a la particion
1902if [ -d $OGLIB/$BOOTLOADER/themes/$NEWTHEME ]; then
1903        cp -pr $OGLIB/$BOOTLOADER/themes/$NEWTHEME $PART/boot/$BOOTLOADERDIR/themes/   
1904fi
1905
1906#Verificamos que el tema esta en la particion
1907if ! [ -d $PART/boot/$BOOTLOADERDIR/themes/$NEWTHEME ]; then
1908                ogRaiseError $OG_ERR_NOTFOUND "theme_name=$NEWTHEME in $PART/boot/$BOOTLOADERDIR/themes/" || return $?
1909fi
1910
1911#Cambiamos la entrada el fichero de configuración.
1912sed --regexp-extended -i  s/"$THEME"/"$NEWTHEME"/g $CFGFILE
1913
1914
1915}
1916
1917#/**
1918# ogGrubSetAdminKeys num_disk num_part str_theme
[872b044]1919#@brief ver ogBootLoaderSetTheme
[deacf00]1920#@see ogBootLoaderSetTheme
[872b044]1921#*/ ##
[d2c8674]1922function ogGrubSetAdminKeys ()
1923{
[deacf00]1924    # Si se solicita, mostrar ayuda.
1925    if [ "$*" == "help" ]; then
1926        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_bolean" \
1927               "$FUNCNAME 1 4 FALSE "\
1928               "$FUNCNAME \$(ogFindCache) ThemeBasic"
1929        return
1930    fi
1931    ogBootLoaderSetAdminKeys $@
1932    return $?
1933}
1934
1935#/**
1936# ogBurgSetAdminKeys num_disk num_part str_bolean
[872b044]1937#@brief ver ogBootLoaderSetAdminKeys
[deacf00]1938#@see ogBootLoaderSetAdminKeys
[872b044]1939#*/ ##
[d2c8674]1940function ogBurgSetAdminKeys  ()
1941{
[deacf00]1942    # Si se solicita, mostrar ayuda.
1943    if [ "$*" == "help" ]; then
1944        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_bolean" \
1945               "$FUNCNAME 1 4 TRUE" \
1946               "$FUNCNAME \$(ogFindCache) FALSE"               
1947        return
1948    fi
1949    ogBootLoaderSetAdminKeys $@
1950    return $?
1951}
1952
1953
1954
1955#/**
1956# ogBootLoaderSetAdminKeys
1957#@brief   Activa/Desactica las teclas de administracion
1958#@param   int_disk_SecondStage     
1959#@param   int_part_SecondStage 
1960#@param   Boolean TRUE/FALSE   
1961#@return 
1962#@exception OG_ERR_FORMAT    Formato incorrecto.
1963#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
1964#@exception OG_ERR_NOTFOUND  Fichero de configuración no encontrado: grub.cfg burg.cfg.
1965#@exception OG_ERR_NOTFOUND  Entrada deltema no encontrada en burg.cfg.
1966#@version 1.1.0 - Primeras pruebas con Burg. grub no soportado.
1967#@author  Antonio J. Doblas Viso. Universidad de Malaga
1968#@date    2018-01-24
1969#*/ ##
[d2c8674]1970function  ogBootLoaderSetAdminKeys ()
1971{
[deacf00]1972
1973# Variables locales.
1974local FUNC PART CFGFILE BOOTLOADER BOOTLOADERDIR CFGFILE MSG
1975
1976# Si se solicita, mostrar ayuda.
1977if [ "$*" == "help" ]; then
1978    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetSetAdminKeys ogBurgSetSetAdminKeys"
1979    return   
1980fi
1981 
1982
1983# Nombre de la función que llama a esta.
1984FUNC="${FUNCNAME[@]:1}"
1985FUNC="${FUNC%%\ *}"
1986
1987
1988# Error si no se reciben 2 parametros.
1989[ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage str_bolean" || return $?
1990
1991# Error si no puede montar sistema de archivos.
1992PART=$(ogMount $1 $2) || return $?
1993# La función debe ser llamanda desde ogGrubSetAdminKeys or ogBurgSetAdminKeys.
1994case "$FUNC" in
1995    ogGrubSetAdminKeys)
1996        BOOTLOADER="grug"
1997        BOOTLOADERDIR="grubMBR"
1998        CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" 
1999        ogRaiseError $OG_ERR_FORMAT "ogGrubSetAdminKeys not sopported"
2000        return $?       
2001        ;;
2002    ogBurgSetAdminKeys)
2003        BOOTLOADER="burg"
2004        BOOTLOADERDIR="burg"
2005        CFGFILE="$PART/boot/burg/burg.cfg"       
2006        ;;
2007    *)
2008        ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetAdminKeys"
2009        return $?
2010        ;;
2011esac
2012
2013
2014# Comprobamos que exista fichero de configuración
2015[ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
2016
2017
2018case "$3" in
2019        true|TRUE)
2020                [ -f ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey.disabled ] && mv ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey.disabled ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey
2021        ;;
2022        false|FALSE)
2023                [ -f ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey ] && mv ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey ${OGCAC}/boot/$BOOTLOADERDIR/themes/conf.d/10_hotkey.disabled
2024        ;;     
2025        *)
2026           ogRaiseError $OG_ERR_FORMAT "str bolean unknow "
2027        return $?
2028    ;; 
2029esac
2030}
2031
2032
2033
2034#/**
2035# ogGrubSetTimeOut num_disk num_part int_timeout_seconds
[872b044]2036#@brief ver ogBootLoaderSetTimeOut
[deacf00]2037#@see ogBootLoaderSetTimeOut
[872b044]2038#*/ ##
[d2c8674]2039function ogGrubSetTimeOut ()
2040{
[deacf00]2041    # Si se solicita, mostrar ayuda.
2042    if [ "$*" == "help" ]; then
2043        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage int_timeout_seconds" \
2044               "$FUNCNAME 1 4 50 "\
2045               "$FUNCNAME \$(ogFindCache) 50"
2046        return
2047    fi
2048    ogBootLoaderSetTimeOut $@
2049    return $?
2050}
2051
2052#/**
2053# ogBurgSetTimeOut num_disk num_part str_bolean
[872b044]2054#@brief ver ogBootLoaderSetTimeOut
[deacf00]2055#@see ogBootLoaderSetTimeOut
[872b044]2056#*/ ##
2057function ogBurgSetTimeOut ()
2058{
[deacf00]2059    # Si se solicita, mostrar ayuda.
2060    if [ "$*" == "help" ]; then
2061        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_timeout_seconds" \
2062               "$FUNCNAME 1 4 50" \
2063               "$FUNCNAME \$(ogFindCache) 50"               
2064        return
2065    fi
2066    ogBootLoaderSetTimeOut $@
2067    return $?
2068}
2069
2070
2071
2072#/**
2073# ogBootLoaderSetTimeOut
2074#@brief   Define el tiempo (segundos) que se muestran las opciones de inicio
2075#@param   int_disk_SecondStage     
2076#@param   int_part_SecondStage 
2077#@param   int_timeout_seconds   
2078#@return 
2079#@exception OG_ERR_FORMAT    Formato incorrecto.
2080#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
2081#@exception OG_ERR_NOTFOUND  Fichero de configuración no encontrado: grub.cfg burg.cfg.
2082#@exception OG_ERR_NOTFOUND  Entrada deltema no encontrada en burg.cfg.
2083#@version 1.1.0 - Primeras pruebas con Burg. GRUB solo si está instalado en MBR
2084#@author  Antonio J. Doblas Viso. Universidad de Malaga
2085#@date    2018-01-24
2086#*/ ##
[d2c8674]2087function  ogBootLoaderSetTimeOut ()
2088{
[deacf00]2089
2090# Variables locales.
2091local FUNC PART CFGFILE TIMEOUT BOOTLOADER BOOTLOADERDIR CFGFILE MSG
2092
2093# Si se solicita, mostrar ayuda.
2094if [ "$*" == "help" ]; then
2095    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetTimeOut ogBurgSetTimeOut"
2096    return   
2097fi
2098 
2099ogCheckStringInReg $3 "^[0-9]{1,10}$" &&  TIMEOUT="$3" || ogRaiseError $OG_ERR_FORMAT "param 3 is not a integer"
2100
2101# Nombre de la función que llama a esta.
2102FUNC="${FUNCNAME[@]:1}"
2103FUNC="${FUNC%%\ *}"
2104
2105# Error si no se reciben 3 parametros.
2106[ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage int_timeout_seconds" || return $?
2107
2108# Error si no puede montar sistema de archivos.
2109PART=$(ogMount $1 $2) || return $?
2110# La función debe ser llamanda desde ogGrubSetTimeOut or ogBurgSetTimeOut.
2111case "$FUNC" in
2112    ogGrubSetTimeOut)
2113        BOOTLOADER="grug"
2114        BOOTLOADERDIR="grubMBR"
2115        CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg"     
2116        ;;
2117    ogBurgSetTimeOut)
2118        BOOTLOADER="burg"
2119        BOOTLOADERDIR="burg"
2120        CFGFILE="$PART/boot/burg/burg.cfg"       
2121        ;;
2122    *)
2123        ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetTimeOut"
2124        return $?
2125        ;;
2126esac
2127
2128# Comprobamos que exista fichero de configuración
2129[ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
2130
2131# Asignamos el timeOut.
2132sed -i s/timeout=.*$/timeout=$TIMEOUT/g $CFGFILE
2133}
2134
2135
2136#/**
2137# ogGrubSetResolution num_disk num_part int_resolution
[872b044]2138#@brief ver ogBootLoaderSetResolution
[deacf00]2139#@see ogBootLoaderSetResolution
[872b044]2140#*/ ##
[d2c8674]2141function ogGrubSetResolution ()
2142{
[deacf00]2143    # Si se solicita, mostrar ayuda.
2144    if [ "$*" == "help" ]; then
2145        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [str_resolution]" \
2146             "$FUNCNAME 1 4 1024x768" \
2147             "$FUNCNAME \$(ogFindCache) 1024x768" \
2148             "$FUNCNAME 1 4" 
2149        return
2150    fi
2151    ogBootLoaderSetResolution $@
2152    return $?
2153}
2154
2155#/**
2156# ogBurgSetResolution num_disk num_part str_bolean
[872b044]2157#@brief ver ogBootLoaderSetResolution
[deacf00]2158#@see ogBootLoaderSetResolution
[872b044]2159#*/ ##
[d2c8674]2160function ogBurgSetResolution ()
2161 {
[deacf00]2162    # Si se solicita, mostrar ayuda.
2163    if [ "$*" == "help" ]; then
2164        ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [str_resolution]" \
2165               "$FUNCNAME 1 4 1024x768" \
2166               "$FUNCNAME \$(ogFindCache) 1024x768" \
2167               "$FUNCNAME 1 4"               
2168        return
2169    fi
2170    ogBootLoaderSetResolution $@
2171    return $?
2172}
2173
2174
2175
2176#/**
2177# ogBootLoaderSetResolution
2178#@brief   Define la resolucion que usuara el thema del gestor de arranque
2179#@param   int_disk_SecondStage     
2180#@param   int_part_SecondStage 
2181#@param   str_resolution (Opcional)   
2182#@return 
2183#@exception OG_ERR_FORMAT    Formato incorrecto.
2184#@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount).
2185#@exception OG_ERR_NOTFOUND  Fichero de configuración no encontrado: grub.cfg burg.cfg.
2186#@version 1.1.0 - Primeras pruebas con Burg. grub no soportado.
2187#@author  Antonio J. Doblas Viso. Universidad de Malaga
2188#@date    2018-01-24
2189#*/ ##
[d2c8674]2190function  ogBootLoaderSetResolution ()
2191{
[deacf00]2192
2193# Variables locales.
2194local FUNC PART CFGFILE RESOLUTION NEWRESOLUTION DEFAULTRESOLUTION BOOTLOADER BOOTLOADERDIR CFGFILE MSG
2195
2196# Si se solicita, mostrar ayuda.
2197if [ "$*" == "help" ]; then
2198    ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetResolution ogBurgSetResolution"
2199    return   
2200fi
2201
2202
2203# Nombre de la función que llama a esta.
2204FUNC="${FUNCNAME[@]:1}"
2205FUNC="${FUNC%%\ *}"
2206
2207
2208# Error si no se reciben 2 parametros.
2209[ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage [str_resolution]" || return $?
2210
2211# Error si no puede montar sistema de archivos.
2212PART=$(ogMount $1 $2) || return $?
2213# La función debe ser llamanda desde oogGrugSetResolution or ogBurgSetResolution.
2214case "$FUNC" in
2215    ogGrubSetResolution)
2216        BOOTLOADER="grug"
2217        BOOTLOADERDIR="grubMBR"
2218        CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" 
2219        ogRaiseError $OG_ERR_FORMAT "ogGrubSetResolution not sopported"
2220        return $?     
2221        ;;
2222    ogBurgSetResolution)
2223        BOOTLOADER="burg"
2224        BOOTLOADERDIR="burg"
2225        CFGFILE="$PART/boot/burg/burg.cfg"       
2226        ;;
2227    *)
2228        ogRaiseError $OG_ERR_FORMAT "Use ogBootLoaderSetResolution"
2229        return $?
2230        ;;
2231esac
2232
2233DEFAULTRESOLUTION=1024x768
2234
2235# Comprobamos que exista fichero de configuración
2236[ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $?
2237
2238#controlar variable a consierar vga (default template) o video (menu)
2239#Si solo dos parametros autoconfiguracion basado en el parametro vga de las propiedad menu. si no hay menu asignado es 788 por defecto
2240if [ $# -eq 2 ] ; then 
2241        if [ -n $video ]; then
2242                NEWRESOLUTION=$(echo "$video" | cut -f2 -d: | cut -f1 -d-)
2243        fi
2244        if [ -n $vga ] ; then
2245        case "$vga" in
2246                788|789|814)
2247                        NEWRESOLUTION=800x600
2248                        ;;
2249                791|792|824)
2250                        NEWRESOLUTION=1024x768
2251                        ;;
2252                355)
2253                        NEWRESOLUTION=1152x864
2254                        ;;
2255                794|795|829)
2256                        NEWRESOLUTION=1280x1024
2257                        ;;
2258        esac
2259        fi
2260fi
2261
2262if [ $# -eq 3 ] ; then
2263        #comprobamos que el parametro 3 cumple formato NNNNxNNNN
2264        ogCheckStringInReg $3 "[0-9]{3,4}[x][0-9]{3,4}\$" &&  NEWRESOLUTION="$3" || ogRaiseError $OG_ERR_FORMAT "param 3 is not a valid resolution: 800x600, 1024x768, 1152x864, 1280x1024, 1600x1200"
2265fi
2266
2267# Si no existe NEWRESOLUCION  asignamos la defaulT
2268[ -z "$NEWRESOLUTION" ] && NEWRESOLUTION=$DEFAULRESOLUTION
2269
2270#Cambiamos la entrada el fichero de configuración.
2271sed -i s/gfxmode=.*$/gfxmode=$NEWRESOLUTION/g $CFGFILE
2272}
[6bb748b]2273
[872b044]2274#/**
[6bb748b]2275#         ogRefindInstall  int_ndisk bool_autoconfig
2276#@brief   Instala y actualiza el gestor rEFInd en la particion EFI
2277#@param   int_ndisk
2278#@param   bolean_Check__auto_config   true | false[default]
2279#@return
2280#@exception OG_ERR_FORMAT    Formato incorrecto.
2281#@version 1.1.0 - Primeras pruebas.
2282#@author  Juan Carlos Garcia.   Universidad de ZAragoza.
2283#@date    2017-06-26
2284#*/ ##
[d2c8674]2285function ogRefindInstall ()
2286{
[6bb748b]2287
2288# Variables locales.
2289local DISK EFIDIR CONFIG EFIPARTITIONID
2290
2291
2292# Si se solicita, mostrar ayuda.
2293if [ "$*" == "help" ]; then
2294    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk boolean_autoconfig " \
2295           "$FUNCNAME 1 TRUE"
2296    return
2297fi
2298
2299# Error si no se recibe 1 parámetro.
2300[ $# -ge 1 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
2301
2302
2303DISK=$1
2304EFIDIR=/mnt/$(ogDiskToDev $1 1 | cut -c 6-8)$1/EFI
2305CONFIG=${2:-"FALSE"}
2306EFIPARTITIONID=$(ogGetPartitionId $1 1)
2307if [ "$EFIPARTITIONID" == "EF00" ] || [ "$EFIPARTITIONID" == "ef00" ]; then
2308    cp -pr /opt/opengnsys/lib/refind ${EFIDIR}
2309    case "$CONFIG" in
2310        FALSE)
2311        if [ -a ${EFIDIR}/ubuntu ]; then
2312            echo "menuentry \"Ubuntu\" {" >> ${EFIDIR}/refind/refind.conf
2313            echo "loader /EFI/ubuntu/grubx64.efi" >> ${EFIDIR}/refind/refind.conf
2314            echo "icon /EFI/refind/icons/os_linux.png" >> ${EFIDIR}/refind/refind.conf
2315            echo "}" >> ${EFIDIR}/refind/refind.conf
2316        fi
2317        if [ -a ${EFIDIR}/Microsoft ]; then
2318            echo "menuentry \"Windows\" {" >> ${EFIDIR}/refind/refind.conf
2319            echo "loader /EFI/Microsoft/Boot/bootmgfw.efi" >> ${EFIDIR}/refind/refind.conf
2320            echo "}" >> ${EFIDIR}/refind/refind.conf
2321        fi
2322        ;;
2323        TRUE)
2324        cp  ${EFIDIR}/refind/refind.conf.auto ${EFIDIR}/refind/refind.conf
2325        ;;
2326    esac
2327else
2328$(ogRaiseError $OG_ERR_FORMAT; echo $?)
2329fi
2330}
2331
Note: See TracBrowser for help on using the repository browser.