source: client/engine/Boot.lib @ c2b03eb

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 c2b03eb was 8964f9b, checked in by ramon <ramongomez@…>, 16 years ago

Resstructuración de trunk.

git-svn-id: https://opengnsys.es/svn/trunk@390 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 12.8 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.
7#@version 0.9
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.
15#@arg  \c ndisk      nº de orden del disco
16#@arg  \c npartition nº de orden de la partición
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.
22#@warning Primeras pruebas.
[4c63eb9]23#@todo    Revisar parámetros de arranque en Windows y Linux.
[b094c59]24#@version 0.1 - Primera adaptación para OpenGNSys.
25#@author  Ramon Gomez, ETSII Universidad de Sevilla
26#@date    2009-09-11
27#*/
28function ogBoot () {
29
30# Variables locales.
[326cec3]31local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER
[b094c59]32
33#/// Si se solicita, mostrar ayuda.
34if [ "$*" == "help" ]; then
35    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
36           "$FUNCNAME 1 1"
37    return
38fi
39#/// Error si no se reciben 2 parámetros.
40[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
41
[4c63eb9]42#/// Detectar tipo de sistema de archivos y montarlo.
[b094c59]43TYPE=$(ogGetFsType $1 $2) || return $?
[4c63eb9]44MNTDIR=$(ogMount $1 $2)
45[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION && return $?
[b094c59]46
47case "$TYPE" in
[4c63eb9]48     EXT[234]|REISERFS|REISER4)
49        #/// Obtiene los parámetros de arranque para Linux.
[b094c59]50        PARAMS=$(ogLinuxBootParameters $1 $2) || return $?
51        read -e KERNEL INITRD APPEND <<<"$PARAMS"
52        # Si no hay kernel, no hay sistema operativo.
53        [ -z "$KERNEL" ] && ogRaiseError $OG_ERR_NOTOS && return $?
[4c63eb9]54        # Configurar kernel Linux con los parámetros leidos de su GRUB.
[b094c59]55        kexec -l ${MNTDIR}${KERNEL} --append="$APPEND" --initrd=${MNTDIR}${INITRD}
56        ;;
[326cec3]57     NTFS|HNTFS|FAT32|HFAT32)
58        #/// Compruebar si hay un cargador de Windows.
59        for f in io.sys ntldr bootmgr; do
60            FILE="$(ogGetPath $1 $2 $f 2>/dev/null)"
61            [ -n "$FILE" ] && LOADER="$(basename $FILE)"
62        done
63        [ -z "$LOADER" ] && ogRaiseError $OG_ERR_NOTOS && return $?
64        # Activar la partición y copiar Grub4DOS.
65        ogSetPartitionActive $1 $2
[89403cd]66        cp $OGLIB/grub4dos/* $MNTDIR    # */ (necesario para Doxygen)
[326cec3]67        kexec -l $MNTDIR/grub.exe --append=--config-file="find --set-root /$LOADER; chainloader /$LOADER; tpm --init"
68        ;;
[b094c59]69     *) ogRaiseError $OG_ERR_PARTITION
[326cec3]70        return $?
[b094c59]71        ;;
72esac
73
[4c63eb9]74#/// Arrancar.
[b094c59]75kexec -e
76}
77
78
79#/**
[3e1561d]80#         ogGetRegistryValue path_mountpoint str_registrytype str_valuename
81#@brief   Devuelve el dato de un valor del registro de Windows.
[055adcf]82#@arg  \c mountpoint   directorio donde está montado el sistema Windows
83#@arg  \c registrytype tipo de registro a leer
[3e1561d]84#@arg  \c valuename    valor de registro
85#@return  str_valuedata - valor de la clave.
[055adcf]86#@exception OG_ERR_FORMAT    Formato incorrecto.
87#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
88#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
89#@note    registrytype = { default, sam, security, software, system, components }
90#@warning Requisitos: chntpw, awk
91#@warning La partición de Windows debe estar montada previamente.
92#@version 0.9 - Primera adaptación para OpenGNSys.
93#@author  Ramon Gomez, ETSII Universidad de Sevilla
94#@date    2009-09-11
95#*/
[3e1561d]96function ogGetRegistryValue () {
[055adcf]97
98# Variables locales.
[50a094c]99local FILE FILENT FILEXP
[055adcf]100
101#/// Si se solicita, mostrar ayuda.
102if [ "$*" == "help" ]; then
103    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
104    return
105fi
106#/// Error si no se reciben 3 parámetros.
107[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
108
109#/// Camino del fichero de registro en NT/2000 o XP/Vista/7.
110FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]111[ -f $FILENT ] && FILE="$FILENT"
[055adcf]112FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]113[ -f $FLEHXP ] && FILE="$FILEXP"
[055adcf]114[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
115
[3e1561d]116#/// Devolver el dato del valor de registro.
[055adcf]117chntpw $FILE << FIN 2>/dev/null | awk '/> Value/ {getline;print $0;}'
118cd ${3%\\*}
119cat ${3##*\\}
120q
121FIN
122}
123
124
125#/**
[3e1561d]126#         ogGetWindowsName int_ndisk int_npartition
127#@brief   Muestra el nombre del equipo en el registro de Windows.
128#@arg  \c ndisk      nº de orden del disco
129#@arg  \c npartition nº de orden de la partición
130#@return  str_name - nombre del equipo
131#@exception OG_ERR_FORMAT    Formato incorrecto.
132#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
133#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
134#@version 0.1 - Primera adaptación para OpenGNSys.
135#@author  Ramon Gomez, ETSII Universidad de Sevilla
136#@date    2009-09-23
137#*/
138function ogGetWindowsName () {
139
140# Variables locales.
141local PART MNTDIR
142
143#/// Si se solicita, mostrar ayuda.
144if [ "$*" == "help" ]; then
145    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
146           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
147    return
148fi
149#/// Error si no se reciben 2 parámetros.
150[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
151
152#/// Montar el sistema de archivos.
153MNTDIR=$(ogMount $1 $2) || return $?
154[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1,$2" && return $?
155
156#/// Obtener dato del valor de registro.
157ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
158}
159
160
161#/**
[50a094c]162#         ogListRegistryKeys path_mountpoint str_registrytype str_key
[3e1561d]163#@brief   Lista los nombres de claves de una determinada clave del registro de Windows.
[50a094c]164#@arg  \c mountpoint   directorio donde está montado el sistema Windows
165#@arg  \c registrytype tipo de registro a leer
166#@arg  \c key          clave de registro
[945b003]167#@return
[50a094c]168#@exception OG_ERR_FORMAT    Formato incorrecto.
169#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
170#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
171#@note    registrytype = { default, sam, security, software, system, components }
172#@warning Requisitos: chntpw, awk
173#@warning La partición de Windows debe estar montada previamente.
174#@version 0.9 - Primera adaptación para OpenGNSys.
175#@author  Ramon Gomez, ETSII Universidad de Sevilla
176#@date    2009-09-23
177#*/
178function ogListRegistryKeys () {
179
180# Variables locales.
181local FILE FILENT FILEXP
182
183#/// Si se solicita, mostrar ayuda.
184if [ "$*" == "help" ]; then
185    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
186    return
187fi
188#/// Error si no se reciben 3 parámetros.
189[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
190
191#/// Camino del fichero de registro en NT/2000 o XP/Vista/7.
192FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]193[ -f $FILENT ] && FILE="$FILENT"
[50a094c]194FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]195[ -f $FLEHXP ] && FILE="$FILEXP"
[50a094c]196[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
197
198#/// Devolver la lista de claves de registro.
199chntpw $FILE << FIN 2>/dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}'
200ls $3
201q
202FIN
203}
204
205
206#/**
[4c63eb9]207#         ogLinuxBootParameters int_ndisk int_npartition
[b094c59]208#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
209#@arg  \c ndisk      nº de orden del disco
210#@arg  \c npartition nº de orden de la partición
211#@return  kernel initrd parámetros ...
212#@exception OG_ERR_FORMAT    Formato incorrecto.
213#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
214#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[055adcf]215#@warning Función básica usada por \c ogBoot
216#@version 0.9 - Primera adaptación para OpenGNSys.
[b094c59]217#@author  Ramon Gomez, ETSII Universidad de Sevilla
218#@date    2009-09-11
219#*/
220function ogLinuxBootParameters () {
221
222# Variables locales.
[4c63eb9]223local MNTDIR CONF
[b094c59]224
225#/// Si se solicita, mostrar ayuda.
226if [ "$*" == "help" ]; then
227    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
228           "$FUNCNAME 1 2  ==>  ..."
229    return
230fi
231#/// Error si no se reciben 2 parámetros.
232[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
233
234#/// Detectar id. de tipo de partición y codificar al mnemonico.
[4c63eb9]235MNTDIR=$(ogMount $1 $2) || return $?
236[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION && return $?
[b094c59]237
238# Fichero de configuración de GRUB.
239CONF="$MNTDIR/boot/grub/menu.lst"
[ee4a96e]240[ ! -e $CONF ] && CONF="$MNTDIR/boot/grub/grub.cfg"
241[ ! -e $CONF ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
[b094c59]242
[4c63eb9]243#/** Toma del fichero de configuracion los valores del kernel, initrd
[ee4a96e]244#       y parámetros de arranque usando las cláusulas por defecto
245#       ("default" en GRUB1, "set default" en GRUB2)
246#       y los formatea para que sean compatibles con \c kexec .  */
[3d0750f]247#/* (ncesario para Doxygen)
[b094c59]248awk 'BEGIN {cont=-1;}
249     $1~/^default/      {sub(/=/," "); def=$2;}
[18f4bc2]250     $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;}
[ee4a96e]251     $1~/^title|^menuentry/ {cont++}
252     $1~/^kernel|^linux/ {if (def==cont) {
[b094c59]253                            kern=$2;
[c56dec5]254                            sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}
[b094c59]255                        }
256     $1~/^initrd/       {if (def==cont) init=$2}
257     END {if (kern!="") printf("%s %s %s", kern,init,app)}
258    ' $CONF
259}
260
[3e1561d]261
262
263#/**
264#         ogSetRegistryValue path_mountpoint str_registrytype str_valuename str_valuedata
265#@brief   Establece el dato asociado a un valor del registro de Windows.
266#@arg  \c mountpoint   directorio donde está montado el sistema Windows
267#@arg  \c registrytype tipo de registro
268#@arg  \c valuename    nombre del valor de registro
269#@arg  \c valuedata    dato del valor de registro
270#@return  (nada)
271#@exception OG_ERR_FORMAT    Formato incorrecto.
272#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
273#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
274#@note    registrytype = { default, sam, security, software, system, components }
275#@warning Requisitos: chntpw, awk
276#@warning La partición de Windows debe estar montada previamente.
277#@version 0.9 - Primera adaptación para OpenGNSys.
278#@author  Ramon Gomez, ETSII Universidad de Sevilla
279#@date    2009-09-24
280#*/
281function ogSetRegistryValue () {
282
283# Variables locales.
284local FILE FILENT FILEXP
285
286#/// Si se solicita, mostrar ayuda.
287if [ "$*" == "help" ]; then
288    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
289    return
290fi
291#/// Error si no se reciben 4 parámetros.
292[ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
293
294#/// Camino del fichero de registro en NT/2000 o XP/Vista/7.
295FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]296[ -f $FILENT ] && FILE="$FILENT"
[3e1561d]297FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]298[ -f $FLEHXP ] && FILE="$FILEXP"
[3e1561d]299[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
300
301#/// Cambiar el dato del valor de registro.
302chntpw $FILE << FIN 2>/dev/null
303ed $3
304$4
305q
306y
307FIN
308}
309
310
311#/**
312#         ogSetWindowsName int_ndisk int_npartition str_name
313#@brief   Establece el nombre del equipo en el registro de Windows.
314#@arg  \c ndisk      nº de orden del disco
315#@arg  \c npartition nº de orden de la partición
316#@arg  \c name       nombre asignado
317#@return  (nada)
318#@exception OG_ERR_FORMAT    Formato incorrecto.
319#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
320#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
321#@version 0.1 - Primera adaptación para OpenGNSys.
322#@author  Ramon Gomez, ETSII Universidad de Sevilla
323#@date    2009-09-24
324#*/
325function ogSetWindowsName () {
326
327# Variables locales.
328local PART MNTDIR NAME
329
330#/// Si se solicita, mostrar ayuda.
331if [ "$*" == "help" ]; then
332    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
333           "$FUNCNAME 1 1 PRACTICA-PC"
334    return
335fi
336#/// Error si no se reciben 3 parámetros.
337[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
338
339#/// Montar el sistema de archivos.
340MNTDIR=$(ogMount $1 $2) || return $?
341[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1,$2" && return $?
342NAME="$3"
343
344#/// Modificar datos de los valores de registro.
345ogSetRegistryKey $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME"
346ogSetRegistryKey $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME"
347ogSetRegistryKey $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME"
348}
349
[a781d7b]350function ogNewMbrXP () {
[945b003]351#/**  @function NewMbrXP: @brief Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
352#@param  $1 obligatorio   int_numdisk
353#@return  salida del programa my-sys
354#@warning    no definidos
355#@attention Requisitos:  my-sys, compilado ubicado en /var/EAC/admin/source
356#@note
357#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
358#*/
359#
360if [ $# = 0 ]
361then
362        Msg "sintaxis: ogNewMbrXP int_disco " red
363return
364fi
365if [ $# = 1 ]
366then
367        particion=`ogDiskToDev $1`
368        ms-sys -z -f $particion
369        ms-sys -m -f $particion
370fi
371}
Note: See TracBrowser for help on using the repository browser.