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