source: client/engine/Boot.lib @ 499a7ec

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 499a7ec was e763190, checked in by ramon <ramongomez@…>, 11 years ago

#548: Función ogWindowsBootParameters detecta y configura Windows 8.1.

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

  • Property mode set to 100755
File size: 33.4 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
[0a7f5c9]391        1|4|6|7|b|c|e|f|17|700)
[fdad5a6]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
[e763190]432#@version 1.0.5 - Soporte para Windows 8 y Windows 8.1.
433#@author  Ramon Gomez, ETSII Universidad de Sevilla
434#@date    2014-01-28
[fdad5a6]435#*/ ##
436
437function ogWindowsBootParameters ()
438{
439# Variables locales.
[3915005]440local PART DISK FILE VERSION WINVER MOUNT
[fdad5a6]441
442# Si se solicita, mostrar ayuda.
443if [ "$*" == "help" ]; then
444    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
445           "$FUNCNAME 1 1 "
446    return
447fi
448
449# Error si no se reciben 2 parámetros.
450[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
451
452ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
453
[e763190]454#Preparando variables adaptadas a sintaxis windows.
455let DISK=$1-1
456PART=$2
457FILE=/tmp/temp$$
458
[fdad5a6]459VERSION=$(ogGetOsVersion $1 $2)
460
[e763190]461if echo "$VERSION" | grep "Windows 8.1"
462then
463        WINVER="Windows 8.1"
464elif echo "$VERSION" | grep "Windows 8"
[f2efc27]465then
466        WINVER="Windows 8"
467elif echo "$VERSION" | grep "Windows 7"
[fdad5a6]468then
469        WINVER="Windows 7"
[78b5dfe7]470elif echo "$VERSION" | grep "Windows Seven"
[fdad5a6]471then
472        WINVER="Windows Vista"
[78b5dfe7]473elif echo "$VERSION" | grep "XP"
474then
475        MOUNT=$(ogMount $1 $2)
476        [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
477        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
478        return 0
[fdad5a6]479else
480        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
481fi
482
483ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
[78b5dfe7]484
[fdad5a6]485
486#Preparando instruccion Windows Resume Application
487cat > $FILE <<EOF
488boot_disk=$DISK
489boot_main_part=$PART
490disk=$DISK
491main_part=$PART
492boot_entry=Windows Resume Application
493EOF
[5fde4bc]494spartlnx.run -cui -nm -w -f $FILE &
495sleep 5
496ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
497
498 
[fdad5a6]499
500#Preparando instruccion tipo windows
501cat > $FILE <<EOF
502boot_disk=$DISK
503boot_main_part=$PART
504disk=$DISK
505main_part=$PART
506boot_entry=$WINVER
507EOF
[5fde4bc]508spartlnx.run -cui -nm -w -f $FILE &
509sleep 5
510ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
511
[fdad5a6]512
[250742d]513##Preparando instruccion        Ramdisk Options
[5fde4bc]514cat > $FILE <<EOF
515boot_disk=$DISK
516boot_main_part=$PART
517disk=$DISK
518main_part=$PART
519boot_entry=Ramdisk Options
520EOF
521spartlnx.run -cui -nm -w -f $FILE &
522sleep 5
523ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
524
[fdad5a6]525
526#Preparando instruccion Windows Boot Manager
527cat > $FILE <<EOF
528boot_disk=$DISK
529boot_main_part=$PART
530disk=$DISK
531main_part=$PART
532boot_entry=Windows Boot Manager
533EOF
[5fde4bc]534spartlnx.run -cui -nm -w -f $FILE &
535sleep 5
536ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
537
[fdad5a6]538
539#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
[5fde4bc]540cat > $FILE <<EOF
541boot_disk=$DISK
542boot_main_part=$PART
543disk=$DISK
544main_part=$PART
545boot_entry=Herramienta de diagnóstico de memoria de Windows
546EOF
547spartlnx.run -cui -nm -w -f $FILE &
548sleep 5
549ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
[fdad5a6]550
551}
[3915005]552
[fdad5a6]553
[78b5dfe7]554#         ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition
[fdad5a6]555#@brief   Registra una partición en windows con un determinado volumen.
556#@param   int_ndisk      nº de orden del disco a registrar
557#@param   int_partition     nº de particion a registrar
558#@param   str_volumen      volumen a resgistar
559#@param   int_ndisk_windows      nº de orden del disco donde esta windows
560#@param   int_partition_windows     nº de particion donde esta windows
561#@return 
562#@exception OG_ERR_FORMAT    Formato incorrecto.
563#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[3915005]564#@version 0.9 - Adaptación a OpenGnSys.
[fdad5a6]565#@author  Antonio J. Doblas Viso. Universidad de Málaga
566#@date    2009-09-24
567#*/ ##
[78b5dfe7]568function ogWindowsRegisterPartition ()
[3915005]569{
[fdad5a6]570# Variables locales.
[3915005]571local PART DISK FILE REGISTREDDISK REGISTREDPART REGISTREDVOL VERSION SYSTEMROOT
[fdad5a6]572
573# Si se solicita, mostrar ayuda.
574if [ "$*" == "help" ]; then
575    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
576           "$FUNCNAME 1 1 c: 1 1"
577    return
578fi
579
580# Error si no se reciben 5 parámetros.
581[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
582
583REGISTREDDISK=$1
584REGISTREDPART=$2
585REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
586DISK=$4
587PART=$5
[3915005]588FILE=/tmp/temp$$
[fdad5a6]589
590ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
591ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
592
593ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
594
595VERSION=$(ogGetOsVersion $DISK $PART)
596
597#Systemroot
598
599if ogGetPath $DISK $PART WINDOWS
600then
601        SYSTEMROOT="Windows"
602elif ogGetPath $DISK $PART WINNT
603then
604        SYSTEMROOT="winnt"
605else
606        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
607fi
608
609ogUnmount $DISK $PART
610let DISK=$DISK-1
611let REGISTREDDISK=$REGISTREDDISK-1
612#Preparando instruccion Windows Boot Manager
613cat > $FILE <<EOF
614windows_disk=$DISK
615windows_main_part=$PART
616windows_dir=$SYSTEMROOT
617disk=$REGISTREDDISK
618main_part=$REGISTREDPART
619;ext_part
620part_letter=$REGISTREDVOL
621EOF
[5fde4bc]622spartlnx.run -cui -nm -u -f $FILE &
623sleep 5
624ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
625
[e0c0d93]626}
[ab82469]627
628
[9c535e0]629#         ogGrubInstallMbr  int_disk_GRUBCFG  int_partition_GRUBCFG #@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
[a4b1e2a]630#@brief   Instala y actualiza el gestor grub el el MBR del disco duro donde se encuentra el fichero grub.cfg. Admite sistemas Windows.
[9c535e0]631#@param   int_disk_SecondStage     
632#@param   int_part_SecondStage     
633#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
[ab82469]634#@return 
635#@exception OG_ERR_FORMAT    Formato incorrecto.
636#@version 1.0.2 - Primeras pruebas.
637#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
638#@date    2011-10-29
[9c535e0]639#@version 1.0.3 - Soporte para linux de 32 y 64 bits
640#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
641#@date    2012-03-13
642#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la primera etapa
643#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
644#@date    2012-03-13
[ab82469]645#*/ ##
646
[9c535e0]647function ogGrubInstallMbr {
[ab82469]648
649# Variables locales.
[1c69be8]650local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[ab82469]651
652# Si se solicita, mostrar ayuda.
653if [ "$*" == "help" ]; then
[9c535e0]654    ogHelp "$FUNCNAME" "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \"  " \
655           "$FUNCNAME 1 1 FALSE " \
656           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
[ab82469]657    return
[9c535e0]658fi 
[ab82469]659
660# Error si no se reciben 2 parámetros.
[9c535e0]661[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
[ab82469]662
663
[9c535e0]664DISK=$1; PART=$2;
665CHECKOS=${3:-"FALSE"}
666KERNELPARAM=$4
[1c69be8]667BACKUPNAME=".backup.og"
[ab82469]668
[9c535e0]669#Error si no es linux.
670#TODO: comprobar si se puede utilizar la particion windows como contenedor de grub.
[a4b1e2a]671#VERSION=$(ogGetOsVersion $DISK $PART)
672#echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
[ab82469]673
[9c535e0]674#Localizar primera etapa del grub
675FIRSTSTAGE=$(ogDiskToDev $DISK)
[ab82469]676
[9c535e0]677#localizar disco segunda etapa del grub
678SECONDSTAGE=$(ogMount $DISK $PART)
[ab82469]679
[a4b1e2a]680# prepara el directorio principal de la segunda etapa
681[ -d ${SECONDSTAGE}/boot/grub/ ]  || mkdir -p ${SECONDSTAGE}/boot/grub/
682
[9c535e0]683#Localizar directorio segunda etapa del grub   
684PREFIXSECONDSTAGE="/boot/grubMBR"
[ab82469]685
[9c535e0]686# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]687if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]688then
689    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
690    then
[1c69be8]691        # Si no se reconfigura se utiliza el grub.cfg orginal
692        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
693                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
694        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
695        # Reactivamos el grub con el grub.cfg original.
[9c535e0]696        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
697        return $?
698    fi
699fi
700
701# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
702#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
703echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
704echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
[ab82469]705
[9c535e0]706#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup
[1c69be8]707[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]708
709#Preparar configuración segunda etapa: crear ubicacion
710mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
711#Preparar configuración segunda etapa: crear cabecera del fichero
712/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
713#Preparar configuración segunda etapa: crear entrada del sistema operativo
714grubSyntax "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
715
716#Instalar el grub
717grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
718}
[ab82469]719
720
721
[9c535e0]722#         ogGrubInstallPartition int_disk_SECONDSTAGE  int_partition_SECONDSTAGE bolean_Check_Os_installed_and_Configure_2ndStage
723#@brief   Instala y actualiza el gestor grub en el bootsector de la particion indicada
724#@param   int_disk_SecondStage     
725#@param   int_part_SecondStage     
726#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
727#@param   str "kernel param "   
728#@return 
729#@exception OG_ERR_FORMAT    Formato incorrecto.
730#@version 1.0.2 - Primeras pruebas.
731#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
732#@date    2011-10-29
733#@version 1.0.3 - Soporte para linux de 32 y 64 bits
734#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
735#@date    2012-03-13
736#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la priemra etapa
737#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
738#@date    2012-03-13
739#*/ ##
[ab82469]740
[9c535e0]741function ogGrubInstallPartition {
[ab82469]742
[9c535e0]743# Variables locales.
[1c69be8]744local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
[9c535e0]745
746# Si se solicita, mostrar ayuda.
747if [ "$*" == "help" ]; then
748    ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \" " \
749           "$FUNCNAME 1 1 FALSE " \
750           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
751    return
752fi 
753
754# Error si no se reciben 2 parámetros.
755[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
756
757DISK=$1; PART=$2;
758CHECKOS=${3:-"FALSE"}
759KERNELPARAM=$4
[1c69be8]760BACKUPNAME=".backup.og"
[9c535e0]761
762#error si no es linux.
763VERSION=$(ogGetOsVersion $DISK $PART)
764echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
765
766#Localizar primera etapa del grub
767FIRSTSTAGE=$(ogDiskToDev $DISK $PART)
768
769#localizar disco segunda etapa del grub
770SECONDSTAGE=$(ogMount $DISK $PART)
771
772#Localizar directorio segunda etapa del grub   
773PREFIXSECONDSTAGE="/boot/grubPARTITION"
774
775# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
[1c69be8]776if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
[9c535e0]777then
778    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
779    then
[1c69be8]780        # Si no se reconfigura se utiliza el grub.cfg orginal
781        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
782                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
783        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
784        # Reactivamos el grub con el grub.cfg original.
[9c535e0]785        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
786        return $?
787    fi
788fi
789
790# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
791#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
792echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
793echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
794
[1c69be8]795#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup.og
796[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
[9c535e0]797
798#Preparar configuración segunda etapa: crear ubicacion
799mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
800#Preparar configuración segunda etapa: crear cabecera del fichero
801/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
802#Preparar configuración segunda etapa: crear entrada del sistema operativo
803grubSyntax $DISK $PART "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
804
805#Instalar el grub
806grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
[ab82469]807}
808
[00cede9]809###
810#En pruebas
811##
812#/**
[c9c2f1d1]813#         ogConfigureFstab int_ndisk int_nfilesys
[00cede9]814#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
815#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]816#@param   int_nfilesys   nº de orden del sistema de archivos
[00cede9]817#@return  (nada)
818#@exception OG_ERR_FORMAT    Formato incorrecto.
[c9c2f1d1]819#@exception OG_ERR_NOTFOUND  No se encuentra el fichero fstab a procesar.
820#@warning Puede haber un error si hay más de 1 partición swap.
821#@version 1.0.5 - Primera versión para OpenGnSys.
822#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
823#@date    2013-03-21
[00cede9]824#*/ ##
825function ogConfigureFstab {
826# Variables locales.
[c9c2f1d1]827local FSTAB DEFROOT PARTROOT DEFSWAP PARTSWAP
[00cede9]828
829# Si se solicita, mostrar ayuda.
830if [ "$*" == "help" ]; then
[c9c2f1d1]831    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
832           "$FUNCNAME 1 1"
[00cede9]833    return
834fi
835# Error si no se reciben 2 parámetros.
836[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[c9c2f1d1]837# Error si no se encuentra un fichero  etc/fstab  en el sistema de archivos.
838FSTAB=$(ogGetPath $1 $2 /etc/fstab) 2>/dev/null
839[ -n "$FSTAB" ] || ogRaiseError $OG_ERR_NOTFOUND "$1,$2,/etc/fstab" || return $?
840
841# Hacer copia de seguridad del fichero fstab original.
842cp -a ${FSTAB} ${FSTAB}.backup
843# Dispositivo del raíz en fichero fstab: 1er campo (si no tiene "#") con 2º campo = "/".
844DEFROOT=$(awk '$1!~/#/ && $2=="/" {print $1}' ${FSTAB})
845PARTROOT=$(ogDiskToDev $1 $2)
[200635a]846# Configuración de swap (solo 1ª partición detectada).
847PARTSWAP=$(blkid -t TYPE=swap | awk -F: 'NR==1 {print $1}')
[00cede9]848if [ -n "$PARTSWAP" ]
849then
[c9c2f1d1]850    # Dispositivo de swap en fichero fstab: 1er campo (si no tiene "#") con 3er campo = "swap".
851    DEFSWAP=$(awk '$1!~/#/ && $3=="swap" {print $1}' ${FSTAB})
[00cede9]852    if [ -n "$DEFSWAP" ]
[c9c2f1d1]853    then
854        echo "Hay definicion de swap en el fstab $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP"   # Mensaje temporal.
855        sed "s|$DEFSWAP|$PARTSWAP|g ; s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
[00cede9]856    else
[c9c2f1d1]857        echo "No hay definicion de swap y si hay partición swap -> moficamos fichero"   # Mensaje temporal.
858        sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
859        echo "$PARTSWAP  none    swap    sw   0  0" >> ${FSTAB}
[00cede9]860    fi 
861else
[c9c2f1d1]862    echo "No hay partición swap -> configuramos fstba"  # Mensaje temporal.
863    sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
[00cede9]864fi
865}
[9c535e0]866
[c9c2f1d1]867
[764f50e]868###
869#En pruebas
870##
871#/**
[c9c2f1d1]872#         ogSetLinuxName int_ndisk int_nfilesys [str_name]
[764f50e]873#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
874#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]875#@param   int_nfilesys   nº de orden del sistema de archivos
876#@param   str_name       nombre asignado (opcional)
[764f50e]877#@return  (nada)
878#@exception OG_ERR_FORMAT    Formato incorrecto.
879#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
880#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]881#@note    Si no se indica nombre, se asigna un valor por defecto.
882#@version 1.0.5 - Primera versión para OpenGnSys.
883#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
884#@date    2013-03-21
[764f50e]885#*/ ##
886function ogSetLinuxName ()
887{
888# Variables locales.
[c9c2f1d1]889local MNTDIR ETC NAME
[764f50e]890
891# Si se solicita, mostrar ayuda.
892if [ "$*" == "help" ]; then
[c9c2f1d1]893    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_name]" \
894           "$FUNCNAME 1 1" "$FUNCNAME 1 1 practica-pc"
[764f50e]895    return
896fi
[c9c2f1d1]897# Error si no se reciben 2 o 3 parámetros.
898case $# in
899    2)   # Asignar nombre automático (por defecto, "pc").
900         NAME="$(ogGetHostname)"
901         NAME=${NAME:-"pc"} ;;
902    3)   # Asignar nombre del 3er parámetro.
903         NAME="$3" ;;
904    *)   # Formato de ejecución incorrecto.
905         ogRaiseError $OG_ERR_FORMAT
906         return $?
907esac
[764f50e]908
909# Montar el sistema de archivos.
910MNTDIR=$(ogMount $1 $2) 2>/dev/null
911[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
912
913ETC=$(ogGetPath $1 $2 /etc)
914
915if [ -d "$ETC" ]; then
916        #cambio de nombre en hostname
[c9c2f1d1]917        echo "$NAME" > $ETC/hostname
[764f50e]918        #Opcion A para cambio de nombre en hosts
919        #sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts
[c9c2f1d1]920        #Opcion B componer fichero de hosts
921        cat > $ETC/hosts <<EOF
[764f50e]922127.0.0.1       localhost
923127.0.1.1       $NAME
924
925# The following lines are desirable for IPv6 capable hosts
926::1     ip6-localhost ip6-loopback
927fe00::0 ip6-localnet
928ff00::0 ip6-mcastprefix
929ff02::1 ip6-allnodes
930ff02::2 ip6-allrouters
931EOF
932fi
933}
934
[df814dd0]935
936###
937#En pruebas
938##
939#/**
[c9c2f1d1]940#         ogCleanLinuxDevices int_ndisk int_nfilesys
[df814dd0]941#@brief   Limpia los dispositivos del equipo de referencia. Interfaz de red ...
942#@param   int_ndisk      nº de orden del disco
[c9c2f1d1]943#@param   int_nfilesys   nº de orden del sistema de archivos
[df814dd0]944#@return  (nada)
945#@exception OG_ERR_FORMAT    Formato incorrecto.
946#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
947#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[c9c2f1d1]948#@version 1.0.5 - Primera versión para OpenGnSys.
949#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
950#@date    2013-03-21
[df814dd0]951#*/ ##
952function ogCleanLinuxDevices ()
953{
954# Variables locales.
[c9c2f1d1]955local MNTDIR
[df814dd0]956
957# Si se solicita, mostrar ayuda.
958if [ "$*" == "help" ]; then
[c9c2f1d1]959    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
960           "$FUNCNAME 1 1"
[df814dd0]961    return
962fi
963# Error si no se reciben 2 parámetros.
964[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
965
966# Montar el sistema de archivos.
967MNTDIR=$(ogMount $1 $2) 2>/dev/null
968[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
969
[c9c2f1d1]970# Eliminar fichero de configuración de udev para dispositivos fijos de red.
[e825eca]971rm -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules
[df814dd0]972}
973
Note: See TracBrowser for help on using the repository browser.