source: client/engine/Boot.lib @ 4d2b852

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 4d2b852 was b94c497, checked in by ramon <ramongomez@…>, 12 years ago

Versión 1.0.5: Mejor proceso del fichero de configuración de GRUB2, para permitir el arranque de distribuciones OpenSuSE 12.3

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

  • Property mode set to 100755
File size: 33.1 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.
[e538e62]7#@version 1.0.5
[b094c59]8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogBoot int_ndisk int_npartition
14#@brief   Inicia el proceso de arranque de un sistema de archivos.
[42669ebf]15#@param   int_ndisk      nº de orden del disco
16#@param   int_npartition nº de orden de la partición
[b094c59]17#@return  (activar el sistema de archivos).
18#@exception OG_ERR_FORMAT    Formato incorrecto.
19#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
20#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
21#@exception OG_ERR_NOTOS     La partición no tiene instalado un sistema operativo.
[f5432db7]22#@note    En Linux, debe arrancarse la partición del directorio \c /boot
[3915005]23#@version 0.1 - Integración para OpenGnSys. - EAC: HDboot; BootLinuxEX en Boot.lib 
[985bef0]24#@author  Antonio J. Doblas Viso, Universidad de Malaga
[e05993a]25#@date    2008-10-27
[3915005]26#@version 0.9 - Adaptación para OpenGnSys.
[b094c59]27#@author  Ramon Gomez, ETSII Universidad de Sevilla
28#@date    2009-09-11
[40ad2e8d]29#@version 1.0.4 - Soporta modo de arranque Windows (parámetro de inicio "winboot").
30#@author  Ramon Gomez, ETSII Universidad de Sevilla
31#@date    2012-04-12
[1e7eaab]32#*/ ##
[42669ebf]33function ogBoot ()
34{
[b094c59]35# Variables locales.
[40ad2e8d]36local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER f
[b094c59]37
[1e7eaab]38# Si se solicita, mostrar ayuda.
[b094c59]39if [ "$*" == "help" ]; then
40    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
41           "$FUNCNAME 1 1"
42    return
43fi
[1e7eaab]44# Error si no se reciben 2 parámetros.
[b094c59]45[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
46
[1e7eaab]47# Detectar tipo de sistema de archivos y montarlo.
[049eadbe]48PART=$(ogDiskToDev $1 $2) || return $?
[b094c59]49TYPE=$(ogGetFsType $1 $2) || return $?
[f5432db7]50MNTDIR=$(ogMount $1 $2) 2>/dev/null
51[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[b094c59]52
53case "$TYPE" in
[049eadbe]54    EXT[234]|REISERFS|REISER4|JFS|XFS)
[1e7eaab]55        # Obtiene los parámetros de arranque para Linux.
[f5432db7]56        PARAMS=$(ogLinuxBootParameters $1 $2) || return $?
57        read -e KERNEL INITRD APPEND <<<"$PARAMS"
[1e7eaab]58        # Si no hay kernel, no hay sistema operativo.
[f5432db7]59        [ -z "$KERNEL" ] && ogRaiseError $OG_ERR_NOTOS && return $?
[1e7eaab]60        # Arrancar de partición distinta a la original.
[049eadbe]61        [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}')
[f5432db7]62        # Configurar kernel Linux con los parámetros leídos de su GRUB.
[049eadbe]63        kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}"
[40ad2e8d]64        kexec -e &
[f5432db7]65        ;;
66    NTFS|HNTFS|FAT32|HFAT32)
[1e7eaab]67        # Compruebar si hay un cargador de Windows.
[f5432db7]68        for f in io.sys ntldr bootmgr; do
69            FILE="$(ogGetPath $1 $2 $f 2>/dev/null)"
[d10549b]70            [ -n "$FILE" ] && LOADER="$f"
[f5432db7]71        done
72        [ -z "$LOADER" ] && ogRaiseError $OG_ERR_NOTOS && return $?
[40ad2e8d]73        if [ "$winboot" == "kexec" ]; then
74            # Modo de arranque en caliente (con kexec).
75            cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
76            kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
77            kexec -e &
78        else
79            # Modo de arranque por reinicio (con reboot).
[75a296b]80            dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3
81            dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3
82            dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3
[4085f13]83            if  [ -z "$(ogGetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleannboot')" ]; then               
84            ogAddRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot'
85            ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot' "cmd /c del c:\ogboot.*"
86            fi
87            # Activar la partición.
88            ogSetPartitionActive $1 $2
[75a296b]89            reboot
90        fi
[f5432db7]91        ;;
92    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
[326cec3]93        return $?
[f5432db7]94        ;;
[b094c59]95esac
96
[40ad2e8d]97# Parar Browser para evitar cuelgues.
[0b9c763]98pkill browser
[b094c59]99}
100
101
102#/**
[3e1561d]103#         ogGetWindowsName int_ndisk int_npartition
104#@brief   Muestra el nombre del equipo en el registro de Windows.
[42669ebf]105#@param   int_ndisk      nº de orden del disco
106#@param   int_npartition nº de orden de la partición
[3e1561d]107#@return  str_name - nombre del equipo
108#@exception OG_ERR_FORMAT    Formato incorrecto.
109#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
110#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]111#@version 0.9 - Adaptación para OpenGnSys.
[3e1561d]112#@author  Ramon Gomez, ETSII Universidad de Sevilla
113#@date    2009-09-23
[1e7eaab]114#*/ ##
[42669ebf]115function ogGetWindowsName ()
116{
[3e1561d]117# Variables locales.
118local PART MNTDIR
119
[1e7eaab]120# Si se solicita, mostrar ayuda.
[3e1561d]121if [ "$*" == "help" ]; then
122    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
123           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
124    return
125fi
[1e7eaab]126# Error si no se reciben 2 parámetros.
[3e1561d]127[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
128
[1e7eaab]129# Montar el sistema de archivos.
[f5432db7]130MNTDIR=$(ogMount $1 $2) 2>/dev/null
131[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[3e1561d]132
[1e7eaab]133# Obtener dato del valor de registro.
[3e1561d]134ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
135}
136
137
138#/**
[b94c497]139#         ogLinuxBootParameters int_ndisk int_nfilesys
[b094c59]140#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
[42669ebf]141#@param   int_ndisk      nº de orden del disco
[b94c497]142#@param   int_nfilesys   nº de orden del sistema de archivos
[42669ebf]143#@return  str_kernel str_initrd str_parameters ...
[b094c59]144#@exception OG_ERR_FORMAT    Formato incorrecto.
145#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
146#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[055adcf]147#@warning Función básica usada por \c ogBoot
[3915005]148#@version 0.9 - Primera adaptación para OpenGnSys.
[b094c59]149#@author  Ramon Gomez, ETSII Universidad de Sevilla
150#@date    2009-09-11
[199bdf3]151#@version 0.9.2 - Soporta partición /boot independiente.
152#@author  Ramon Gomez, ETSII Universidad de Sevilla
153#@date    2010-07-20
[b94c497]154#@version 1.0.5 - Mejoras en tratamiento de GRUB2.
155#@author  Ramon Gomez, ETSII Universidad de Sevilla
156#@date    2013-05-14
[1e7eaab]157#*/ ##
[42669ebf]158function ogLinuxBootParameters ()
159{
[b094c59]160# Variables locales.
[199bdf3]161local MNTDIR CONFDIR CONFFILE
[b094c59]162
[1e7eaab]163# Si se solicita, mostrar ayuda.
[b094c59]164if [ "$*" == "help" ]; then
[b94c497]165    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
166           "$FUNCNAME 1 2  ==>  /vmlinuz-3.5.0-21-generic /initrd.img-3.5.0-21-generic root=/dev/sda2 ro splash"
[b094c59]167    return
168fi
[1e7eaab]169# Error si no se reciben 2 parámetros.
[b094c59]170[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
171
[1e7eaab]172# Detectar id. de tipo de partición y codificar al mnemonico.
[f5432db7]173MNTDIR=$(ogMount $1 $2) 2>/dev/null
174[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[b094c59]175
176# Fichero de configuración de GRUB.
[199bdf3]177CONFDIR=$MNTDIR                               # Partición de arranque /boot.
178[ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot   # Partición raíz con directorio boot.
[210a4ffc]179CONFFILE="$CONFDIR/grubPARTITION/boot/grub/grub.cfg"
180[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/menu.lst"
[199bdf3]181[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/grub.cfg"
[b94c497]182[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub2/grub.cfg"
[199bdf3]183[ ! -e $CONFFILE ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
[b094c59]184
[1e7eaab]185# Toma del fichero de configuracion los valores del kernel, initrd
[ee4a96e]186#       y parámetros de arranque usando las cláusulas por defecto
187#       ("default" en GRUB1, "set default" en GRUB2)
188#       y los formatea para que sean compatibles con \c kexec .  */
[1e7eaab]189# /* (comentario Doxygen)
[b094c59]190awk 'BEGIN {cont=-1;}
[b94c497]191     $1~/^default$/     {sub(/=/," "); def=$2;}
192     $1~/^set$/ && $2~/^default$/ {gsub(/[="]/," "); def=$3;
193                                   if (def ~ /saved_entry/) def=0;
194                                  }
195     $1~/^(title|menuentry)$/ {cont++}
196     $1~/^(kernel|linux)$/ {if (def==cont) {
197                               kern=$2;
198                               sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}  # /* (comentario Doxygen)
199                           }
200     $1~/^initrd$/      {if (def==cont) init=$2}
[b094c59]201     END {if (kern!="") printf("%s %s %s", kern,init,app)}
[199bdf3]202    ' $CONFFILE
[1e7eaab]203# */ (comentario Doxygen)
[b094c59]204}
205
[3e1561d]206
207#/**
[e538e62]208#         ogSetWindowsName int_ndisk int_nfilesys str_name
[3e1561d]209#@brief   Establece el nombre del equipo en el registro de Windows.
[42669ebf]210#@param   int_ndisk      nº de orden del disco
[e538e62]211#@param   int_nfilesys   nº de orden del sistema de archivos
[42669ebf]212#@param   str_name       nombre asignado
[3e1561d]213#@return  (nada)
[e538e62]214#@exception OG_ERR_FORMAT     Formato incorrecto.
215#@exception OG_ERR_NOTFOUND   Disco o particion no corresponden con un dispositivo.
216#@exception OG_ERR_PARTITION  Tipo de partición desconocido o no se puede montar.
217#@exception OG_ERR_OUTOFLIMIT Nombre Netbios con más de 15 caracteres.
[3915005]218#@version 0.9 - Adaptación a OpenGnSys.
[3e1561d]219#@author  Ramon Gomez, ETSII Universidad de Sevilla
220#@date    2009-09-24
[e538e62]221#@version 1.0.5 - Establecer restricción de tamaño de nombre Netbios.
222#@author  Ramon Gomez, ETSII Universidad de Sevilla
223#@date    2013-03-20
[1e7eaab]224#*/ ##
[42669ebf]225function ogSetWindowsName ()
226{
[3e1561d]227# Variables locales.
228local PART MNTDIR NAME
229
[1e7eaab]230# Si se solicita, mostrar ayuda.
[3e1561d]231if [ "$*" == "help" ]; then
[e538e62]232    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys str_name" \
[3e1561d]233           "$FUNCNAME 1 1 PRACTICA-PC"
234    return
235fi
[1e7eaab]236# Error si no se reciben 3 parámetros.
[3e1561d]237[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[e538e62]238# Error si el nombre supera los 15 caracteres.
239[ ${#3} -le 15 ] || ogRaiseError $OG_ERR_OUTOFLIMIT "\"${3:0:15}...\"" || return $?
[3e1561d]240
[42669ebf]241# Montar el sistema de archivos.
[f5432db7]242MNTDIR=$(ogMount $1 $2) 2>/dev/null
[e538e62]243[ -n "$MNTDIR" ] || ogRaiseError OG_ERR_PARTITION "$1, $2" || return $?
[3e1561d]244NAME="$3"
245
[1e7eaab]246# Modificar datos de los valores de registro.
[4b9cdda]247ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null
248ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
249ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
250ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
251ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
[3e1561d]252}
253
[f5432db7]254
[4b9cdda]255#/**
256#         ogSetWinlogonUser int_ndisk int_npartition str_username
257#@brief   Establece el nombre de usuario por defecto en la entrada de Windows.
258#@param   int_ndisk      nº de orden del disco
259#@param   int_npartition nº de orden de la partición
260#@param   str_username   nombre de usuario por defecto
261#@return  (nada)
262#@exception OG_ERR_FORMAT    Formato incorrecto.
263#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
264#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]265#@version 0.9.2 - Adaptación a OpenGnSys.
[4b9cdda]266#@author  Ramon Gomez, ETSII Universidad de Sevilla
267#@date    2010-07-20
268#*/ ##
269function ogSetWinlogonUser ()
270{
271# Variables locales.
272local PART MNTDIR NAME
273
274# Si se solicita, mostrar ayuda.
275if [ "$*" == "help" ]; then
276    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \
277           "$FUNCNAME 1 1 USUARIO"
278    return
279fi
280# Error si no se reciben 3 parámetros.
281[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
282
283# Montar el sistema de archivos.
284MNTDIR=$(ogMount $1 $2) 2>/dev/null
285[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
286NAME="$3"
287
288# Modificar datos en el registro.
289ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3"
290}
291
[38231e9]292
293#/**
[9e8773c]294#         ogBootMbrXP int_ndisk
[38231e9]295#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
[42669ebf]296#@param   int_ndisk      nº de orden del disco
[945b003]297#@return  salida del programa my-sys
[38231e9]298#@exception OG_ERR_FORMAT    Formato incorrecto.
299#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]300#@version 0.9 - Adaptación a OpenGnSys.
[38231e9]301#@author  Antonio J. Doblas Viso. Universidad de Málaga
302#@date    2009-09-24
303#*/ ##
304
[9e8773c]305function ogBootMbrXP ()
[e05993a]306{
[38231e9]307# Variables locales.
308local PART
309
310# Si se solicita, mostrar ayuda.
311if [ "$*" == "help" ]; then
312    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
313           "$FUNCNAME 1 "
314    return
[945b003]315fi
[38231e9]316# Error si no se reciben 1 parámetros.
317[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
318
[6e139c9]319PART="$(ogDiskToDev $1)" || return $?
[38231e9]320ms-sys -z -f $PART
321ms-sys -m -f $PART
[945b003]322}
[42669ebf]323
[fdad5a6]324
[9e8773c]325#/**
326#         ogBootMbrGeneric int_ndisk
327#@brief   Genera un nuevo Codigo de arranque en el MBR del disco indicado, compatible con los SO tipo Windows, Linux.
328#@param   int_ndisk      nº de orden del disco
329#@return  salida del programa my-sys
330#@exception OG_ERR_FORMAT    Formato incorrecto.
331#@exception OG_ERR_NOTFOUND Tipo de partición desconocido o no se puede montar.
[3915005]332#@version 0.9 - Adaptación a OpenGnSys.
[9e8773c]333#@author  Antonio J. Doblas Viso. Universidad de Málaga
334#@date    2009-09-24
335#*/ ##
336
337function ogBootMbrGeneric ()
338{
339# Variables locales.
340local PART
341
342# Si se solicita, mostrar ayuda.
343if [ "$*" == "help" ]; then
344    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
345           "$FUNCNAME 1 "
346    return
347fi
348# Error si no se reciben 1 parámetros.
349[ $# == 1 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
350
351PART="$(ogDiskToDev $1)" || return $(ogRaiseError $OG_ERR_NOTFOUND; echo $?)
352ms-sys -z -f $PART
353ms-sys -s -f $PART
354}
355
356
357
[fdad5a6]358
359#/**
360#         ogFixBootSector int_ndisk int_parition
361#@brief   Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs
362#@param   int_ndisk      nº de orden del disco
363#@param   int_partition     nº de particion
364#@return 
365#@exception OG_ERR_FORMAT    Formato incorrecto.
366#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]367#@version 0.9 - Adaptación a OpenGnSys.
[fdad5a6]368#@author  Antonio J. Doblas Viso. Universidad de Málaga
369#@date    2009-09-24
370#*/ ##
371
372function ogFixBootSector ()
373{
374# Variables locales.
[1cd64e6]375local PARTYPE DISK PART FILE
[fdad5a6]376
377# Si se solicita, mostrar ayuda.
378if [ "$*" == "help" ]; then
379    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
380           "$FUNCNAME 1 1 "
381    return
382fi
383
384# Error si no se reciben 2 parámetros.
385[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
386
387#TODO, solo si la particion existe
388#TODO, solo si es ntfs o fat
389PARTYPE=$(ogGetPartitionId $1 $2)
[3915005]390case "$PARTYPE" in
[fdad5a6]391        1|4|6|7|b|c|e|f)
392        ;;
393        *)
394        return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
395        ;;
396esac
397
398ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
399
400#Preparando instruccion
401let DISK=$1-1   
402PART=$2
[1cd64e6]403FILE=/tmp/temp$$
[fdad5a6]404cat > $FILE <<EOF
405disk=$DISK
406main_part=$PART
407fix_first_sector=yes
408EOF
409
[5fde4bc]410spartlnx.run -cui -nm -a -f $FILE &
411sleep 5
412ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
[1cd64e6]413rm -f $FILE
[fdad5a6]414}
415
416
417
418#/**
419#         ogWindowsBootParameters int_ndisk int_parition
[78b5dfe7]420#@brief   Configura el gestor de arranque de windows 7 / vista / XP / 2000
[fdad5a6]421#@param   int_ndisk      nº de orden del disco
422#@param   int_partition     nº de particion
423#@return 
424#@exception OG_ERR_FORMAT    Formato incorrecto.
425#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]426#@version 0.9 - Integración desde EAC para OpenGnSys.
[fdad5a6]427#@author  Antonio J. Doblas Viso. Universidad de Málaga
428#@date    2009-09-24
[78b5dfe7]429#@version 1.0.1 - Adapatacion para OpenGnsys.
430#@author  Antonio J. Doblas Viso. Universidad de Málaga
431#@date    2011-05-20
[fdad5a6]432#*/ ##
433
434
435function ogWindowsBootParameters ()
436{
437# Variables locales.
[3915005]438local PART DISK FILE VERSION WINVER MOUNT
[78b5dfe7]439#Preparando variables adaptadas a sintaxis windows.
440let DISK=$1-1
441PART=$2
[3915005]442FILE=/tmp/temp$$
[fdad5a6]443
444# Si se solicita, mostrar ayuda.
445if [ "$*" == "help" ]; then
446    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
447           "$FUNCNAME 1 1 "
448    return
449fi
450
451# Error si no se reciben 2 parámetros.
452[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
453
454ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
455
456VERSION=$(ogGetOsVersion $1 $2)
457
[78b5dfe7]458if echo "$VERSION" | grep "Windows 7"
[fdad5a6]459then
460        WINVER="Windows 7"
[78b5dfe7]461elif echo "$VERSION" | grep "Windows Seven"
[fdad5a6]462then
463        WINVER="Windows Vista"
[78b5dfe7]464elif echo "$VERSION" | grep "XP"
465then
466        MOUNT=$(ogMount $1 $2)
467        [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
468        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
469        return 0
[fdad5a6]470else
471        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
472fi
473
474ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
[78b5dfe7]475
[fdad5a6]476
477#Preparando instruccion Windows Resume Application
478cat > $FILE <<EOF
479boot_disk=$DISK
480boot_main_part=$PART
481disk=$DISK
482main_part=$PART
483boot_entry=Windows Resume Application
484EOF
[5fde4bc]485spartlnx.run -cui -nm -w -f $FILE &
486sleep 5
487ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
488
489 
[fdad5a6]490
491#Preparando instruccion tipo windows
492cat > $FILE <<EOF
493boot_disk=$DISK
494boot_main_part=$PART
495disk=$DISK
496main_part=$PART
497boot_entry=$WINVER
498EOF
[5fde4bc]499spartlnx.run -cui -nm -w -f $FILE &
500sleep 5
501ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
502
[fdad5a6]503
[250742d]504##Preparando instruccion        Ramdisk Options
[5fde4bc]505cat > $FILE <<EOF
506boot_disk=$DISK
507boot_main_part=$PART
508disk=$DISK
509main_part=$PART
510boot_entry=Ramdisk Options
511EOF
512spartlnx.run -cui -nm -w -f $FILE &
513sleep 5
514ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
515
[fdad5a6]516
517#Preparando instruccion Windows Boot Manager
518cat > $FILE <<EOF
519boot_disk=$DISK
520boot_main_part=$PART
521disk=$DISK
522main_part=$PART
523boot_entry=Windows Boot Manager
524EOF
[5fde4bc]525spartlnx.run -cui -nm -w -f $FILE &
526sleep 5
527ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
528
[fdad5a6]529
530#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
[5fde4bc]531cat > $FILE <<EOF
532boot_disk=$DISK
533boot_main_part=$PART
534disk=$DISK
535main_part=$PART
536boot_entry=Herramienta de diagnóstico de memoria de Windows
537EOF
538spartlnx.run -cui -nm -w -f $FILE &
539sleep 5
540ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
[fdad5a6]541
542}
[3915005]543
[fdad5a6]544
[78b5dfe7]545#         ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition
[fdad5a6]546#@brief   Registra una partición en windows con un determinado volumen.
547#@param   int_ndisk      nº de orden del disco a registrar
548#@param   int_partition     nº de particion a registrar
549#@param   str_volumen      volumen a resgistar
550#@param   int_ndisk_windows      nº de orden del disco donde esta windows
551#@param   int_partition_windows     nº de particion donde esta windows
552#@return 
553#@exception OG_ERR_FORMAT    Formato incorrecto.
554#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]555#@version 0.9 - Adaptación a OpenGnSys.
[fdad5a6]556#@author  Antonio J. Doblas Viso. Universidad de Málaga
557#@date    2009-09-24
558#*/ ##
[78b5dfe7]559function ogWindowsRegisterPartition ()
[3915005]560{
[fdad5a6]561# Variables locales.
[3915005]562local PART DISK FILE REGISTREDDISK REGISTREDPART REGISTREDVOL VERSION SYSTEMROOT
[fdad5a6]563
564# Si se solicita, mostrar ayuda.
565if [ "$*" == "help" ]; then
566    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
567           "$FUNCNAME 1 1 c: 1 1"
568    return
569fi
570
571# Error si no se reciben 5 parámetros.
572[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
573
574REGISTREDDISK=$1
575REGISTREDPART=$2
576REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
577DISK=$4
578PART=$5
[3915005]579FILE=/tmp/temp$$
[fdad5a6]580
581ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
582ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
583
584ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
585
586VERSION=$(ogGetOsVersion $DISK $PART)
587
588#Systemroot
589
590if ogGetPath $DISK $PART WINDOWS
591then
592        SYSTEMROOT="Windows"
593elif ogGetPath $DISK $PART WINNT
594then
595        SYSTEMROOT="winnt"
596else
597        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
598fi
599
600ogUnmount $DISK $PART
601let DISK=$DISK-1
602let REGISTREDDISK=$REGISTREDDISK-1
603#Preparando instruccion Windows Boot Manager
604cat > $FILE <<EOF
605windows_disk=$DISK
606windows_main_part=$PART
607windows_dir=$SYSTEMROOT
608disk=$REGISTREDDISK
609main_part=$REGISTREDPART
610;ext_part
611part_letter=$REGISTREDVOL
612EOF
[5fde4bc]613spartlnx.run -cui -nm -u -f $FILE &
614sleep 5
615ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
616
[e0c0d93]617}
[ab82469]618
619
[9c535e0]620#         ogGrubInstallMbr  int_disk_GRUBCFG  int_partition_GRUBCFG #@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
[a4b1e2a]621#@brief   Instala y actualiza el gestor grub el el MBR del disco duro donde se encuentra el fichero grub.cfg. Admite sistemas Windows.
[9c535e0]622#@param   int_disk_SecondStage     
623#@param   int_part_SecondStage     
624#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
[ab82469]625#@return 
626#@exception OG_ERR_FORMAT    Formato incorrecto.
627#@version 1.0.2 - Primeras pruebas.
628#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
629#@date    2011-10-29
[9c535e0]630#@version 1.0.3 - Soporte para linux de 32 y 64 bits
631#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
632#@date    2012-03-13
633#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la primera etapa
634#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
635#@date    2012-03-13
[ab82469]636#*/ ##
637
[9c535e0]638function ogGrubInstallMbr {
[ab82469]639
640# Variables locales.
[1c69be8]641local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[ab82469]642
643# Si se solicita, mostrar ayuda.
644if [ "$*" == "help" ]; then
[9c535e0]645    ogHelp "$FUNCNAME" "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \"  " \
646           "$FUNCNAME 1 1 FALSE " \
647           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
[ab82469]648    return
[9c535e0]649fi 
[ab82469]650
651# Error si no se reciben 2 parámetros.
[9c535e0]652[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
[ab82469]653
654
[9c535e0]655DISK=$1; PART=$2;
656CHECKOS=${3:-"FALSE"}
657KERNELPARAM=$4
[1c69be8]658BACKUPNAME=".backup.og"
[ab82469]659
[9c535e0]660#Error si no es linux.
661#TODO: comprobar si se puede utilizar la particion windows como contenedor de grub.
[a4b1e2a]662#VERSION=$(ogGetOsVersion $DISK $PART)
663#echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
[ab82469]664
[9c535e0]665#Localizar primera etapa del grub
666FIRSTSTAGE=$(ogDiskToDev $DISK)
[ab82469]667
[9c535e0]668#localizar disco segunda etapa del grub
669SECONDSTAGE=$(ogMount $DISK $PART)
[ab82469]670
[a4b1e2a]671# prepara el directorio principal de la segunda etapa
672[ -d ${SECONDSTAGE}/boot/grub/ ]  || mkdir -p ${SECONDSTAGE}/boot/grub/
673
[9c535e0]674#Localizar directorio segunda etapa del grub   
675PREFIXSECONDSTAGE="/boot/grubMBR"
[ab82469]676
[9c535e0]677# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]678if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]679then
680    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
681    then
[1c69be8]682        # Si no se reconfigura se utiliza el grub.cfg orginal
683        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
684                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
685        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
686        # Reactivamos el grub con el grub.cfg original.
[9c535e0]687        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
688        return $?
689    fi
690fi
691
692# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
693#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
694echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
695echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
[ab82469]696
[9c535e0]697#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup
[1c69be8]698[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]699
700#Preparar configuración segunda etapa: crear ubicacion
701mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
702#Preparar configuración segunda etapa: crear cabecera del fichero
703/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
704#Preparar configuración segunda etapa: crear entrada del sistema operativo
705grubSyntax "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
706
707#Instalar el grub
708grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
709}
[ab82469]710
711
712
[9c535e0]713#         ogGrubInstallPartition int_disk_SECONDSTAGE  int_partition_SECONDSTAGE bolean_Check_Os_installed_and_Configure_2ndStage
714#@brief   Instala y actualiza el gestor grub en el bootsector de la particion indicada
715#@param   int_disk_SecondStage     
716#@param   int_part_SecondStage     
717#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
718#@param   str "kernel param "   
719#@return 
720#@exception OG_ERR_FORMAT    Formato incorrecto.
721#@version 1.0.2 - Primeras pruebas.
722#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
723#@date    2011-10-29
724#@version 1.0.3 - Soporte para linux de 32 y 64 bits
725#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
726#@date    2012-03-13
727#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la priemra etapa
728#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
729#@date    2012-03-13
730#*/ ##
[ab82469]731
[9c535e0]732function ogGrubInstallPartition {
[ab82469]733
[9c535e0]734# Variables locales.
[1c69be8]735local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[9c535e0]736
737# Si se solicita, mostrar ayuda.
738if [ "$*" == "help" ]; then
739    ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \" " \
740           "$FUNCNAME 1 1 FALSE " \
741           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
742    return
743fi 
744
745# Error si no se reciben 2 parámetros.
746[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
747
748DISK=$1; PART=$2;
749CHECKOS=${3:-"FALSE"}
750KERNELPARAM=$4
[1c69be8]751BACKUPNAME=".backup.og"
[9c535e0]752
753#error si no es linux.
754VERSION=$(ogGetOsVersion $DISK $PART)
755echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
756
757#Localizar primera etapa del grub
758FIRSTSTAGE=$(ogDiskToDev $DISK $PART)
759
760#localizar disco segunda etapa del grub
761SECONDSTAGE=$(ogMount $DISK $PART)
762
763#Localizar directorio segunda etapa del grub   
764PREFIXSECONDSTAGE="/boot/grubPARTITION"
765
766# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]767if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]768then
769    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
770    then
[1c69be8]771        # Si no se reconfigura se utiliza el grub.cfg orginal
772        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
773                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
774        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
775        # Reactivamos el grub con el grub.cfg original.
[9c535e0]776        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
777        return $?
778    fi
779fi
780
781# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
782#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
783echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
784echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
785
[1c69be8]786#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup.og
787[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]788
789#Preparar configuración segunda etapa: crear ubicacion
790mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
791#Preparar configuración segunda etapa: crear cabecera del fichero
792/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
793#Preparar configuración segunda etapa: crear entrada del sistema operativo
794grubSyntax $DISK $PART "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
795
796#Instalar el grub
797grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
[ab82469]798}
799
[00cede9]800###
801#En pruebas
802##
803#/**
[c9c2f1d1]804#         ogConfigureFstab int_ndisk int_nfilesys
[00cede9]805#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
806#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]807#@param   int_nfilesys   nº de orden del sistema de archivos
[00cede9]808#@return  (nada)
809#@exception OG_ERR_FORMAT    Formato incorrecto.
[c9c2f1d1]810#@exception OG_ERR_NOTFOUND  No se encuentra el fichero fstab a procesar.
811#@warning Puede haber un error si hay más de 1 partición swap.
812#@version 1.0.5 - Primera versión para OpenGnSys.
813#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
814#@date    2013-03-21
[00cede9]815#*/ ##
816function ogConfigureFstab {
817# Variables locales.
[c9c2f1d1]818local FSTAB DEFROOT PARTROOT DEFSWAP PARTSWAP
[00cede9]819
820# Si se solicita, mostrar ayuda.
821if [ "$*" == "help" ]; then
[c9c2f1d1]822    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
823           "$FUNCNAME 1 1"
[00cede9]824    return
825fi
826# Error si no se reciben 2 parámetros.
827[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[c9c2f1d1]828# Error si no se encuentra un fichero  etc/fstab  en el sistema de archivos.
829FSTAB=$(ogGetPath $1 $2 /etc/fstab) 2>/dev/null
830[ -n "$FSTAB" ] || ogRaiseError $OG_ERR_NOTFOUND "$1,$2,/etc/fstab" || return $?
831
832# Hacer copia de seguridad del fichero fstab original.
833cp -a ${FSTAB} ${FSTAB}.backup
834# Dispositivo del raíz en fichero fstab: 1er campo (si no tiene "#") con 2º campo = "/".
835DEFROOT=$(awk '$1!~/#/ && $2=="/" {print $1}' ${FSTAB})
836PARTROOT=$(ogDiskToDev $1 $2)
[200635a]837# Configuración de swap (solo 1ª partición detectada).
838PARTSWAP=$(blkid -t TYPE=swap | awk -F: 'NR==1 {print $1}')
[00cede9]839if [ -n "$PARTSWAP" ]
840then
[c9c2f1d1]841    # Dispositivo de swap en fichero fstab: 1er campo (si no tiene "#") con 3er campo = "swap".
842    DEFSWAP=$(awk '$1!~/#/ && $3=="swap" {print $1}' ${FSTAB})
[00cede9]843    if [ -n "$DEFSWAP" ]
[c9c2f1d1]844    then
845        echo "Hay definicion de swap en el fstab $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP"   # Mensaje temporal.
846        sed "s|$DEFSWAP|$PARTSWAP|g ; s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
[00cede9]847    else
[c9c2f1d1]848        echo "No hay definicion de swap y si hay partición swap -> moficamos fichero"   # Mensaje temporal.
849        sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
850        echo "$PARTSWAP  none    swap    sw   0  0" >> ${FSTAB}
[00cede9]851    fi 
852else
[c9c2f1d1]853    echo "No hay partición swap -> configuramos fstba"  # Mensaje temporal.
854    sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
[00cede9]855fi
856}
[9c535e0]857
[c9c2f1d1]858
[764f50e]859###
860#En pruebas
861##
862#/**
[c9c2f1d1]863#         ogSetLinuxName int_ndisk int_nfilesys [str_name]
[764f50e]864#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
865#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]866#@param   int_nfilesys   nº de orden del sistema de archivos
867#@param   str_name       nombre asignado (opcional)
[764f50e]868#@return  (nada)
869#@exception OG_ERR_FORMAT    Formato incorrecto.
870#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
871#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]872#@note    Si no se indica nombre, se asigna un valor por defecto.
873#@version 1.0.5 - Primera versión para OpenGnSys.
874#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
875#@date    2013-03-21
[764f50e]876#*/ ##
877function ogSetLinuxName ()
878{
879# Variables locales.
[c9c2f1d1]880local MNTDIR ETC NAME
[764f50e]881
882# Si se solicita, mostrar ayuda.
883if [ "$*" == "help" ]; then
[c9c2f1d1]884    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_name]" \
885           "$FUNCNAME 1 1" "$FUNCNAME 1 1 practica-pc"
[764f50e]886    return
887fi
[c9c2f1d1]888# Error si no se reciben 2 o 3 parámetros.
889case $# in
890    2)   # Asignar nombre automático (por defecto, "pc").
891         NAME="$(ogGetHostname)"
892         NAME=${NAME:-"pc"} ;;
893    3)   # Asignar nombre del 3er parámetro.
894         NAME="$3" ;;
895    *)   # Formato de ejecución incorrecto.
896         ogRaiseError $OG_ERR_FORMAT
897         return $?
898esac
[764f50e]899
900# Montar el sistema de archivos.
901MNTDIR=$(ogMount $1 $2) 2>/dev/null
902[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
903
904ETC=$(ogGetPath $1 $2 /etc)
905
906if [ -d "$ETC" ]; then
907        #cambio de nombre en hostname
[c9c2f1d1]908        echo "$NAME" > $ETC/hostname
[764f50e]909        #Opcion A para cambio de nombre en hosts
910        #sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts
[c9c2f1d1]911        #Opcion B componer fichero de hosts
912        cat > $ETC/hosts <<EOF
[764f50e]913127.0.0.1       localhost
914127.0.1.1       $NAME
915
916# The following lines are desirable for IPv6 capable hosts
917::1     ip6-localhost ip6-loopback
918fe00::0 ip6-localnet
919ff00::0 ip6-mcastprefix
920ff02::1 ip6-allnodes
921ff02::2 ip6-allrouters
922EOF
923fi
924}
925
[df814dd0]926
927###
928#En pruebas
929##
930#/**
[c9c2f1d1]931#         ogCleanLinuxDevices int_ndisk int_nfilesys
[df814dd0]932#@brief   Limpia los dispositivos del equipo de referencia. Interfaz de red ...
933#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]934#@param   int_nfilesys   nº de orden del sistema de archivos
[df814dd0]935#@return  (nada)
936#@exception OG_ERR_FORMAT    Formato incorrecto.
937#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
938#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]939#@version 1.0.5 - Primera versión para OpenGnSys.
940#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
941#@date    2013-03-21
[df814dd0]942#*/ ##
943function ogCleanLinuxDevices ()
944{
945# Variables locales.
[c9c2f1d1]946local MNTDIR
[df814dd0]947
948# Si se solicita, mostrar ayuda.
949if [ "$*" == "help" ]; then
[c9c2f1d1]950    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
951           "$FUNCNAME 1 1"
[df814dd0]952    return
953fi
954# Error si no se reciben 2 parámetros.
955[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
956
957# Montar el sistema de archivos.
958MNTDIR=$(ogMount $1 $2) 2>/dev/null
959[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
960
[c9c2f1d1]961# Eliminar fichero de configuración de udev para dispositivos fijos de red.
[e825eca]962rm -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules
[df814dd0]963}
964
Note: See TracBrowser for help on using the repository browser.