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 | #@version 1.1.1 - UEFI: Permite iniciar linux recien instalados (ticket #802 #890) |
---|
41 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
42 | #@date 2019-03-13 |
---|
43 | #*/ ## |
---|
44 | function ogBoot () |
---|
45 | { |
---|
46 | # Variables locales. |
---|
47 | local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER f |
---|
48 | local EFIDISK EFIPART EFIDIR BOOTLABEL BOOTLOADER BOOTNO DIRGRUB b |
---|
49 | |
---|
50 | # Si se solicita, mostrar ayuda. |
---|
51 | if [ "$*" == "help" ]; then |
---|
52 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_kernel str_initrd str_kernelparams]" \ |
---|
53 | "$FUNCNAME 1 1" "$FUNCNAME 1 2 \"/boot/vmlinuz /boot/initrd.img root=/dev/sda2 ro\"" |
---|
54 | return |
---|
55 | fi |
---|
56 | # Error si no se reciben 2 o 3 parámetros. |
---|
57 | [ $# == 2 ] || [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
58 | |
---|
59 | # Detectar tipo de sistema de archivos y montarlo. |
---|
60 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
61 | TYPE=$(ogGetOsType $1 $2) || return $? |
---|
62 | # Error si no puede montar sistema de archivos. |
---|
63 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
64 | |
---|
65 | case "$TYPE" in |
---|
66 | Linux|Android) |
---|
67 | # Si no se indican, obtiene los parámetros de arranque para Linux. |
---|
68 | PARAMS="${3:-$(ogLinuxBootParameters $1 $2 2>/dev/null)}" |
---|
69 | # Si no existe y el UEFI buscar en particion ESP |
---|
70 | [ -z "$PARAMS" ] && ogIsEfiActive && PARAMS="$(ogLinuxBootParameters $(ogGetEsp))" |
---|
71 | # Si no existe, buscar sistema de archivo /boot en /etc/fstab. |
---|
72 | if [ -z "$PARAMS" -a -e $MNTDIR/etc/fstab ]; then |
---|
73 | # Localizar S.F. /boot en /etc/fstab del S.F. actual. |
---|
74 | PART=$(ogDevToDisk $(awk '$1!="#" && $2=="/boot" {print $1}' $MNTDIR/etc/fstab)) |
---|
75 | # Montar S.F. de /boot. |
---|
76 | MNTDIR=$(ogMount $PART) || return $? |
---|
77 | # Buscar los datos de arranque. |
---|
78 | PARAMS=$(ogLinuxBootParameters $PART) || exit $? |
---|
79 | fi |
---|
80 | read -e KERNEL INITRD APPEND <<<"$PARAMS" |
---|
81 | # Si no hay kernel, no hay sistema operativo. |
---|
82 | [ -n "$KERNEL" -a -e "$MNTDIR/$KERNEL" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE)" || return $? |
---|
83 | # Arrancar de partición distinta a la original. |
---|
84 | [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}') |
---|
85 | # Comprobar tipo de sistema. |
---|
86 | if ogIsEfiActive; then |
---|
87 | # Comprobar si el Kernel está firmado. |
---|
88 | if ! file -k "$MNTDIR/$KERNEL" | grep -q "EFI app"; then |
---|
89 | ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE, EFI)" |
---|
90 | return $? |
---|
91 | fi |
---|
92 | |
---|
93 | BOOTLABEL=$(printf "Part-%02d-%02d" $1 $2) |
---|
94 | BOOTLOADER="shimx64.efi" |
---|
95 | # Obtener parcición EFI. |
---|
96 | read -e EFIDISK EFIPART <<<"$(ogGetEsp)" |
---|
97 | # TODO: Comprobamos que existe la BOOTLABEL, si no buscamos por sistema operativo |
---|
98 | if [ "$(ogGetPath $EFIDISK $EFIPART EFI/$BOOTLABEL)" == "" ]; then |
---|
99 | OSVERSION="$(ogGetOsVersion $1 $2)" |
---|
100 | case $OSVERSION in |
---|
101 | *SUSE*) |
---|
102 | BOOTLABEL="opensuse" |
---|
103 | ;; |
---|
104 | *Fedora*) |
---|
105 | BOOTLABEL="fedora" |
---|
106 | ;; |
---|
107 | *Ubuntu*) |
---|
108 | BOOTLABEL="ubuntu" |
---|
109 | ;; |
---|
110 | *) |
---|
111 | ogRaiseError $OG_ERR_NOTFOUND "$EFIDISK $EFIPART Boot loader"; return $? |
---|
112 | ;; |
---|
113 | esac |
---|
114 | fi |
---|
115 | |
---|
116 | # Crear orden de arranque (con unos valores por defecto). |
---|
117 | ogNvramAddEntry $BOOTLABEL "/EFI/$BOOTLABEL/Boot/$BOOTLOADER" |
---|
118 | # Marcar próximo arranque y reiniciar. |
---|
119 | ogNvramSetNext "$BOOTLABEL" |
---|
120 | reboot |
---|
121 | else |
---|
122 | # Arranque BIOS: configurar kernel Linux con los parámetros leídos de su GRUB. |
---|
123 | kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}" |
---|
124 | nohup bash -c 'sleep 2 && pkill ogclient' >/dev/null 2>&1 & |
---|
125 | nohup bash -c 'sleep 3 && kexec -e' >/dev/null 2>&1 & |
---|
126 | fi |
---|
127 | ;; |
---|
128 | Windows) |
---|
129 | # Comprobar tipo de sistema. |
---|
130 | if ogIsEfiActive; then |
---|
131 | BOOTLABEL=$(printf "Part-%02d-%02d" $1 $2) |
---|
132 | # Obtener parcición EFI. |
---|
133 | read -e EFIDISK EFIPART <<<"$(ogGetEsp)" |
---|
134 | [ -n "$EFIPART" ] || ogRaiseError $OG_ERR_PARTITION "ESP" || return $? |
---|
135 | EFIDIR=$(ogMount $EFIDISK $EFIPART) || exit $? |
---|
136 | # Comprobar cargador (si no existe buscar por defecto en ESP). |
---|
137 | LOADER=$(ogGetPath $EFIDIR/EFI/$BOOTLABEL/Boot/bootmgfw.efi) |
---|
138 | [ -z "$LOADER" ] && BOOTLABEL=Microsoft && LOADER=$(ogGetPath $EFIDIR/EFI/Microsoft/Boot/bootmgfw.efi) |
---|
139 | [ -n "$LOADER" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE, EFI)" || return $? |
---|
140 | |
---|
141 | # Crear orden de arranque (con unos valores por defecto). |
---|
142 | ogNvramAddEntry $BOOTLABEL "/EFI${LOADER#*EFI}" |
---|
143 | # Marcar próximo arranque y reiniciar. |
---|
144 | ogNvramSetNext "$BOOTLABEL" |
---|
145 | reboot |
---|
146 | else |
---|
147 | # Arranque BIOS: comprueba si hay un cargador de Windows. |
---|
148 | for f in io.sys ntldr bootmgr; do |
---|
149 | FILE="$(ogGetPath $1 $2 $f 2>/dev/null)" |
---|
150 | [ -n "$FILE" ] && LOADER="$f" |
---|
151 | done |
---|
152 | [ -n "$LOADER" ] || ogRaiseError $OG_ERR_NOTOS "$1 $2 ($TYPE)" || return $? |
---|
153 | if [ "$winboot" == "kexec" ]; then |
---|
154 | # Modo de arranque en caliente (con kexec). |
---|
155 | cp $OGLIB/grub4dos/* $MNTDIR # */ (Comentario Doxygen) |
---|
156 | kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init" |
---|
157 | nohup bash -c 'sleep 2 && pkill ogclient' >/dev/null 2>&1 & |
---|
158 | nohup bash -c 'sleep 3 && kexec -e' >/dev/null 2>&1 & |
---|
159 | else |
---|
160 | # Modo de arranque por reinicio (con reboot). |
---|
161 | dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3 |
---|
162 | dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3 |
---|
163 | dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3 |
---|
164 | if [ -z "$(ogGetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleannboot')" ]; then |
---|
165 | ogAddRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot' |
---|
166 | ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot' "cmd /c del c:\ogboot.*" |
---|
167 | fi |
---|
168 | # Activar la partición. |
---|
169 | ogSetPartitionActive $1 $2 |
---|
170 | reboot |
---|
171 | fi |
---|
172 | fi |
---|
173 | ;; |
---|
174 | MacOS) |
---|
175 | # Modo de arranque por reinicio. |
---|
176 | # Nota: el cliente tiene que tener configurado correctamente Grub. |
---|
177 | touch ${MNTDIR}/boot.mac &>/dev/null |
---|
178 | reboot |
---|
179 | ;; |
---|
180 | GrubLoader) |
---|
181 | # Reiniciar. |
---|
182 | #reboot |
---|
183 | ;; |
---|
184 | *) ogRaiseError $OG_ERR_NOTOS "$1 $2 ${TYPE:+($TYPE)}" |
---|
185 | return $? |
---|
186 | ;; |
---|
187 | esac |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | #/** |
---|
192 | # ogGetWindowsName int_ndisk int_nfilesys |
---|
193 | #@brief Muestra el nombre del equipo en el registro de Windows. |
---|
194 | #@param int_ndisk nº de orden del disco |
---|
195 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
196 | #@return str_name - nombre del equipo |
---|
197 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
198 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
199 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
200 | #@version 0.9 - Adaptación para OpenGnSys. |
---|
201 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
202 | #@date 2009-09-23 |
---|
203 | #*/ ## |
---|
204 | function ogGetWindowsName () |
---|
205 | { |
---|
206 | # Variables locales. |
---|
207 | local MNTDIR |
---|
208 | |
---|
209 | # Si se solicita, mostrar ayuda. |
---|
210 | if [ "$*" == "help" ]; then |
---|
211 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
212 | "$FUNCNAME 1 1 ==> PRACTICA-PC" |
---|
213 | return |
---|
214 | fi |
---|
215 | # Error si no se reciben 2 parámetros. |
---|
216 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
217 | |
---|
218 | # Montar el sistema de archivos. |
---|
219 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
220 | |
---|
221 | # Obtener dato del valor de registro. |
---|
222 | ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | #/** |
---|
227 | # ogLinuxBootParameters int_ndisk int_nfilesys |
---|
228 | #@brief Muestra los parámetros de arranque de un sistema de archivos Linux. |
---|
229 | #@param int_ndisk nº de orden del disco |
---|
230 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
231 | #@return str_kernel str_initrd str_parameters ... |
---|
232 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
233 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
234 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
235 | #@warning Función básica usada por \c ogBoot |
---|
236 | #@version 0.9 - Primera adaptación para OpenGnSys. |
---|
237 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
238 | #@date 2009-09-11 |
---|
239 | #@version 0.9.2 - Soporta partición /boot independiente. |
---|
240 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
241 | #@date 2010-07-20 |
---|
242 | #@version 1.0.5 - Mejoras en tratamiento de GRUB2. |
---|
243 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
244 | #@date 2013-05-14 |
---|
245 | #@version 1.0.6 - Detectar instalaciones sobre EFI. |
---|
246 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
247 | #@date 2014-09-15 |
---|
248 | #*/ ## |
---|
249 | function ogLinuxBootParameters () |
---|
250 | { |
---|
251 | # Variables locales. |
---|
252 | local MNTDIR CONFDIR CONFFILE f |
---|
253 | |
---|
254 | # Si se solicita, mostrar ayuda. |
---|
255 | if [ "$*" == "help" ]; then |
---|
256 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \ |
---|
257 | "$FUNCNAME 1 2 ==> /vmlinuz-3.5.0-21-generic /initrd.img-3.5.0-21-generic root=/dev/sda2 ro splash" |
---|
258 | return |
---|
259 | fi |
---|
260 | # Error si no se reciben 2 parámetros. |
---|
261 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
262 | |
---|
263 | # Detectar id. de tipo de partición y codificar al mnemonico. |
---|
264 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
265 | |
---|
266 | # Fichero de configuración de GRUB. |
---|
267 | CONFDIR=$MNTDIR # Sistema de archivos de arranque (/boot). |
---|
268 | [ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot # Sist. archivos raíz con directorio boot. |
---|
269 | for f in $MNTDIR/{,boot/}{{grubMBR,grubPARTITION}/boot/,}{grub{2,},{,efi/}EFI/*}/{menu.lst,grub.cfg}; do |
---|
270 | [ -r $f ] && CONFFILE=$f |
---|
271 | done |
---|
272 | [ -n "$CONFFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" || return $? |
---|
273 | |
---|
274 | # Toma del fichero de configuracion los valores del kernel, initrd |
---|
275 | # y parámetros de arranque usando las cláusulas por defecto |
---|
276 | # ("default" en GRUB1, "set default" en GRUB2) |
---|
277 | # y los formatea para que sean compatibles con \c kexec . */ |
---|
278 | # /* (comentario Doxygen) |
---|
279 | awk 'BEGIN {cont=-1;} |
---|
280 | $1~/^default$/ {sub(/=/," "); def=$2;} |
---|
281 | $1~/^set$/ && $2~/^default/ { gsub(/[="]/," "); def=$3; |
---|
282 | if (def ~ /saved_entry/) def=0; |
---|
283 | } |
---|
284 | $1~/^(title|menuentry)$/ {cont++} |
---|
285 | $1~/^set$/ && $2~/^root=.\(hd'$[1-1]',(msdos|gpt)'$2'\).$/ { if (def==0) def=cont; } |
---|
286 | $1~/^(kernel|linux(16|efi)?)$/ { if (def==cont) { |
---|
287 | kern=$2; |
---|
288 | sub($1,""); sub($1,""); sub(/^[ \t]*/,""); app=$0 |
---|
289 | } # /* (comentario Doxygen) |
---|
290 | } |
---|
291 | $1~/^initrd(16|efi)?$/ {if (def==cont) init=$2} |
---|
292 | END {if (kern!="") printf("%s %s %s", kern,init,app)} |
---|
293 | ' $CONFFILE |
---|
294 | # */ (comentario Doxygen) |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | #/** |
---|
299 | # ogSetWindowsName int_ndisk int_nfilesys str_name |
---|
300 | #@brief Establece el nombre del equipo en el registro de Windows. |
---|
301 | #@param int_ndisk nº de orden del disco |
---|
302 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
303 | #@param str_name nombre asignado |
---|
304 | #@return (nada) |
---|
305 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
306 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
307 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
308 | #@exception OG_ERR_OUTOFLIMIT Nombre Netbios con más de 15 caracteres. |
---|
309 | #@version 0.9 - Adaptación a OpenGnSys. |
---|
310 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
311 | #@date 2009-09-24 |
---|
312 | #@version 1.0.5 - Establecer restricción de tamaño de nombre Netbios. |
---|
313 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
314 | #@date 2013-03-20 |
---|
315 | #*/ ## |
---|
316 | function ogSetWindowsName () |
---|
317 | { |
---|
318 | # Variables locales. |
---|
319 | local PART MNTDIR NAME |
---|
320 | |
---|
321 | # Si se solicita, mostrar ayuda. |
---|
322 | if [ "$*" == "help" ]; then |
---|
323 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys str_name" \ |
---|
324 | "$FUNCNAME 1 1 PRACTICA-PC" |
---|
325 | return |
---|
326 | fi |
---|
327 | # Error si no se reciben 3 parámetros. |
---|
328 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
329 | # Error si el nombre supera los 15 caracteres. |
---|
330 | [ ${#3} -le 15 ] || ogRaiseError $OG_ERR_OUTOFLIMIT "\"${3:0:15}...\"" || return $? |
---|
331 | |
---|
332 | # Montar el sistema de archivos. |
---|
333 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
334 | |
---|
335 | # Asignar nombre. |
---|
336 | NAME="$3" |
---|
337 | |
---|
338 | # Modificar datos de los valores de registro. |
---|
339 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null |
---|
340 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null |
---|
341 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\HostName' "$NAME" 2>/dev/null |
---|
342 | ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null |
---|
343 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null |
---|
344 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV HostName' "$NAME" 2>/dev/null |
---|
345 | ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | #/** |
---|
350 | # ogSetWinlogonUser int_ndisk int_npartition str_username |
---|
351 | #@brief Establece el nombre de usuario por defecto en la entrada de Windows. |
---|
352 | #@param int_ndisk nº de orden del disco |
---|
353 | #@param int_npartition nº de orden de la partición |
---|
354 | #@param str_username nombre de usuario por defecto |
---|
355 | #@return (nada) |
---|
356 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
357 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
358 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
359 | #@version 0.9.2 - Adaptación a OpenGnSys. |
---|
360 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
361 | #@date 2010-07-20 |
---|
362 | #*/ ## |
---|
363 | function ogSetWinlogonUser () |
---|
364 | { |
---|
365 | # Variables locales. |
---|
366 | local PART MNTDIR NAME |
---|
367 | |
---|
368 | # Si se solicita, mostrar ayuda. |
---|
369 | if [ "$*" == "help" ]; then |
---|
370 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \ |
---|
371 | "$FUNCNAME 1 1 USUARIO" |
---|
372 | return |
---|
373 | fi |
---|
374 | # Error si no se reciben 3 parámetros. |
---|
375 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
376 | |
---|
377 | # Montar el sistema de archivos. |
---|
378 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
379 | |
---|
380 | # Asignar nombre. |
---|
381 | NAME="$3" |
---|
382 | |
---|
383 | # Modificar datos en el registro. |
---|
384 | ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3" |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | #/** |
---|
389 | # ogBootMbrXP int_ndisk |
---|
390 | #@brief Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows |
---|
391 | #@param int_ndisk nº de orden del disco |
---|
392 | #@return salida del programa my-sys |
---|
393 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
394 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
395 | #@version 0.9 - Adaptación a OpenGnSys. |
---|
396 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
397 | #@date 2009-09-24 |
---|
398 | #*/ ## |
---|
399 | |
---|
400 | function ogBootMbrXP () |
---|
401 | { |
---|
402 | # Variables locales. |
---|
403 | local DISK |
---|
404 | |
---|
405 | # Si se solicita, mostrar ayuda. |
---|
406 | if [ "$*" == "help" ]; then |
---|
407 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \ |
---|
408 | "$FUNCNAME 1" |
---|
409 | return |
---|
410 | fi |
---|
411 | # Error si no se recibe 1 parámetro. |
---|
412 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
413 | |
---|
414 | DISK="$(ogDiskToDev $1)" || return $? |
---|
415 | ms-sys -z -f $DISK |
---|
416 | ms-sys -m -f $DISK |
---|
417 | } |
---|
418 | |
---|
419 | |
---|
420 | #/** |
---|
421 | # ogBootMbrGeneric int_ndisk |
---|
422 | #@brief Genera un nuevo Codigo de arranque en el MBR del disco indicado, compatible con los SO tipo Windows, Linux. |
---|
423 | #@param int_ndisk nº de orden del disco |
---|
424 | #@return salida del programa my-sys |
---|
425 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
426 | #@exception OG_ERR_NOTFOUND Tipo de partición desconocido o no se puede montar. |
---|
427 | #@version 0.9 - Adaptación a OpenGnSys. |
---|
428 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
429 | #@date 2009-09-24 |
---|
430 | #*/ ## |
---|
431 | |
---|
432 | function ogBootMbrGeneric () |
---|
433 | { |
---|
434 | # Variables locales. |
---|
435 | local DISK |
---|
436 | |
---|
437 | # Si se solicita, mostrar ayuda. |
---|
438 | if [ "$*" == "help" ]; then |
---|
439 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \ |
---|
440 | "$FUNCNAME 1 " |
---|
441 | return |
---|
442 | fi |
---|
443 | # Error si no se recibe 1 parámetro. |
---|
444 | [ $# == 1 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
445 | |
---|
446 | DISK="$(ogDiskToDev $1)" || return $? |
---|
447 | ms-sys -z -f $DISK |
---|
448 | ms-sys -s -f $DISK |
---|
449 | } |
---|
450 | |
---|
451 | |
---|
452 | |
---|
453 | |
---|
454 | #/** |
---|
455 | # ogFixBootSector int_ndisk int_parition |
---|
456 | #@brief Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs |
---|
457 | #@param int_ndisk nº de orden del disco |
---|
458 | #@param int_partition nº de particion |
---|
459 | #@return |
---|
460 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
461 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
462 | #@version 0.9 - Adaptación a OpenGnSys. |
---|
463 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
464 | #@date 2009-09-24 |
---|
465 | #*/ ## |
---|
466 | |
---|
467 | function ogFixBootSector () |
---|
468 | { |
---|
469 | # Variables locales. |
---|
470 | local PARTYPE DISK PART FILE |
---|
471 | |
---|
472 | # Si se solicita, mostrar ayuda. |
---|
473 | if [ "$*" == "help" ]; then |
---|
474 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \ |
---|
475 | "$FUNCNAME 1 1 " |
---|
476 | return |
---|
477 | fi |
---|
478 | |
---|
479 | # Error si no se reciben 2 parámetros. |
---|
480 | [ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
481 | |
---|
482 | #TODO, solo si la particion existe |
---|
483 | #TODO, solo si es ntfs o fat |
---|
484 | PARTYPE=$(ogGetPartitionId $1 $2) |
---|
485 | case "$PARTYPE" in |
---|
486 | 1|4|6|7|b|c|e|f|17|700|EF00) |
---|
487 | ;; |
---|
488 | *) |
---|
489 | return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
490 | ;; |
---|
491 | esac |
---|
492 | |
---|
493 | ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
494 | |
---|
495 | #Preparando instruccion |
---|
496 | let DISK=$1-1 |
---|
497 | PART=$2 |
---|
498 | FILE=/tmp/temp$$ |
---|
499 | cat > $FILE <<EOF |
---|
500 | disk=$DISK |
---|
501 | main_part=$PART |
---|
502 | fix_first_sector=yes |
---|
503 | EOF |
---|
504 | |
---|
505 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -a -f $FILE |
---|
506 | rm -f $FILE |
---|
507 | } |
---|
508 | |
---|
509 | |
---|
510 | #/** |
---|
511 | # ogGetBootMbr int_ndisk |
---|
512 | #@brief Obtiene el contenido del sector de arranque de un disco. |
---|
513 | #@param int_ndisk nº de orden del disco |
---|
514 | #@return str_MBR Descripción del contenido del MBR. |
---|
515 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
516 | #@exception OG_ERR_NOTFOUND Dispositivo de disco no encontrado. |
---|
517 | #@version 1.1.1b - Primera versión |
---|
518 | #@author Irina Gómez (US). Propuesto por Antonio J. Doblas Viso (UMA) |
---|
519 | #@date 2020-04-05 |
---|
520 | #*/ ## |
---|
521 | function ogGetBootMbr () |
---|
522 | { |
---|
523 | # Variables locales. |
---|
524 | local DISK |
---|
525 | |
---|
526 | # Si se solicita, mostrar ayuda. |
---|
527 | if [ "$*" == "help" ]; then |
---|
528 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \ |
---|
529 | "$FUNCNAME 1" |
---|
530 | return |
---|
531 | fi |
---|
532 | |
---|
533 | # Error si no se recibe 1 parámetro. |
---|
534 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndisk" || return $? |
---|
535 | |
---|
536 | DISK="$(ogDiskToDev $1)" || return $? |
---|
537 | |
---|
538 | ms-sys -f $DISK |
---|
539 | } |
---|
540 | |
---|
541 | #/** |
---|
542 | # ogWindowsBootParameters int_ndisk int_parition |
---|
543 | #@brief Configura el gestor de arranque de windows 7 / vista / XP / 2000 |
---|
544 | #@param int_ndisk nº de orden del disco |
---|
545 | #@param int_partition nº de particion |
---|
546 | #@return |
---|
547 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
548 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
549 | #@version 0.9 - Integración desde EAC para OpenGnSys. |
---|
550 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
551 | #@date 2009-09-24 |
---|
552 | #@version 1.0.1 - Adapatacion para OpenGnsys. |
---|
553 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
554 | #@date 2011-05-20 |
---|
555 | #@version 1.0.5 - Soporte para Windows 8 y Windows 8.1. |
---|
556 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
557 | #@date 2014-01-28 |
---|
558 | #@version 1.1.0 - Soporte para Windows 10. |
---|
559 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
560 | #@date 2016-01-19 |
---|
561 | #@version 1.1.1 - Compatibilidad con UEFI (ticket #802 #889) |
---|
562 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
563 | #@date 2019-01-28 |
---|
564 | #*/ ## |
---|
565 | |
---|
566 | function ogWindowsBootParameters () |
---|
567 | { |
---|
568 | # Variables locales. |
---|
569 | local PART DISK BOOTLABEL BCDFILE BOOTDISK BOOTPART FILE WINVER MOUNT |
---|
570 | |
---|
571 | # Si se solicita, mostrar ayuda. |
---|
572 | if [ "$*" == "help" ]; then |
---|
573 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \ |
---|
574 | "$FUNCNAME 1 1 " |
---|
575 | return |
---|
576 | fi |
---|
577 | |
---|
578 | # Error si no se reciben 2 parámetros. |
---|
579 | [ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
580 | |
---|
581 | ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
582 | |
---|
583 | #Preparando variables adaptadas a sintaxis windows. |
---|
584 | let DISK=$1-1 |
---|
585 | PART=$2 |
---|
586 | FILE=/tmp/temp$$ |
---|
587 | if ogIsEfiActive; then |
---|
588 | read BOOTDISK BOOTPART <<< $(ogGetEsp) |
---|
589 | ogUnmount $BOOTDISK $BOOTPART || ogRaiseError $OG_ERR_PARTITION "ESP: $BOOTDISK $BOOTPART" || return $? |
---|
590 | |
---|
591 | let BOOTDISK=$BOOTDISK-1 |
---|
592 | BOOTLABEL=$(printf "Part-%02d-%02d" $1 $2) |
---|
593 | BCDFILE="boot_BCD_file=/EFI/$BOOTLABEL/Boot/BCD" |
---|
594 | else |
---|
595 | BOOTDISK=$DISK |
---|
596 | BOOTPART=$PART |
---|
597 | BCDFILE="" |
---|
598 | fi |
---|
599 | |
---|
600 | |
---|
601 | # Obtener versión de Windows. |
---|
602 | WINVER=$(ogGetOsVersion $1 $2 | awk -F"[: ]" '$1=="Windows" {if ($3=="Server") print $2,$3,$4; else print $2,$3;}') |
---|
603 | [ -z "$WINVER" ] && return $(ogRaiseError $OG_ERR_NOTOS "Windows"; echo $?) |
---|
604 | |
---|
605 | # Acciones para Windows XP. |
---|
606 | if [[ "$WINVER" =~ "XP" ]]; then |
---|
607 | MOUNT=$(ogMount $1 $2) |
---|
608 | [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTFOUND "boot.ini"; echo $?) |
---|
609 | 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 |
---|
610 | return 0 |
---|
611 | fi |
---|
612 | |
---|
613 | ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
614 | |
---|
615 | |
---|
616 | #Preparando instruccion Windows Resume Application |
---|
617 | cat > $FILE <<EOF |
---|
618 | boot_disk=$BOOTDISK |
---|
619 | boot_main_part=$BOOTPART |
---|
620 | $BCDFILE |
---|
621 | disk=$DISK |
---|
622 | main_part=$PART |
---|
623 | boot_entry=Windows Resume Application |
---|
624 | EOF |
---|
625 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
626 | |
---|
627 | |
---|
628 | #Preparando instruccion tipo windows |
---|
629 | cat > $FILE <<EOF |
---|
630 | boot_disk=$BOOTDISK |
---|
631 | boot_main_part=$BOOTPART |
---|
632 | $BCDFILE |
---|
633 | disk=$DISK |
---|
634 | main_part=$PART |
---|
635 | boot_entry=$WINVER |
---|
636 | EOF |
---|
637 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
638 | |
---|
639 | ##Preparando instruccion Ramdisk Options |
---|
640 | cat > $FILE <<EOF |
---|
641 | boot_disk=$BOOTDISK |
---|
642 | boot_main_part=$BOOTPART |
---|
643 | $BCDFILE |
---|
644 | disk=$DISK |
---|
645 | main_part=$PART |
---|
646 | boot_entry=Ramdisk Options |
---|
647 | EOF |
---|
648 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
649 | |
---|
650 | ##Preparando instruccion Recovery Environment |
---|
651 | cat > $FILE <<EOF |
---|
652 | boot_disk=$BOOTDISK |
---|
653 | boot_main_part=$BOOTPART |
---|
654 | $BCDFILE |
---|
655 | disk=$DISK |
---|
656 | main_part=$PART |
---|
657 | boot_entry=Windows Recovery Environment |
---|
658 | EOF |
---|
659 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
660 | |
---|
661 | ##Preparando instruccion Recovery |
---|
662 | cat > $FILE <<EOF |
---|
663 | boot_disk=$BOOTDISK |
---|
664 | boot_main_part=$BOOTPART |
---|
665 | $BCDFILE |
---|
666 | disk=$DISK |
---|
667 | main_part=$PART |
---|
668 | boot_entry=Windows Recovery |
---|
669 | EOF |
---|
670 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
671 | |
---|
672 | #Preparando instruccion Windows Boot Manager |
---|
673 | cat > $FILE <<EOF |
---|
674 | boot_disk=$BOOTDISK |
---|
675 | boot_main_part=$BOOTPART |
---|
676 | $BCDFILE |
---|
677 | disk=$BOOTDISK |
---|
678 | main_part=$BOOTPART |
---|
679 | boot_entry=Windows Boot Manager |
---|
680 | EOF |
---|
681 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
682 | |
---|
683 | #Preparando instruccion Herramienta de diagnóstico de memoria de Windows |
---|
684 | cat > $FILE <<EOF |
---|
685 | boot_disk=$BOOTDISK |
---|
686 | boot_main_part=$BOOTPART |
---|
687 | $BCDFILE |
---|
688 | disk=$BOOTDISK |
---|
689 | main_part=$BOOTPART |
---|
690 | boot_entry=Herramienta de diagnóstico de memoria de Windows |
---|
691 | EOF |
---|
692 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
693 | |
---|
694 | #Preparando instruccion Herramienta de diagnóstico de memoria de Windows |
---|
695 | cat > $FILE <<EOF |
---|
696 | boot_disk=$BOOTDISK |
---|
697 | boot_main_part=$BOOTPART |
---|
698 | $BCDFILE |
---|
699 | disk=$BOOTDISK |
---|
700 | main_part=$BOOTPART |
---|
701 | boot_entry=Herramienta de diagn<f3>stico de memoria de Windows |
---|
702 | EOF |
---|
703 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -w -f $FILE |
---|
704 | |
---|
705 | rm -f $FILE |
---|
706 | } |
---|
707 | |
---|
708 | |
---|
709 | |
---|
710 | #/** |
---|
711 | # ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition |
---|
712 | #@brief Registra una partición en windows con un determinado volumen. |
---|
713 | #@param int_ndisk nº de orden del disco a registrar |
---|
714 | #@param int_partition nº de particion a registrar |
---|
715 | #@param str_volumen volumen a resgistar |
---|
716 | #@param int_ndisk_windows nº de orden del disco donde esta windows |
---|
717 | #@param int_partition_windows nº de particion donde esta windows |
---|
718 | #@return |
---|
719 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
720 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
721 | #@version 0.9 - Adaptación a OpenGnSys. |
---|
722 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
723 | #@date 2009-09-24 |
---|
724 | #*/ ## |
---|
725 | function ogWindowsRegisterPartition () |
---|
726 | { |
---|
727 | # Variables locales. |
---|
728 | local PART DISK FILE REGISTREDDISK REGISTREDPART REGISTREDVOL VERSION SYSTEMROOT |
---|
729 | |
---|
730 | # Si se solicita, mostrar ayuda. |
---|
731 | if [ "$*" == "help" ]; then |
---|
732 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \ |
---|
733 | "$FUNCNAME 1 1 c: 1 1" |
---|
734 | return |
---|
735 | fi |
---|
736 | |
---|
737 | # Error si no se reciben 5 parámetros. |
---|
738 | [ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
739 | |
---|
740 | REGISTREDDISK=$1 |
---|
741 | REGISTREDPART=$2 |
---|
742 | REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]') |
---|
743 | DISK=$4 |
---|
744 | PART=$5 |
---|
745 | FILE=/tmp/temp$$ |
---|
746 | |
---|
747 | ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?) |
---|
748 | ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?) |
---|
749 | |
---|
750 | ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?) |
---|
751 | |
---|
752 | VERSION=$(ogGetOsVersion $DISK $PART) |
---|
753 | |
---|
754 | #Systemroot |
---|
755 | |
---|
756 | if ogGetPath $DISK $PART WINDOWS |
---|
757 | then |
---|
758 | SYSTEMROOT="Windows" |
---|
759 | elif ogGetPath $DISK $PART WINNT |
---|
760 | then |
---|
761 | SYSTEMROOT="winnt" |
---|
762 | else |
---|
763 | return $(ogRaiseError $OG_ERR_NOTOS; echo $?) |
---|
764 | fi |
---|
765 | |
---|
766 | ogUnmount $DISK $PART |
---|
767 | let DISK=$DISK-1 |
---|
768 | let REGISTREDDISK=$REGISTREDDISK-1 |
---|
769 | #Preparando instruccion Windows Boot Manager |
---|
770 | cat > $FILE <<EOF |
---|
771 | windows_disk=$DISK |
---|
772 | windows_main_part=$PART |
---|
773 | windows_dir=$SYSTEMROOT |
---|
774 | disk=$REGISTREDDISK |
---|
775 | main_part=$REGISTREDPART |
---|
776 | ;ext_part |
---|
777 | part_letter=$REGISTREDVOL |
---|
778 | EOF |
---|
779 | timeout --foreground --signal=SIGKILL 5s spartlnx.run -cui -nm -u -f $FILE |
---|
780 | |
---|
781 | } |
---|
782 | |
---|
783 | #/** |
---|
784 | # ogGrubInstallMbr int_disk_GRUBCFG int_partition_GRUBCFG |
---|
785 | #@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. |
---|
786 | #@param int_disk_SecondStage |
---|
787 | #@param int_part_SecondStage |
---|
788 | #@param bolean_Check_Os_installed_and_Configure_2ndStage true | false[default] |
---|
789 | #@return |
---|
790 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
791 | #@version 1.0.2 - Primeras pruebas. |
---|
792 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
793 | #@date 2011-10-29 |
---|
794 | #@version 1.0.3 - Soporte para linux de 32 y 64 bits |
---|
795 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
796 | #@date 2012-03-13 |
---|
797 | #@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la primera etapa |
---|
798 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
799 | #@date 2012-03-13 |
---|
800 | #@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. |
---|
801 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
802 | #@date 2017-06-19 |
---|
803 | #@version 1.1.0 - #827 Entrada para el ogLive si el equipo tiene partición cache. |
---|
804 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
805 | #@date 2018-01-21 |
---|
806 | #@version 1.1.1 - #802 Equipos EFI: Se crea el grub.cfg de la partición EFI |
---|
807 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
808 | #@date 2019-01-08 |
---|
809 | #@version 1.1.1 - #890 UEFI: el grub.cfg original es necesario para obtener los datos del kernel efi: se mueve al final. |
---|
810 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
811 | #@date 2019-03-05 |
---|
812 | #*/ ## |
---|
813 | |
---|
814 | function ogGrubInstallMbr () |
---|
815 | { |
---|
816 | |
---|
817 | # Variables locales. |
---|
818 | local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME |
---|
819 | local EFIDISK EFIPART EFISECONDSTAGE EFISUBDIR EFIOPTGRUB GRUBENTRY NEWORDER |
---|
820 | |
---|
821 | # Si se solicita, mostrar ayuda. |
---|
822 | if [ "$*" == "help" ]; then |
---|
823 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage \"param param \" " \ |
---|
824 | "$FUNCNAME 1 1 FALSE " \ |
---|
825 | "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" " |
---|
826 | return |
---|
827 | fi |
---|
828 | |
---|
829 | # Error si no se reciben 2 parámetros. |
---|
830 | [ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
831 | |
---|
832 | |
---|
833 | DISK=$1; PART=$2; |
---|
834 | CHECKOS=${3:-"FALSE"} |
---|
835 | KERNELPARAM=$4 |
---|
836 | BACKUPNAME=".backup.og" |
---|
837 | |
---|
838 | #Error si no es linux. |
---|
839 | #TODO: comprobar si se puede utilizar la particion windows como contenedor de grub. |
---|
840 | #VERSION=$(ogGetOsVersion $DISK $PART) |
---|
841 | #echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?) |
---|
842 | |
---|
843 | #La primera etapa del grub se fija en el primer disco duro |
---|
844 | FIRSTSTAGE=$(ogDiskToDev 1) |
---|
845 | |
---|
846 | #localizar disco segunda etapa del grub |
---|
847 | SECONDSTAGE=$(ogMount "$DISK" "$PART") || return $? |
---|
848 | |
---|
849 | # prepara el directorio principal de la segunda etapa |
---|
850 | [ -d ${SECONDSTAGE}/boot/grub/ ] || mkdir -p ${SECONDSTAGE}/boot/grub/ |
---|
851 | |
---|
852 | #Localizar directorio segunda etapa del grub |
---|
853 | PREFIXSECONDSTAGE="/boot/grubMBR" |
---|
854 | |
---|
855 | # Instalamos grub para EFI en ESP |
---|
856 | EFIOPTGRUB="" |
---|
857 | if ogIsEfiActive; then |
---|
858 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
859 | # Comprobamos que exista ESP y el directorio para ubuntu |
---|
860 | EFISECONDSTAGE=$(ogMount $EFIDISK $EFIPART) |
---|
861 | if [ $? -ne 0 ]; then |
---|
862 | ogFormat $EFIDISK $EFIPART FAT32 |
---|
863 | EFISECONDSTAGE=$(ogMount $EFIDISK $EFIPART) || ogRaiseError $OG_ERR_PARTITION "ESP" || return $? |
---|
864 | fi |
---|
865 | EFISUBDIR="grub" |
---|
866 | # Borramos la configuración anterior |
---|
867 | [ -d ${EFISECONDSTAGE}/EFI/$EFISUBDIR ] && rm -rf ${EFISECONDSTAGE}/EFI/$EFISUBDIR |
---|
868 | mkdir -p ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot |
---|
869 | EFIOPTGRUB=" --removable --no-nvram --uefi-secure-boot --target $(ogGetArch)-efi --efi-directory=${EFISECONDSTAGE}/EFI/$EFISUBDIR " |
---|
870 | fi |
---|
871 | |
---|
872 | # Si Reconfigurar segunda etapa (grub.cfg) == FALSE |
---|
873 | if [ "${CHECKOS^^}" == "FALSE" ] && [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] |
---|
874 | then |
---|
875 | # Si no se reconfigura se utiliza el grub.cfg orginal |
---|
876 | [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg |
---|
877 | # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys. |
---|
878 | [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] && rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE} |
---|
879 | PREFIXSECONDSTAGE="" |
---|
880 | else |
---|
881 | # SI Reconfigurar segunda etapa (grub.cfg) == TRUE |
---|
882 | |
---|
883 | #llamada a updateBootCache para que aloje la primera fase del ogLive |
---|
884 | updateBootCache |
---|
885 | |
---|
886 | if ogIsEfiActive; then |
---|
887 | # UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup. |
---|
888 | if ! [ -f ${SECONDSTAGE}/boot/grub/grub.cfg ]; then |
---|
889 | [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg |
---|
890 | fi |
---|
891 | else |
---|
892 | #Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup |
---|
893 | mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME |
---|
894 | fi |
---|
895 | |
---|
896 | #Configur la sintaxis grub para evitar menus de "recovery" en el OGLive |
---|
897 | echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub |
---|
898 | echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub |
---|
899 | |
---|
900 | |
---|
901 | #Preparar configuración segunda etapa: crear ubicacion |
---|
902 | mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/ |
---|
903 | #Preparar configuración segunda etapa: crear cabecera del fichero (ignorar errores) |
---|
904 | sed -i 's/^set -e/#set -e/' /etc/grub.d/00_header |
---|
905 | # (ogLive 5.0) Si 'pkgdatadir' está vacía ponemos valor de otros ogLive |
---|
906 | sed -i '/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}' /etc/grub.d/00_header |
---|
907 | /etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg 2>/dev/null |
---|
908 | |
---|
909 | #Preparar configuración segunda etapa: crear entrada del sistema operativo |
---|
910 | grubSyntax "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg |
---|
911 | |
---|
912 | # Renombramos la configuración de grub antigua |
---|
913 | [ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME |
---|
914 | |
---|
915 | fi |
---|
916 | |
---|
917 | #Instalar el grub |
---|
918 | grub-install --force ${EFIOPTGRUB} --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE |
---|
919 | EVAL=$? |
---|
920 | |
---|
921 | # Movemos el grubx64.efi |
---|
922 | if ogIsEfiActive; then |
---|
923 | mv ${EFISECONDSTAGE}/EFI/$EFISUBDIR/EFI/BOOT/* ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot |
---|
924 | rm -rf ${EFISECONDSTAGE}/EFI/$EFISUBDIR/EFI |
---|
925 | cp /usr/lib/shim/shimx64.efi.signed ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot/shimx64.efi |
---|
926 | # Nombre OpenGnsys para cargador |
---|
927 | cp ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot/{grubx64.efi,ogloader.efi} |
---|
928 | |
---|
929 | # Creamos entrada NVRAM y la ponemos en segundo lugar |
---|
930 | ogNvramAddEntry grub /EFI/grub/Boot/shimx64.efi |
---|
931 | GRUBENTRY=$(ogNvramList| awk '{if ($2=="grub") print $1}') |
---|
932 | NEWORDER="$(ogNvramGetOrder|awk -v ENTRY=$GRUBENTRY '{gsub(",", " "); printf "%x %x %s\n", $1 , ENTRY , substr($0, index($0,$2))}')" |
---|
933 | ogNvramSetOrder $NEWORDER |
---|
934 | fi |
---|
935 | return $EVAL |
---|
936 | |
---|
937 | } |
---|
938 | |
---|
939 | |
---|
940 | #/** |
---|
941 | # ogGrubInstallPartition int_disk_SECONDSTAGE int_partition_SECONDSTAGE bolean_Check_Os_installed_and_Configure_2ndStage |
---|
942 | #@brief Instala y actualiza el gestor grub en el bootsector de la particion indicada |
---|
943 | #@param int_disk_SecondStage |
---|
944 | #@param int_part_SecondStage |
---|
945 | #@param bolean_Check_Os_installed_and_Configure_2ndStage true | false[default] |
---|
946 | #@param str "kernel param " |
---|
947 | #@return |
---|
948 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
949 | #@version 1.0.2 - Primeras pruebas. |
---|
950 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
951 | #@date 2011-10-29 |
---|
952 | #@version 1.0.3 - Soporte para linux de 32 y 64 bits |
---|
953 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
954 | #@date 2012-03-13 |
---|
955 | #@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la priemra etapa |
---|
956 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
957 | #@date 2012-03-13 |
---|
958 | #@version 1.1.1 - #802 Equipos EFI: Se crea el grub.cfg de la partición EFI |
---|
959 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
960 | #@date 2019-01-08 |
---|
961 | #@version 1.1.1 - #890 UEFI: el grub.cfg original es necesario para obtener los datos del kernel efi: se mueve al final. |
---|
962 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
963 | #@date 2019-03-05 |
---|
964 | #*/ ## |
---|
965 | |
---|
966 | function ogGrubInstallPartition () |
---|
967 | { |
---|
968 | |
---|
969 | # Variables locales. |
---|
970 | local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME |
---|
971 | local EFIDISK EFIPART EFISECONDSTAGE EFISUBDIR EFIOPTGRUB EFIBOOTDIR |
---|
972 | |
---|
973 | # Si se solicita, mostrar ayuda. |
---|
974 | if [ "$*" == "help" ]; then |
---|
975 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage \"param param \" " \ |
---|
976 | "$FUNCNAME 1 1 FALSE " \ |
---|
977 | "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" " |
---|
978 | return |
---|
979 | fi |
---|
980 | |
---|
981 | # Error si no se reciben 2 parámetros. |
---|
982 | [ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
983 | |
---|
984 | DISK=$1; PART=$2; |
---|
985 | CHECKOS=${3:-"FALSE"} |
---|
986 | KERNELPARAM=$4 |
---|
987 | BACKUPNAME=".backup.og" |
---|
988 | |
---|
989 | #error si no es linux. |
---|
990 | VERSION=$(ogGetOsVersion $DISK $PART) |
---|
991 | echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?) |
---|
992 | |
---|
993 | #Localizar primera etapa del grub |
---|
994 | FIRSTSTAGE=$(ogDiskToDev $DISK $PART) |
---|
995 | |
---|
996 | #localizar disco segunda etapa del grub |
---|
997 | SECONDSTAGE=$(ogMount $DISK $PART) |
---|
998 | |
---|
999 | #Localizar directorio segunda etapa del grub |
---|
1000 | PREFIXSECONDSTAGE="/boot/grubPARTITION" |
---|
1001 | |
---|
1002 | # Si es EFI instalamos el grub en la ESP |
---|
1003 | EFIOPTGRUB="" |
---|
1004 | # Desde el bootdir uefi y bios buscan el grub.cfg en subdirectorios distintos. |
---|
1005 | EFIBOOTDIR="" |
---|
1006 | if ogIsEfiActive; then |
---|
1007 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
1008 | # Comprobamos que exista ESP y el directorio para ubuntu |
---|
1009 | EFISECONDSTAGE=$(ogMount $EFIDISK $EFIPART) |
---|
1010 | if [ $? -ne 0 ]; then |
---|
1011 | ogFormat $EFIDISK $EFIPART FAT32 |
---|
1012 | EFISECONDSTAGE=$(ogMount $EFIDISK $EFIPART) || ogRaiseError $OG_ERR_PARTITION "ESP" || return $? |
---|
1013 | fi |
---|
1014 | EFISUBDIR=$(printf "Part-%02d-%02d" $DISK $PART) |
---|
1015 | # Borramos la configuración anterior |
---|
1016 | [ -d ${EFISECONDSTAGE}/EFI/$EFISUBDIR ] && rm -rf ${EFISECONDSTAGE}/EFI/$EFISUBDIR |
---|
1017 | mkdir -p ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot |
---|
1018 | EFIOPTGRUB=" --removable --no-nvram --uefi-secure-boot --target $(ogGetArch)-efi --efi-directory=${EFISECONDSTAGE}/EFI/$EFISUBDIR " |
---|
1019 | EFIBOOTDIR="/boot" |
---|
1020 | fi |
---|
1021 | |
---|
1022 | # Si Reconfigurar segunda etapa (grub.cfg) == FALSE |
---|
1023 | if [ "${CHECKOS^^}" == "FALSE" ] && [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] |
---|
1024 | then |
---|
1025 | # Si no se reconfigura se utiliza el grub.cfg orginal |
---|
1026 | [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg |
---|
1027 | # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys. |
---|
1028 | [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] && rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE} |
---|
1029 | # Reactivamos el grub con el grub.cfg original. |
---|
1030 | PREFIXSECONDSTAGE="" |
---|
1031 | else |
---|
1032 | # SI Reconfigurar segunda etapa (grub.cfg) == TRUE |
---|
1033 | |
---|
1034 | if ogIsEfiActive; then |
---|
1035 | # UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup. |
---|
1036 | if ! [ -f ${SECONDSTAGE}/boot/grub/grub.cfg ]; then |
---|
1037 | [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg |
---|
1038 | fi |
---|
1039 | else |
---|
1040 | #Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup |
---|
1041 | mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME |
---|
1042 | fi |
---|
1043 | |
---|
1044 | #Configur la sintaxis grub para evitar menus de "recovery" en el OGLive |
---|
1045 | echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub |
---|
1046 | echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub |
---|
1047 | |
---|
1048 | #Preparar configuración segunda etapa: crear ubicacion |
---|
1049 | mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/ |
---|
1050 | #Preparar configuración segunda etapa: crear cabecera del fichero (ingnorar errores) |
---|
1051 | sed -i 's/^set -e/#set -e/' /etc/grub.d/00_header |
---|
1052 | # (ogLive 5.0) Si 'pkgdatadir' está vacía ponemos valor de otros ogLive |
---|
1053 | sed -i '/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}' /etc/grub.d/00_header |
---|
1054 | /etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg 2>/dev/null |
---|
1055 | #Preparar configuración segunda etapa: crear entrada del sistema operativo |
---|
1056 | grubSyntax $DISK $PART "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg |
---|
1057 | |
---|
1058 | fi |
---|
1059 | #Instalar el grub |
---|
1060 | grub-install --force ${EFIOPTGRUB} --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE |
---|
1061 | EVAL=$? |
---|
1062 | |
---|
1063 | # Movemos el grubx64.efi |
---|
1064 | if ogIsEfiActive; then |
---|
1065 | mv ${EFISECONDSTAGE}/EFI/$EFISUBDIR/EFI/BOOT/* ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot |
---|
1066 | rm -rf ${EFISECONDSTAGE}/EFI/$EFISUBDIR/EFI |
---|
1067 | cp /usr/lib/shim/shimx64.efi.signed ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot/shimx64.efi |
---|
1068 | # Nombre OpenGnsys para cargador |
---|
1069 | cp ${EFISECONDSTAGE}/EFI/$EFISUBDIR/Boot/{grubx64.efi,ogloader.efi} |
---|
1070 | fi |
---|
1071 | |
---|
1072 | return $EVAL |
---|
1073 | } |
---|
1074 | |
---|
1075 | |
---|
1076 | #/** |
---|
1077 | # ogConfigureFstab int_ndisk int_nfilesys |
---|
1078 | #@brief Configura el fstab según particiones existentes |
---|
1079 | #@param int_ndisk nº de orden del disco |
---|
1080 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
1081 | #@return (nada) |
---|
1082 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1083 | #@exception OG_ERR_NOTFOUND No se encuentra el fichero fstab a procesar. |
---|
1084 | #@warning Puede haber un error si hay más de 1 partición swap. |
---|
1085 | #@version 1.0.5 - Primera versión para OpenGnSys. Solo configura la SWAP |
---|
1086 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1087 | #@date 2013-03-21 |
---|
1088 | #@version 1.0.6b - correccion. Si no hay partición fisica para la SWAP, eliminar entrada del fstab. |
---|
1089 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1090 | #@date 2016-11-03 |
---|
1091 | #@version 1.1.1 - Se configura la partición ESP (para sistemas EFI) (ticket #802) |
---|
1092 | #@author Irina Gómez, ETSII Universidad de Sevilla |
---|
1093 | #@date 2018-12-13 |
---|
1094 | #*/ ## |
---|
1095 | function ogConfigureFstab () |
---|
1096 | { |
---|
1097 | # Variables locales. |
---|
1098 | local FSTAB DEFROOT PARTROOT DEFSWAP PARTSWAP |
---|
1099 | local EFIDISK EFIPART EFIDEV EFIOPT |
---|
1100 | |
---|
1101 | # Si se solicita, mostrar ayuda. |
---|
1102 | if [ "$*" == "help" ]; then |
---|
1103 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \ |
---|
1104 | "$FUNCNAME 1 1" |
---|
1105 | return |
---|
1106 | fi |
---|
1107 | # Error si no se reciben 2 parámetros. |
---|
1108 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1109 | # Error si no se encuentra un fichero etc/fstab en el sistema de archivos. |
---|
1110 | FSTAB=$(ogGetPath $1 $2 /etc/fstab) 2>/dev/null |
---|
1111 | [ -n "$FSTAB" ] || ogRaiseError $OG_ERR_NOTFOUND "$1,$2,/etc/fstab" || return $? |
---|
1112 | |
---|
1113 | # Hacer copia de seguridad del fichero fstab original. |
---|
1114 | cp -a ${FSTAB} ${FSTAB}.backup |
---|
1115 | # Dispositivo del raíz en fichero fstab: 1er campo (si no tiene "#") con 2º campo = "/". |
---|
1116 | DEFROOT=$(awk '$1!~/#/ && $2=="/" {print $1}' ${FSTAB}) |
---|
1117 | PARTROOT=$(ogDiskToDev $1 $2) |
---|
1118 | # Configuración de swap (solo 1ª partición detectada). |
---|
1119 | PARTSWAP=$(blkid -t TYPE=swap | awk -F: 'NR==1 {print $1}') |
---|
1120 | if [ -n "$PARTSWAP" ] |
---|
1121 | then |
---|
1122 | # Dispositivo de swap en fichero fstab: 1er campo (si no tiene "#") con 3er campo = "swap". |
---|
1123 | DEFSWAP=$(awk '$1!~/#/ && $3=="swap" {print $1}' ${FSTAB}) |
---|
1124 | if [ -n "$DEFSWAP" ] |
---|
1125 | then |
---|
1126 | echo "Hay definicion de SWAP en el FSTAB $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP" # Mensaje temporal. |
---|
1127 | sed "s|$DEFSWAP|$PARTSWAP|g ; s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB} |
---|
1128 | else |
---|
1129 | echo "No hay definicion de SWAP y si hay partición SWAP -> moficamos fichero" # Mensaje temporal. |
---|
1130 | sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB} |
---|
1131 | echo "$PARTSWAP none swap sw 0 0" >> ${FSTAB} |
---|
1132 | fi |
---|
1133 | else |
---|
1134 | echo "No hay partición SWAP -> configuramos FSTAB" # Mensaje temporal. |
---|
1135 | sed "/swap/d" ${FSTAB}.backup > ${FSTAB} |
---|
1136 | fi |
---|
1137 | # Si es un sistema EFI incluimos partición ESP (Si existe la modificamos) |
---|
1138 | if ogIsEfiActive; then |
---|
1139 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
1140 | EFIDEV=$(ogDiskToDev $EFIDISK $EFIPART) |
---|
1141 | |
---|
1142 | # Opciones de la partición ESP: si no existe ponemos un valor por defecto |
---|
1143 | EFIOPT=$(awk '$1!~/#/ && $2=="/boot/efi" {print $3"\t"$4"\t"$5"\t"$6 }' ${FSTAB}) |
---|
1144 | [ "$EFIOPT" == "" ] && EFIOPT='vfat\tumask=0077\t0\t1' |
---|
1145 | |
---|
1146 | sed -i /"boot\/efi"/d ${FSTAB} |
---|
1147 | echo -e "$EFIDEV\t/boot/efi\t$EFIOPT" >> ${FSTAB} |
---|
1148 | fi |
---|
1149 | } |
---|
1150 | |
---|
1151 | #/** |
---|
1152 | # ogSetLinuxName int_ndisk int_nfilesys [str_name] |
---|
1153 | #@brief Establece el nombre del equipo en los ficheros hostname y hosts. |
---|
1154 | #@param int_ndisk nº de orden del disco |
---|
1155 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
1156 | #@param str_name nombre asignado (opcional) |
---|
1157 | #@return (nada) |
---|
1158 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1159 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
1160 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
1161 | #@note Si no se indica nombre, se asigna un valor por defecto. |
---|
1162 | #@version 1.0.5 - Primera versión para OpenGnSys. |
---|
1163 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1164 | #@date 2013-03-21 |
---|
1165 | #*/ ## |
---|
1166 | function ogSetLinuxName () |
---|
1167 | { |
---|
1168 | # Variables locales. |
---|
1169 | local MNTDIR ETC NAME |
---|
1170 | |
---|
1171 | # Si se solicita, mostrar ayuda. |
---|
1172 | if [ "$*" == "help" ]; then |
---|
1173 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_name]" \ |
---|
1174 | "$FUNCNAME 1 1" "$FUNCNAME 1 1 practica-pc" |
---|
1175 | return |
---|
1176 | fi |
---|
1177 | # Error si no se reciben 2 o 3 parámetros. |
---|
1178 | case $# in |
---|
1179 | 2) # Asignar nombre automático (por defecto, "pc"). |
---|
1180 | NAME="$(ogGetHostname)" |
---|
1181 | NAME=${NAME:-"pc"} ;; |
---|
1182 | 3) # Asignar nombre del 3er parámetro. |
---|
1183 | NAME="$3" ;; |
---|
1184 | *) # Formato de ejecución incorrecto. |
---|
1185 | ogRaiseError $OG_ERR_FORMAT |
---|
1186 | return $? |
---|
1187 | esac |
---|
1188 | |
---|
1189 | # Montar el sistema de archivos. |
---|
1190 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
1191 | |
---|
1192 | ETC=$(ogGetPath $1 $2 /etc) |
---|
1193 | |
---|
1194 | if [ -d "$ETC" ]; then |
---|
1195 | #cambio de nombre en hostname |
---|
1196 | echo "$NAME" > $ETC/hostname |
---|
1197 | #Opcion A para cambio de nombre en hosts |
---|
1198 | #sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts |
---|
1199 | #Opcion B componer fichero de hosts |
---|
1200 | cat > $ETC/hosts <<EOF |
---|
1201 | 127.0.0.1 localhost |
---|
1202 | 127.0.1.1 $NAME |
---|
1203 | |
---|
1204 | # The following lines are desirable for IPv6 capable hosts |
---|
1205 | ::1 ip6-localhost ip6-loopback |
---|
1206 | fe00::0 ip6-localnet |
---|
1207 | ff00::0 ip6-mcastprefix |
---|
1208 | ff02::1 ip6-allnodes |
---|
1209 | ff02::2 ip6-allrouters |
---|
1210 | EOF |
---|
1211 | fi |
---|
1212 | } |
---|
1213 | |
---|
1214 | |
---|
1215 | |
---|
1216 | #/** |
---|
1217 | # ogCleanLinuxDevices int_ndisk int_nfilesys |
---|
1218 | #@brief Limpia los dispositivos del equipo de referencia. Interfaz de red ... |
---|
1219 | #@param int_ndisk nº de orden del disco |
---|
1220 | #@param int_nfilesys nº de orden del sistema de archivos |
---|
1221 | #@return (nada) |
---|
1222 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1223 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
1224 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
1225 | #@version 1.0.5 - Primera versión para OpenGnSys. |
---|
1226 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1227 | #@date 2013-03-21 |
---|
1228 | #@version 1.0.6b - Elimina fichero resume de hibernacion |
---|
1229 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1230 | #@date 2016-11-07 |
---|
1231 | #*/ ## |
---|
1232 | function ogCleanLinuxDevices () |
---|
1233 | { |
---|
1234 | # Variables locales. |
---|
1235 | local MNTDIR |
---|
1236 | |
---|
1237 | # Si se solicita, mostrar ayuda. |
---|
1238 | if [ "$*" == "help" ]; then |
---|
1239 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \ |
---|
1240 | "$FUNCNAME 1 1" |
---|
1241 | return |
---|
1242 | fi |
---|
1243 | # Error si no se reciben 2 parámetros. |
---|
1244 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1245 | |
---|
1246 | # Montar el sistema de archivos. |
---|
1247 | MNTDIR=$(ogMount $1 $2) || return $? |
---|
1248 | |
---|
1249 | # Eliminar fichero de configuración de udev para dispositivos fijos de red. |
---|
1250 | [ -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules ] && rm -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules |
---|
1251 | # Eliminar fichero resume (estado previo de hibernación) utilizado por el initrd scripts-premount |
---|
1252 | [ -f ${MNTDIR}/etc/initramfs-tools/conf.d/resume ] && rm -f ${MNTDIR}/etc/initramfs-tools/conf.d/resume |
---|
1253 | } |
---|
1254 | |
---|
1255 | #/** |
---|
1256 | # ogGrubAddOgLive num_disk num_part [ timeout ] [ offline ] |
---|
1257 | #@brief Crea entrada de menu grub para ogclient, tomando como paramentros del kernel los actuales del cliente. |
---|
1258 | #@param 1 Numero de disco |
---|
1259 | #@param 2 Numero de particion |
---|
1260 | #@param 3 timeout Segundos de espera para iniciar el sistema operativo por defecto (opcional) |
---|
1261 | #@param 4 offline configura el modo offline [offline|online] (opcional) |
---|
1262 | #@return (nada) |
---|
1263 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1264 | #@exception OG_ERR_NOTFOUND No existe kernel o initrd en cache. |
---|
1265 | #@exception OG_ERR_NOTFOUND No existe archivo de configuracion del grub. |
---|
1266 | # /// FIXME: Solo para el grub instalado en MBR por Opengnsys, ampliar para más casos. |
---|
1267 | #@version 1.0.6 - Prmera integración |
---|
1268 | #@author |
---|
1269 | #@date 2016-11-07 |
---|
1270 | #@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. |
---|
1271 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1272 | #@date 2017-06-17 |
---|
1273 | #*/ ## |
---|
1274 | |
---|
1275 | |
---|
1276 | function ogGrubAddOgLive () |
---|
1277 | { |
---|
1278 | local TIMEOUT DIRMOUNT GRUBGFC PARTTABLETYPE NUMDISK NUMPART KERNEL STATUS NUMLINE MENUENTRY |
---|
1279 | |
---|
1280 | # Si se solicita, mostrar ayuda. |
---|
1281 | if [ "$*" == "help" ]; then |
---|
1282 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [ time_out ] [ offline|online ] " \ |
---|
1283 | "$FUNCNAME 1 1" \ |
---|
1284 | "$FUNCNAME 1 6 15 offline" |
---|
1285 | return |
---|
1286 | fi |
---|
1287 | |
---|
1288 | # Error si no se reciben 2 parámetros. |
---|
1289 | [ $# -lt 2 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part [ timeout ]"; echo $?) |
---|
1290 | [[ "$3" =~ ^[0-9]*$ ]] && TIMEOUT="$3" |
---|
1291 | |
---|
1292 | # Error si no existe el kernel y el initrd en la cache. |
---|
1293 | # Falta crear nuevo codigo de error. |
---|
1294 | [ -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 $?) |
---|
1295 | |
---|
1296 | # Archivo de configuracion del grub |
---|
1297 | DIRMOUNT=$(ogMount $1 $2) |
---|
1298 | GRUBGFC="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg" |
---|
1299 | |
---|
1300 | # Error si no existe archivo del grub |
---|
1301 | [ -r $GRUBGFC ] || return $(ogRaiseError log session $OG_ERR_NOTFOUND "$GRUBGFC" 1>&2; echo $?) |
---|
1302 | |
---|
1303 | # Si existe la entrada de opengnsys, se borra |
---|
1304 | grep -q "menuentry Opengnsys" $GRUBGFC && sed -ie "/menuentry Opengnsys/,+6d" $GRUBGFC |
---|
1305 | |
---|
1306 | # Tipo de tabla de particiones |
---|
1307 | PARTTABLETYPE=$(ogGetPartitionTableType $1 | tr [:upper:] [:lower:]) |
---|
1308 | |
---|
1309 | # Localizacion de la cache |
---|
1310 | read NUMDISK NUMPART <<< $(ogFindCache) |
---|
1311 | let NUMDISK=$NUMDISK-1 |
---|
1312 | # kernel y sus opciones. Pasamos a modo usuario |
---|
1313 | KERNEL="/boot/${oglivedir}/ogvmlinuz $(sed -e s/^.*linuz//g -e s/ogactiveadmin=[a-z]*//g /proc/cmdline)" |
---|
1314 | |
---|
1315 | # Configuracion offline si existe parametro |
---|
1316 | echo "$@" |grep offline &>/dev/null && STATUS=offline |
---|
1317 | echo "$@" |grep online &>/dev/null && STATUS=online |
---|
1318 | [ -z "$STATUS" ] || KERNEL="$(echo $KERNEL | sed s/"ogprotocol=[a-z]* "/"ogprotocol=local "/g ) ogstatus=$STATUS" |
---|
1319 | |
---|
1320 | # Numero de línea de la primera entrada del grub. |
---|
1321 | NUMLINE=$(grep -n -m 1 "^menuentry" $GRUBGFC|cut -d: -f1) |
---|
1322 | # Texto de la entrada de opengnsys |
---|
1323 | MENUENTRY="menuentry "OpenGnsys" --class opengnsys --class gnu --class os { \n \ |
---|
1324 | \tinsmod part_$PARTTABLETYPE \n \ |
---|
1325 | \tinsmod ext2 \n \ |
---|
1326 | \tset root='(hd${NUMDISK},$PARTTABLETYPE${NUMPART})' \n \ |
---|
1327 | \tlinux $KERNEL \n \ |
---|
1328 | \tinitrd /boot/${oglivedir}/oginitrd.img \n \ |
---|
1329 | }" |
---|
1330 | |
---|
1331 | |
---|
1332 | # Insertamos la entrada de opengnsys antes de la primera entrada existente. |
---|
1333 | sed -i "${NUMLINE}i\ $MENUENTRY" $GRUBGFC |
---|
1334 | |
---|
1335 | # Ponemos que la entrada por defecto sea la primera. |
---|
1336 | sed -i s/"set.*default.*$"/"set default=\"0\""/g $GRUBGFC |
---|
1337 | |
---|
1338 | # Si me dan valor para timeout lo cambio en el grub. |
---|
1339 | [ $TIMEOUT ] && sed -i s/timeout=.*$/timeout=$TIMEOUT/g $GRUBGFC |
---|
1340 | } |
---|
1341 | |
---|
1342 | #/** |
---|
1343 | # ogGrubHidePartitions num_disk num_part |
---|
1344 | #@brief ver ogBootLoaderHidePartitions |
---|
1345 | #@see ogBootLoaderHidePartitions |
---|
1346 | #*/ ## |
---|
1347 | function ogGrubHidePartitions () |
---|
1348 | { |
---|
1349 | # Si se solicita, mostrar ayuda. |
---|
1350 | if [ "$*" == "help" ]; then |
---|
1351 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [ num_disk_partdata num_partdata ]" \ |
---|
1352 | "$FUNCNAME 1 2" \ |
---|
1353 | "$FUNCNAME 1 2 1 3" |
---|
1354 | return |
---|
1355 | fi |
---|
1356 | ogBootLoaderHidePartitions $@ |
---|
1357 | return $? |
---|
1358 | } |
---|
1359 | |
---|
1360 | #/** |
---|
1361 | # ogBurgHidePartitions num_disk num_part |
---|
1362 | #@brief ver ogBootLoaderHidePartitions |
---|
1363 | #@see ogBootLoaderHidePartitions |
---|
1364 | #*/ ## |
---|
1365 | function ogBurgHidePartitions () |
---|
1366 | { |
---|
1367 | # Si se solicita, mostrar ayuda. |
---|
1368 | if [ "$*" == "help" ]; then |
---|
1369 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [ num_disk_partdata num_partdata ]" \ |
---|
1370 | "$FUNCNAME 1 2" \ |
---|
1371 | "$FUNCNAME 1 2 1 3" |
---|
1372 | return |
---|
1373 | fi |
---|
1374 | ogBootLoaderHidePartitions $@ |
---|
1375 | return $? |
---|
1376 | } |
---|
1377 | |
---|
1378 | #/** |
---|
1379 | # ogBootLoaderHidePartitions num_disk num_part |
---|
1380 | #@brief Configura el grub/burg para que oculte las particiones de windows que no se esten iniciando. |
---|
1381 | #@param 1 Numero de disco |
---|
1382 | #@param 2 Numero de particion |
---|
1383 | #@param 3 Numero de disco de la partición de datos (no ocultar) |
---|
1384 | #@param 4 Numero de particion de datos (no ocultar) |
---|
1385 | #@return (nada) |
---|
1386 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1387 | #@exception No existe archivo de configuracion del grub/burg. |
---|
1388 | #@version 1.1 Se comprueban las particiones de Windows con blkid (y no con grub.cfg) |
---|
1389 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1390 | #@date 2015-11-17 |
---|
1391 | #@version 1.1 Se generaliza la función para grub y burg |
---|
1392 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1393 | #@date 2017-10-20 |
---|
1394 | #@version 1.1.1 Se incluye comentarios en codigo para autodocuemtnacion con Doxygen |
---|
1395 | #@author Antonio J. Doblas Viso, EVLT Univesidad de Malaga. |
---|
1396 | #@date 2018-07-05 |
---|
1397 | #@version Se permite una partición de datos que no se ocultará. Soporta más de un disco. Compatible con grub.cfg creado por ogLive 5.0 |
---|
1398 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1399 | #@date 2019-08-26 |
---|
1400 | #*/ |
---|
1401 | |
---|
1402 | function ogBootLoaderHidePartitions () |
---|
1403 | { |
---|
1404 | local FUNC DIRMOUNT GFCFILE PARTTABLETYPE WINENTRY WINPART ENTRY LINE PART PARTDATA TEXT PARTHIDDEN HIDDEN |
---|
1405 | |
---|
1406 | # Si se solicita, mostrar ayuda. |
---|
1407 | if [ "$*" == "help" ]; then |
---|
1408 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubHidePartitions ogBurgHidePartitions" |
---|
1409 | return |
---|
1410 | fi |
---|
1411 | |
---|
1412 | # Nombre de la función que llama a esta. |
---|
1413 | FUNC="${FUNCNAME[@]:1}" |
---|
1414 | FUNC="${FUNC%%\ *}" |
---|
1415 | |
---|
1416 | # Error si no se reciben 2 parámetros. |
---|
1417 | [ $# -lt 2 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part [ num_disk_partdata num_partdata ]"; echo $?) |
---|
1418 | # Si no existe $4 pongo un valor imposible para la partición de datos |
---|
1419 | [ $# -eq 4 ] && PARTDATA=$(ogDiskToDev $3 $4) || PARTDATA=0 |
---|
1420 | |
---|
1421 | # Archivo de configuracion del grub |
---|
1422 | DIRMOUNT=$(ogMount $1 $2) |
---|
1423 | # La función debe ser llamanda desde ogGrubHidePartitions or ogBurgHidePartitions. |
---|
1424 | case "$FUNC" in |
---|
1425 | ogGrubHidePartitions) |
---|
1426 | CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg" |
---|
1427 | ;; |
---|
1428 | ogBurgHidePartitions) |
---|
1429 | CFGFILE="$DIRMOUNT/boot/burg/burg.cfg" |
---|
1430 | ;; |
---|
1431 | *) |
---|
1432 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubHidePartitions or ogBurgHidePartitions." |
---|
1433 | return $? |
---|
1434 | ;; |
---|
1435 | esac |
---|
1436 | |
---|
1437 | # Error si no existe archivo del grub |
---|
1438 | [ -r $CFGFILE ] || return $(ogRaiseError log session $OG_ERR_NOTFOUND "$CFGFILE" 1>&2; echo $?) |
---|
1439 | |
---|
1440 | # Si solo hay una particion de Windows me salgo |
---|
1441 | [ $(fdisk -l $(ogDiskToDev) | grep 'NTFS' |wc -l) -eq 1 ] && return 0 |
---|
1442 | |
---|
1443 | # Elimino llamadas a parttool, se han incluido en otras ejecuciones de esta funcion. |
---|
1444 | sed -i '/parttool/d' $CFGFILE |
---|
1445 | |
---|
1446 | PARTTABLETYPE=$(ogGetPartitionTableType $1 | tr [:upper:] [:lower:]) |
---|
1447 | |
---|
1448 | # /* (comentario de bloque para Doxygen) |
---|
1449 | # Entradas de Windows: numero de linea y particion. De mayor a menor. |
---|
1450 | WINENTRY=$(awk '/menuentry.*Windows/ {gsub(/\)\"/, ""); gsub(/^.*dev/,""); print NR":/dev"$1} ' $CFGFILE | sed -e '1!G;h;$!d') |
---|
1451 | #*/ (comentario para bloque Doxygen) |
---|
1452 | # Particiones de Windows, pueden no estar en el grub. |
---|
1453 | WINPART=$(fdisk -l $(ogDiskToDev)|awk '/NTFS/ {print $1}'|sed '1!G;h;$!d') |
---|
1454 | |
---|
1455 | |
---|
1456 | # Modifico todas las entradas de Windows. |
---|
1457 | for ENTRY in $WINENTRY; do |
---|
1458 | LINE=${ENTRY%:*} |
---|
1459 | PART=${ENTRY#*:} |
---|
1460 | |
---|
1461 | # En cada entrada, oculto o muestro cada particion. |
---|
1462 | TEXT="" |
---|
1463 | for PARTHIDDEN in $WINPART; do |
---|
1464 | # Muestro la particion de la entrada actual y la de datos. |
---|
1465 | [ "$PARTHIDDEN" == "$PART" -o "$PARTHIDDEN" == "$PARTDATA" ] && HIDDEN="-" || HIDDEN="+" |
---|
1466 | read NUMDISK NUMPART <<< $(ogDevToDisk $PARTHIDDEN) |
---|
1467 | |
---|
1468 | TEXT="\tparttool (hd$((NUMDISK-1)),$PARTTABLETYPE$NUMPART) hidden$HIDDEN \n$TEXT" |
---|
1469 | done |
---|
1470 | |
---|
1471 | sed -i "${LINE}a\ $TEXT" $CFGFILE |
---|
1472 | done |
---|
1473 | |
---|
1474 | # Activamos la particion que se inicia en todas las entradas de windows. |
---|
1475 | sed -i "/chainloader/i\\\tparttool \$\{root\} boot+" $CFGFILE |
---|
1476 | } |
---|
1477 | |
---|
1478 | #/** |
---|
1479 | # ogGrubDeleteEntry num_disk num_part num_disk_delete num_part_delete |
---|
1480 | #@brief ver ogBootLoaderDeleteEntry |
---|
1481 | #@see ogBootLoaderDeleteEntry |
---|
1482 | #*/ |
---|
1483 | function ogGrubDeleteEntry () |
---|
1484 | { |
---|
1485 | # Si se solicita, mostrar ayuda. |
---|
1486 | if [ "$*" == "help" ]; then |
---|
1487 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_delete int_npartition_delete" \ |
---|
1488 | "$FUNCNAME 1 6 2 1" |
---|
1489 | return |
---|
1490 | fi |
---|
1491 | ogBootLoaderDeleteEntry $@ |
---|
1492 | return $? |
---|
1493 | } |
---|
1494 | |
---|
1495 | #/** |
---|
1496 | # ogBurgDeleteEntry num_disk num_part num_disk_delete num_part_delete |
---|
1497 | #@brief ver ogBootLoaderDeleteEntry |
---|
1498 | #@see ogBootLoaderDeleteEntry |
---|
1499 | #*/ |
---|
1500 | function ogBurgDeleteEntry () |
---|
1501 | { |
---|
1502 | # Si se solicita, mostrar ayuda. |
---|
1503 | if [ "$*" == "help" ]; then |
---|
1504 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_delete int_npartition_delete" \ |
---|
1505 | "$FUNCNAME 1 6 2 1" |
---|
1506 | return |
---|
1507 | fi |
---|
1508 | ogBootLoaderDeleteEntry $@ |
---|
1509 | return $? |
---|
1510 | } |
---|
1511 | |
---|
1512 | #/** |
---|
1513 | # ogRefindDeleteEntry num_disk_delete num_part_delete |
---|
1514 | #@brief ver ogBootLoaderDeleteEntry |
---|
1515 | #@see ogBootLoaderDeleteEntry |
---|
1516 | #*/ |
---|
1517 | function ogRefindDeleteEntry () |
---|
1518 | { |
---|
1519 | local EFIDISK EFIPART |
---|
1520 | # Si se solicita, mostrar ayuda. |
---|
1521 | if [ "$*" == "help" ]; then |
---|
1522 | ogHelp "$FUNCNAME" "$FUNCNAME int_disk_delete int_npartition_delete" \ |
---|
1523 | "$FUNCNAME 2 1" |
---|
1524 | return |
---|
1525 | fi |
---|
1526 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
1527 | ogBootLoaderDeleteEntry $EFIDISK $EFIPART $@ |
---|
1528 | return $? |
---|
1529 | } |
---|
1530 | |
---|
1531 | #/** |
---|
1532 | # ogBootLoaderDeleteEntry num_disk num_part num_part_delete |
---|
1533 | #@brief Borra en el grub las entradas para el inicio en una particion. |
---|
1534 | #@param 1 Numero de disco donde esta el grub |
---|
1535 | #@param 2 Numero de particion donde esta el grub |
---|
1536 | #@param 3 Numero del disco del que borramos las entradas |
---|
1537 | #@param 4 Numero de la particion de la que borramos las entradas |
---|
1538 | #@note Tiene que ser llamada desde ogGrubDeleteEntry, ogBurgDeleteEntry o ogRefindDeleteEntry |
---|
1539 | #@return (nada) |
---|
1540 | #@exception OG_ERR_FORMAT Use ogGrubDeleteEntry or ogBurgDeleteEntry. |
---|
1541 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1542 | #@exception OG_ERR_NOTFOUND No existe archivo de configuracion del grub. |
---|
1543 | #@version 1.1 Se generaliza la función para grub y burg |
---|
1544 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1545 | #@date 2017-10-20 |
---|
1546 | #*/ ## |
---|
1547 | |
---|
1548 | function ogBootLoaderDeleteEntry () |
---|
1549 | { |
---|
1550 | local FUNC DIRMOUNT CFGFILE LABEL MENUENTRY DELETEENTRY ENDENTRY ENTRY |
---|
1551 | |
---|
1552 | # Si se solicita, mostrar ayuda. |
---|
1553 | if [ "$*" == "help" ]; then |
---|
1554 | ogHelp "$FUNCNAME" "$MSG_SEE ogBurgDeleteEntry, ogGrubDeleteEntry or ogRefindDeleteEntry" |
---|
1555 | return |
---|
1556 | fi |
---|
1557 | |
---|
1558 | # Si el número de parámetros menos que 4 nos salimos |
---|
1559 | [ $# -lt 4 ] && return $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $FUNCNAME num_disk num_part num_disk_delete num_part_delete"; echo $?) |
---|
1560 | |
---|
1561 | |
---|
1562 | # Nombre de la función que llama a esta. |
---|
1563 | FUNC="${FUNCNAME[@]:1}" |
---|
1564 | FUNC="${FUNC%%\ *}" |
---|
1565 | |
---|
1566 | # Archivo de configuracion del grub |
---|
1567 | DIRMOUNT=$(ogMount $1 $2) |
---|
1568 | # La función debe ser llamanda desde ogGrubDeleteEntry, ogBurgDeleteEntry or ogRefindDeleteEntry. |
---|
1569 | case "$FUNC" in |
---|
1570 | ogGrubDeleteEntry) |
---|
1571 | CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg" |
---|
1572 | ;; |
---|
1573 | ogBurgDeleteEntry) |
---|
1574 | CFGFILE="$DIRMOUNT/boot/burg/burg.cfg" |
---|
1575 | ;; |
---|
1576 | ogRefindDeleteEntry) |
---|
1577 | CFGFILE="$DIRMOUNT/EFI/refind/refind.conf" |
---|
1578 | ;; |
---|
1579 | *) |
---|
1580 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubDeleteEntry, ogBurgDeleteEntry or ogRefindDeleteEntry." |
---|
1581 | return $? |
---|
1582 | ;; |
---|
1583 | esac |
---|
1584 | |
---|
1585 | # Dispositivo |
---|
1586 | if [ "$(basename $CFGFILE)" == "refind.conf" ]; then |
---|
1587 | LABEL=$(printf "Part-%02d-%02d" $3 $4) |
---|
1588 | else |
---|
1589 | LABEL=$(ogDiskToDev $3 $4) |
---|
1590 | fi |
---|
1591 | |
---|
1592 | # Error si no existe archivo de configuración |
---|
1593 | [ -r $CFGFILE ] || ogRaiseError log session $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
1594 | |
---|
1595 | # Numero de linea de cada entrada. |
---|
1596 | MENUENTRY="$(grep -n -e menuentry $CFGFILE| cut -d: -f1 | sed '1!G;h;$!d' )" |
---|
1597 | |
---|
1598 | # Entradas que hay que borrar. |
---|
1599 | DELETEENTRY=$(grep -n menuentry.*$LABEL $CFGFILE| cut -d: -f1) |
---|
1600 | |
---|
1601 | # Si no hay entradas para borrar me salgo con aviso |
---|
1602 | [ "$DELETEENTRY" != "" ] || ogRaiseError log session $OG_ERR_NOTFOUND "Menuentry $LABEL" || return $? |
---|
1603 | |
---|
1604 | # Recorremos el fichero del final hacia el principio. |
---|
1605 | ENDENTRY="$(wc -l $CFGFILE|cut -d" " -f1)" |
---|
1606 | for ENTRY in $MENUENTRY; do |
---|
1607 | # Comprobamos si hay que borrar la entrada. |
---|
1608 | if ogCheckStringInGroup $ENTRY "$DELETEENTRY" ; then |
---|
1609 | let ENDENTRY=$ENDENTRY-1 |
---|
1610 | sed -i -e $ENTRY,${ENDENTRY}d $CFGFILE |
---|
1611 | fi |
---|
1612 | |
---|
1613 | # Guardamos el número de línea de la entrada, que sera el final de la siguiente. |
---|
1614 | ENDENTRY=$ENTRY |
---|
1615 | done |
---|
1616 | } |
---|
1617 | |
---|
1618 | #/** |
---|
1619 | # ogBurgInstallMbr int_disk_GRUBCFG int_partition_GRUBCFG |
---|
1620 | #@param bolean_Check_Os_installed_and_Configure_2ndStage true | false[default] |
---|
1621 | #@brief Instala y actualiza el gestor grub en el MBR del disco duro donde se encuentra el fichero grub.cfg. Admite sistemas Windows. |
---|
1622 | #@param int_disk_SecondStage |
---|
1623 | #@param int_part_SecondStage |
---|
1624 | #@param bolean_Check_Os_installed_and_Configure_2ndStage true | false[default] |
---|
1625 | #@return |
---|
1626 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1627 | #@exception OG_ERR_PARTITION Partición no soportada |
---|
1628 | #@version 1.1.0 - Primeras pruebas instalando BURG. Codigo basado en el ogGrubInstallMBR. |
---|
1629 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1630 | #@date 2017-06-23 |
---|
1631 | #@version 1.1.0 - Redirección del proceso de copiado de archivos y de la instalacion del binario |
---|
1632 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1633 | #@date 2018-01-21 |
---|
1634 | #@version 1.1.0 - Refactorizar fichero de configuacion |
---|
1635 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1636 | #@date 2018-01-24 |
---|
1637 | #@version 1.1.1 - Se incluye comentarios en codigo para autodocuemtnacion con Doxygen |
---|
1638 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
1639 | #@date 2018-07-05 |
---|
1640 | #*/ ## |
---|
1641 | |
---|
1642 | function ogBurgInstallMbr () |
---|
1643 | { |
---|
1644 | |
---|
1645 | # Variables locales. |
---|
1646 | local BINARYAVAILABLE PART DISK DEVICE MOUNTDISK FIRSTAGE SECONSTAGE PREFIXSECONDSTAGE CHECKOS KERNELPARAM BACKUPNAME FILECFG |
---|
1647 | |
---|
1648 | # Si se solicita, mostrar ayuda. |
---|
1649 | if [ "$*" == "help" ]; then |
---|
1650 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage \"param param \" " \ |
---|
1651 | "$FUNCNAME 1 1 FALSE " \ |
---|
1652 | "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" " |
---|
1653 | return |
---|
1654 | fi |
---|
1655 | |
---|
1656 | # Error si no se reciben 2 parametros. |
---|
1657 | [ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
1658 | |
---|
1659 | #Error si no tenemos el binario burg |
---|
1660 | BINARYAVAILABLE=$(burg-install -v &>/dev/null && echo "YES" ||echo "NO") |
---|
1661 | if [ "$BINARYAVAILABLE" == NO ]; then |
---|
1662 | if [ -e $OGLIB/burg/burg.tgz ]; then |
---|
1663 | cd / ; tar xzvf $OGLIB/burg/burg.tgz --strip 1 &>/dev/null |
---|
1664 | else |
---|
1665 | return $(ogRaiseError $OG_ERR_NOTEXEC "Binary burg not found"; echo $?) |
---|
1666 | fi |
---|
1667 | fi |
---|
1668 | |
---|
1669 | DISK=$1; PART=$2; |
---|
1670 | CHECKOS=${3:-"FALSE"} |
---|
1671 | KERNELPARAM=$4 |
---|
1672 | BACKUPNAME=".backup.og" |
---|
1673 | |
---|
1674 | #Controlar disco no uefi |
---|
1675 | ogIsEfiActive && return $(ogRaiseError $OG_ERR_NOTBIOS " : grub4dos solo soporta PC con bios legacy"; echo $?) |
---|
1676 | #Controlar particionado tipo msdos |
---|
1677 | ogCheckStringInGroup $(ogGetPartitionTableType $DISK) "MSDOS" || return $(ogRaiseError $OG_ERR_NOMSDOS ": grub2dos requiere particionado tipo MSDOS"; echo $?) |
---|
1678 | #Controlar existencia de disco y particion |
---|
1679 | DEVICE=$(ogDiskToDev $DISK) || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
1680 | MOUNTDISK=$(ogMount $DISK $PART) || ogRaiseError $OG_ERR_PARTITION "$MSG_ERROR " || return $? |
---|
1681 | #Controlar particion segunda etapa del burg |
---|
1682 | ogCheckStringInGroup $(ogGetFsType $DISK $PART) "CACHE EXT4 EXT3 EXT2" || return $(ogRaiseError $OG_ERR_PARTITION "burg.cfg soporta solo particiones linux"; echo $?) |
---|
1683 | #Controlar acceso de escritura a la particion segunda etapa del burg |
---|
1684 | ogIsReadonly $DISK $PART && return $(ogRaiseError $OG_ERR_NOTWRITE ": $DISK $PART" || echo $?) |
---|
1685 | |
---|
1686 | #Asigar la primera etapa del grub en el primer disco duro |
---|
1687 | FIRSTSTAGE=$(ogDiskToDev 1) |
---|
1688 | #Localizar disco segunda etapa del grub |
---|
1689 | SECONDSTAGE=$(ogMount $DISK $PART) |
---|
1690 | |
---|
1691 | #Preparar el directorio principal de la segunda etapa (y copia los binarios) |
---|
1692 | [ -d ${SECONDSTAGE}/boot/burg/ ] || mkdir -p ${SECONDSTAGE}/boot/burg/; cp -prv /boot/burg/* ${SECONDSTAGE}/boot/burg/ 2>&1>/dev/null; cp -prv $OGLIB/burg/themes ${SECONDSTAGE}/boot/burg/ 2>&1>/dev/null; #*/ ## (comentario Dogygen) #*/ ## (comentario Dogygen) |
---|
1693 | #Copiar el tema de opengnsys |
---|
1694 | mkdir -p ${SECONDSTAGE}/boot/burg/themes/OpenGnsys |
---|
1695 | cp -prv "$OGLIB/burg/themes" "${SECONDSTAGE}/boot/burg/" 2>&1>/dev/null |
---|
1696 | |
---|
1697 | # No configurar la segunda etapa (grub.cfg). Parámetro FALSE |
---|
1698 | if [ -f ${SECONDSTAGE}/boot/burg/burg.cfg -o -f ${SECONDSTAGE}/boot/burg/burg.cfg$BACKUPNAME ]; |
---|
1699 | then |
---|
1700 | if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ] |
---|
1701 | then |
---|
1702 | burg-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE 2>&1>/dev/null |
---|
1703 | return $? |
---|
1704 | fi |
---|
1705 | fi |
---|
1706 | |
---|
1707 | # Configurrar la segunda etapa (burg.cfg) == tercer parámetro TRUE |
---|
1708 | |
---|
1709 | #llamar a updateBootCache para que aloje la primera fase del ogLive |
---|
1710 | updateBootCache |
---|
1711 | |
---|
1712 | #Configur la sintaxis grub para evitar menus de "recovery" en el OGLive |
---|
1713 | echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub |
---|
1714 | echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub |
---|
1715 | |
---|
1716 | #Preparar configuración segunda etapa: crear ubicacion |
---|
1717 | mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/burg/ |
---|
1718 | #Preparar configuración segunda etapa: crear cabecera del fichero |
---|
1719 | FILECFG=${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/burg/burg.cfg |
---|
1720 | #/* ## (comentario Dogygen) |
---|
1721 | cat > "$FILECFG" << EOF |
---|
1722 | |
---|
1723 | set theme_name=OpenGnsys |
---|
1724 | set gfxmode=1024x768 |
---|
1725 | |
---|
1726 | |
---|
1727 | set locale_dir=(\$root)/boot/burg/locale |
---|
1728 | |
---|
1729 | set default=0 |
---|
1730 | set timeout=25 |
---|
1731 | set lang=es |
---|
1732 | |
---|
1733 | |
---|
1734 | insmod ext2 |
---|
1735 | insmod gettext |
---|
1736 | |
---|
1737 | |
---|
1738 | |
---|
1739 | |
---|
1740 | if [ -s \$prefix/burgenv ]; then |
---|
1741 | load_env |
---|
1742 | fi |
---|
1743 | |
---|
1744 | |
---|
1745 | |
---|
1746 | if [ \${prev_saved_entry} ]; then |
---|
1747 | set saved_entry=\${prev_saved_entry} |
---|
1748 | save_env saved_entry |
---|
1749 | set prev_saved_entry= |
---|
1750 | save_env prev_saved_entry |
---|
1751 | set boot_once=true |
---|
1752 | fi |
---|
1753 | |
---|
1754 | function savedefault { |
---|
1755 | if [ -z \${boot_once} ]; then |
---|
1756 | saved_entry=\${chosen} |
---|
1757 | save_env saved_entry |
---|
1758 | fi |
---|
1759 | } |
---|
1760 | function select_menu { |
---|
1761 | if menu_popup -t template_popup theme_menu ; then |
---|
1762 | free_config template_popup template_subitem menu class screen |
---|
1763 | load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name} |
---|
1764 | save_env theme_name |
---|
1765 | menu_refresh |
---|
1766 | fi |
---|
1767 | } |
---|
1768 | |
---|
1769 | function toggle_fold { |
---|
1770 | if test -z $theme_fold ; then |
---|
1771 | set theme_fold=1 |
---|
1772 | else |
---|
1773 | set theme_fold= |
---|
1774 | fi |
---|
1775 | save_env theme_fold |
---|
1776 | menu_refresh |
---|
1777 | } |
---|
1778 | function select_resolution { |
---|
1779 | if menu_popup -t template_popup resolution_menu ; then |
---|
1780 | menu_reload_mode |
---|
1781 | save_env gfxmode |
---|
1782 | fi |
---|
1783 | } |
---|
1784 | |
---|
1785 | |
---|
1786 | if test -f \${prefix}/themes/\${theme_name}/theme ; then |
---|
1787 | insmod coreui |
---|
1788 | menu_region.text |
---|
1789 | load_string '+theme_menu { -OpenGnsys { command="set theme_name=OpenGnsys" }}' |
---|
1790 | load_config \${prefix}/themes/conf.d/10_hotkey |
---|
1791 | load_config \${prefix}/themes/\${theme_name}/theme \${prefix}/themes/custom/theme_\${theme_name} |
---|
1792 | insmod vbe |
---|
1793 | insmod png |
---|
1794 | insmod jpeg |
---|
1795 | set gfxfont="Unifont Regular 16" |
---|
1796 | menu_region.gfx |
---|
1797 | vmenu resolution_menu |
---|
1798 | controller.ext |
---|
1799 | fi |
---|
1800 | |
---|
1801 | |
---|
1802 | EOF |
---|
1803 | #*/ ## (comentario Dogygen) |
---|
1804 | |
---|
1805 | #Preparar configuración segunda etapa: crear entrada del sistema operativo |
---|
1806 | grubSyntax "$KERNELPARAM" >> "$FILECFG" |
---|
1807 | #Instalar el burg |
---|
1808 | burg-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE 2>&1>/dev/null |
---|
1809 | } |
---|
1810 | |
---|
1811 | #/** |
---|
1812 | # ogGrubDefaultEntry int_disk_GRUGCFG int_partition_GRUBCFG int_disk_default_entry int_npartition_default_entry |
---|
1813 | #@brief ver ogBootLoaderDefaultEntry |
---|
1814 | #@see ogBootLoaderDefaultEntry |
---|
1815 | #*/ ## |
---|
1816 | function ogGrubDefaultEntry () |
---|
1817 | { |
---|
1818 | # Si se solicita, mostrar ayuda. |
---|
1819 | if [ "$*" == "help" ]; then |
---|
1820 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_default_entry int_npartition_default_entry" \ |
---|
1821 | "$FUNCNAME 1 6 1 1" |
---|
1822 | return |
---|
1823 | fi |
---|
1824 | ogBootLoaderDefaultEntry $@ |
---|
1825 | return $? |
---|
1826 | } |
---|
1827 | |
---|
1828 | #/** |
---|
1829 | # ogBurgDefaultEntry int_disk_BURGCFG int_partition_BURGCFG int_disk_default_entry int_npartition_default_entry |
---|
1830 | #@brief ver ogBootLoaderDefaultEntry |
---|
1831 | #@see ogBootLoaderDefaultEntry |
---|
1832 | #*/ ## |
---|
1833 | function ogBurgDefaultEntry () |
---|
1834 | { |
---|
1835 | # Si se solicita, mostrar ayuda. |
---|
1836 | if [ "$*" == "help" ]; then |
---|
1837 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_disk_default_entry int_npartition_default_entry" \ |
---|
1838 | "$FUNCNAME 1 6 1 1" |
---|
1839 | return |
---|
1840 | fi |
---|
1841 | ogBootLoaderDefaultEntry $@ |
---|
1842 | return $? |
---|
1843 | } |
---|
1844 | |
---|
1845 | |
---|
1846 | #/** |
---|
1847 | # ogRefindDefaultEntry int_disk_default_entry int_npartition_default_entry |
---|
1848 | #@brief ver ogBootLoaderDefaultEntry |
---|
1849 | #@see ogBootLoaderDefaultEntry |
---|
1850 | #*/ ## |
---|
1851 | function ogRefindDefaultEntry () |
---|
1852 | { |
---|
1853 | local EFIDISK EFIPART |
---|
1854 | # Si se solicita, mostrar ayuda. |
---|
1855 | if [ "$*" == "help" ]; then |
---|
1856 | ogHelp "$FUNCNAME" "$FUNCNAME int_disk_default_entry int_npartition_default_entry" \ |
---|
1857 | "$FUNCNAME 1 1" |
---|
1858 | return |
---|
1859 | fi |
---|
1860 | |
---|
1861 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
1862 | ogBootLoaderDefaultEntry $EFIDISK $EFIPART $@ |
---|
1863 | return $? |
---|
1864 | } |
---|
1865 | |
---|
1866 | #/** |
---|
1867 | # ogBootLoaderDefaultEntry int_disk_CFG int_partition_CFG int_disk_default_entry int_npartition_default_entry |
---|
1868 | #@brief Configura la entrada por defecto de Burg |
---|
1869 | #@param int_disk_SecondStage |
---|
1870 | #@param int_part_SecondStage |
---|
1871 | #@param int_disk_default_entry |
---|
1872 | #@param int_part_default_entry |
---|
1873 | #@return |
---|
1874 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1875 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
1876 | #@exception OG_ERR_OUTOFLIMIT Param $3 no es entero. |
---|
1877 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: burg.cfg. |
---|
1878 | #@version 1.1.0 - Define la entrada por defecto del Burg |
---|
1879 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1880 | #@date 2017-08-09 |
---|
1881 | #@version 1.1 Se generaliza la función para grub y burg |
---|
1882 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
1883 | #@date 2018-01-04 |
---|
1884 | #*/ ## |
---|
1885 | function ogBootLoaderDefaultEntry () |
---|
1886 | { |
---|
1887 | |
---|
1888 | # Variables locales. |
---|
1889 | local PART FUNC DIRMOUNT LABEL CFGFILE DEFAULTENTRY MENUENTRY MSG |
---|
1890 | |
---|
1891 | # Si se solicita, mostrar ayuda. |
---|
1892 | if [ "$*" == "help" ]; then |
---|
1893 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubDefaultEntry, ogBurgDefaultEntry or ogRefindDefaultEntry." |
---|
1894 | return |
---|
1895 | fi |
---|
1896 | |
---|
1897 | # Nombre de la función que llama a esta. |
---|
1898 | FUNC="${FUNCNAME[@]:1}" |
---|
1899 | FUNC="${FUNC%%\ *}" |
---|
1900 | |
---|
1901 | # Error si no se reciben 3 parametros. |
---|
1902 | [ $# -eq 4 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage int_disk_default_entry int_partitions_default_entry" || return $? |
---|
1903 | |
---|
1904 | # Error si no puede montar sistema de archivos. |
---|
1905 | DIRMOUNT=$(ogMount $1 $2) || return $? |
---|
1906 | |
---|
1907 | # Comprobamos que exista fichero de configuración |
---|
1908 | # La función debe ser llamanda desde ogGrubDefaultEntry, ogBurgDefaultEntry or ogRefindDefaultEntry. |
---|
1909 | case "$FUNC" in |
---|
1910 | ogGrubDefaultEntry) |
---|
1911 | CFGFILE="$DIRMOUNT/boot/grubMBR/boot/grub/grub.cfg" |
---|
1912 | ;; |
---|
1913 | ogBurgDefaultEntry) |
---|
1914 | CFGFILE="$DIRMOUNT/boot/burg/burg.cfg" |
---|
1915 | ;; |
---|
1916 | ogRefindDefaultEntry) |
---|
1917 | CFGFILE="$DIRMOUNT/EFI/refind/refind.conf" |
---|
1918 | ;; |
---|
1919 | *) |
---|
1920 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubDefaultEntry, ogBurgDefaultEntry or ogRefindDefaultEntry." |
---|
1921 | return $? |
---|
1922 | ;; |
---|
1923 | esac |
---|
1924 | |
---|
1925 | # Error si no existe archivo de configuración |
---|
1926 | [ -r $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
1927 | |
---|
1928 | # Dispositivo |
---|
1929 | if [ "$(basename $CFGFILE)" == "refind.conf" ]; then |
---|
1930 | LABEL=$(printf "Part-%02d-%02d" $3 $4) |
---|
1931 | else |
---|
1932 | LABEL=$(ogDiskToDev $3 $4) |
---|
1933 | fi |
---|
1934 | |
---|
1935 | # Número de línea de la entrada por defecto en CFGFILE (primera de la partición). |
---|
1936 | DEFAULTENTRY=$(grep -n -m 1 menuentry.*$LABEL $CFGFILE| cut -d: -f1) |
---|
1937 | |
---|
1938 | # Si no hay entradas para borrar me salgo con aviso |
---|
1939 | [ "$DEFAULTENTRY" != "" ] || ogRaiseError session log $OG_ERR_NOTFOUND "No menuentry $LABEL" || return $? |
---|
1940 | |
---|
1941 | # Número de la de linea por defecto en el menú de usuario |
---|
1942 | MENUENTRY="$(grep -n -e menuentry $CFGFILE| cut -d: -f1 | grep -n $DEFAULTENTRY |cut -d: -f1)" |
---|
1943 | |
---|
1944 | if [ "$(basename $CFGFILE)" == "refind.conf" ]; then |
---|
1945 | sed -i /default_selection.*$/d $CFGFILE |
---|
1946 | sed -i "1 i\default_selection $MENUENTRY" $CFGFILE |
---|
1947 | else |
---|
1948 | # En grub y burg las líneas empiezan a contar desde cero |
---|
1949 | let MENUENTRY=$MENUENTRY-1 |
---|
1950 | sed --regexp-extended -i s/"set default=\"?[0-9]*\"?$"/"set default=\"$MENUENTRY\""/g $CFGFILE |
---|
1951 | fi |
---|
1952 | MSG="MSG_HELP_$FUNC" |
---|
1953 | echo "${!MSG%%\.}: $@" |
---|
1954 | } |
---|
1955 | |
---|
1956 | #/** |
---|
1957 | # ogGrubOgliveDefaultEntry num_disk num_part |
---|
1958 | #@brief ver ogBootLoaderOgliveDefaultEntry |
---|
1959 | #@see ogBootLoaderOgliveDefaultEntry |
---|
1960 | #*/ ## |
---|
1961 | function ogGrubOgliveDefaultEntry () |
---|
1962 | { |
---|
1963 | # Si se solicita, mostrar ayuda. |
---|
1964 | if [ "$*" == "help" ]; then |
---|
1965 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage" \ |
---|
1966 | "$FUNCNAME 1 6" |
---|
1967 | return |
---|
1968 | fi |
---|
1969 | ogBootLoaderOgliveDefaultEntry $@ |
---|
1970 | return $? |
---|
1971 | } |
---|
1972 | |
---|
1973 | #/** |
---|
1974 | # ogBurgOgliveDefaultEntry num_disk num_part |
---|
1975 | #@brief ver ogBootLoaderOgliveDefaultEntry |
---|
1976 | #@see ogBootLoaderOgliveDefaultEntry |
---|
1977 | #*/ ## |
---|
1978 | function ogBurgOgliveDefaultEntry () |
---|
1979 | { |
---|
1980 | # Si se solicita, mostrar ayuda. |
---|
1981 | if [ "$*" == "help" ]; then |
---|
1982 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage" \ |
---|
1983 | "$FUNCNAME 1 6" |
---|
1984 | return |
---|
1985 | fi |
---|
1986 | ogBootLoaderOgliveDefaultEntry $@ |
---|
1987 | return $? |
---|
1988 | } |
---|
1989 | |
---|
1990 | |
---|
1991 | #/** |
---|
1992 | # ogRefindOgliveDefaultEntry |
---|
1993 | #@brief ver ogBootLoaderOgliveDefaultEntry |
---|
1994 | #@see ogBootLoaderOgliveDefaultEntry |
---|
1995 | #*/ ## |
---|
1996 | function ogRefindOgliveDefaultEntry () |
---|
1997 | { |
---|
1998 | local EFIDISK EFIPART |
---|
1999 | # Si se solicita, mostrar ayuda. |
---|
2000 | if [ "$*" == "help" ]; then |
---|
2001 | ogHelp "$FUNCNAME" "$FUNCNAME" \ |
---|
2002 | "$FUNCNAME" |
---|
2003 | return |
---|
2004 | fi |
---|
2005 | |
---|
2006 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
2007 | ogBootLoaderOgliveDefaultEntry $EFIDISK $EFIPART |
---|
2008 | return $? |
---|
2009 | } |
---|
2010 | |
---|
2011 | |
---|
2012 | #/** |
---|
2013 | # ogBootLoaderOgliveDefaultEntry |
---|
2014 | #@brief Configura la entrada de ogLive como la entrada por defecto de Burg. |
---|
2015 | #@param int_disk_SecondStage |
---|
2016 | #@param int_part_SecondStage |
---|
2017 | #@return |
---|
2018 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2019 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2020 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: burg.cfg. |
---|
2021 | #@exception OG_ERR_NOTFOUND Entrada de OgLive no encontrada en burg.cfg. |
---|
2022 | #@version 1.1.0 - Primeras pruebas con Burg |
---|
2023 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
2024 | #@date 2017-08-09 |
---|
2025 | #@version 1.1 Se generaliza la función para grub y burg |
---|
2026 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
2027 | #@date 2018-01-04 |
---|
2028 | #*/ ## |
---|
2029 | function ogBootLoaderOgliveDefaultEntry () |
---|
2030 | { |
---|
2031 | |
---|
2032 | # Variables locales. |
---|
2033 | local FUNC PART CFGFILE NUMENTRY MSG |
---|
2034 | |
---|
2035 | # Si se solicita, mostrar ayuda. |
---|
2036 | if [ "$*" == "help" ]; then |
---|
2037 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubOgliveDefaultEntry, ogBurgOgliveDefaultEntry or ogRefindOgliveDefaultEntry" \ |
---|
2038 | return |
---|
2039 | fi |
---|
2040 | |
---|
2041 | # Nombre de la función que llama a esta. |
---|
2042 | FUNC="${FUNCNAME[@]:1}" |
---|
2043 | FUNC="${FUNC%%\ *}" |
---|
2044 | |
---|
2045 | # Error si no se reciben 2 parametros. |
---|
2046 | [ $# -eq 2 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage" || return $? |
---|
2047 | |
---|
2048 | # Error si no puede montar sistema de archivos. |
---|
2049 | PART=$(ogMount $1 $2) || return $? |
---|
2050 | # La función debe ser llamanda desde ogGrubOgliveDefaultEntry, ogBurgOgliveDefaultEntry or ogRefindOgliveDefaultEntry. |
---|
2051 | case "$FUNC" in |
---|
2052 | ogGrubOgliveDefaultEntry) |
---|
2053 | CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" |
---|
2054 | ;; |
---|
2055 | ogBurgOgliveDefaultEntry) |
---|
2056 | CFGFILE="$PART/boot/burg/burg.cfg" |
---|
2057 | ;; |
---|
2058 | ogRefindOgliveDefaultEntry) |
---|
2059 | CFGFILE="$PART/EFI/refind/refind.conf" |
---|
2060 | ;; |
---|
2061 | *) |
---|
2062 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubOgliveDefaultEntry, ogBurgOgliveDefaultEntry or ogRefindOgliveDefaultEntry." |
---|
2063 | return $? |
---|
2064 | ;; |
---|
2065 | esac |
---|
2066 | |
---|
2067 | # Comprobamos que exista fichero de configuración |
---|
2068 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2069 | |
---|
2070 | # Detectamos cual es la entrada de ogLive |
---|
2071 | NUMENTRY=$(grep ^menuentry $CFGFILE| grep -n "OpenGnsys Live"|cut -d: -f1) |
---|
2072 | |
---|
2073 | # Si no existe entrada de ogLive nos salimos |
---|
2074 | [ -z "$NUMENTRY" ] && (ogRaiseError $OG_ERR_NOTFOUND "menuentry OpenGnsys Live in $CFGFILE" || return $?) |
---|
2075 | |
---|
2076 | if [ "$(basename $CFGFILE)" == "refind.conf" ]; then |
---|
2077 | sed -i /default_selection.*$/d $CFGFILE |
---|
2078 | |
---|
2079 | sed -i "1 i\default_selection $NUMENTRY" $CFGFILE |
---|
2080 | else |
---|
2081 | let NUMENTRY=$NUMENTRY-1 |
---|
2082 | sed --regexp-extended -i s/"set default=\"?[0-9]+\"?"/"set default=\"$NUMENTRY\""/g $CFGFILE |
---|
2083 | fi |
---|
2084 | |
---|
2085 | MSG="MSG_HELP_$FUNC" |
---|
2086 | echo "${!MSG%%\.}: $@" |
---|
2087 | } |
---|
2088 | |
---|
2089 | |
---|
2090 | #/** |
---|
2091 | # ogGrubSecurity int_disk_GRUBCFG int_partition_GRUBCFG [user] [password] |
---|
2092 | #@brief Configura grub.cfg para que sólo permita editar entrada o acceder a línea de comandos al usuario especificado |
---|
2093 | #@param int_disk_SecondStage |
---|
2094 | #@param int_part_SecondStage |
---|
2095 | #@param user (default root) |
---|
2096 | #@param password (default "", no puede entrar) |
---|
2097 | #@return (nada) |
---|
2098 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2099 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar (ogMount). |
---|
2100 | #@exception OG_ERR_NOTFOUND No encuentra archivo de configuración del grub. |
---|
2101 | #@author Irina Gomez, ETSII Universidad de Sevilla |
---|
2102 | #@date 2019-12-17 |
---|
2103 | #*/ ## |
---|
2104 | function ogGrubSecurity () |
---|
2105 | { |
---|
2106 | # Variables locales. |
---|
2107 | local SECONDSTAGE GRUBGFC FILE USER PASSWD ENCRYPTPASSWD |
---|
2108 | |
---|
2109 | # Si se solicita, mostrar ayuda. |
---|
2110 | if [ "$*" == "help" ]; then |
---|
2111 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [USER] [PASSWORD]" \ |
---|
2112 | "$FUNCNAME 1 1 " \ |
---|
2113 | "$FUNCNAME 1 2 user clave" |
---|
2114 | return |
---|
2115 | fi |
---|
2116 | |
---|
2117 | # Error si no se reciben 2 parámetros. |
---|
2118 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [USER] [PASSWORD]"|| return $? |
---|
2119 | |
---|
2120 | #localizar disco segunda etapa del grub |
---|
2121 | SECONDSTAGE=$(ogMount "$1" "$2") || return $? |
---|
2122 | |
---|
2123 | GRUBGFC=$(ls $SECONDSTAGE/{,boot/}{{grubMBR,grubPARTITION}/boot/,}{grub{,2},{,efi/}EFI/*}/{menu.lst,grub.cfg,grub.cfg.backup.og} 2>/dev/null) |
---|
2124 | |
---|
2125 | # comprobamos que exista el archivo de configuración. |
---|
2126 | [ -n "$GRUBGFC" ] || ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" || return $? |
---|
2127 | |
---|
2128 | USER=${3:-root} |
---|
2129 | PASSWD=${4:-""} |
---|
2130 | |
---|
2131 | ENCRYPTPASSWD=$(echo -e "$PASSWD\n$PASSWD"|grub-mkpasswd-pbkdf2|sed -e 1,2d -e s/^.*grub/grub/) |
---|
2132 | |
---|
2133 | for FILE in $GRUBGFC; do |
---|
2134 | # Eliminamos configuración anterior |
---|
2135 | sed -i -e /superusers/d -e /password_pbkdf2/d $FILE |
---|
2136 | |
---|
2137 | # Configuramos grub.cfg para que sólo permita editar o entrar en línea de comandos al usuario especificado |
---|
2138 | [ "$PASSWD" == "" ] || sed -i "1i\password_pbkdf2 $USER $ENCRYPTPASSWD" $FILE |
---|
2139 | sed -i "1i\set superusers=\"$USER\"" $FILE |
---|
2140 | |
---|
2141 | # Permitimos que se seleccionen las entradas |
---|
2142 | sed -i /"menuentry "/s/"{"/"--unrestricted {"/ $FILE |
---|
2143 | done |
---|
2144 | } |
---|
2145 | |
---|
2146 | |
---|
2147 | #/** |
---|
2148 | # ogGrubSetTheme num_disk num_part str_theme |
---|
2149 | #@brief ver ogBootLoaderSetTheme |
---|
2150 | #@see ogBootLoaderSetTheme |
---|
2151 | #*/ ## |
---|
2152 | function ogGrubSetTheme () |
---|
2153 | { |
---|
2154 | # Si se solicita, mostrar ayuda. |
---|
2155 | if [ "$*" == "help" ]; then |
---|
2156 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_themeName" \ |
---|
2157 | "$FUNCNAME 1 4 ThemeBasic"\ |
---|
2158 | "$FUNCNAME \$(ogFindCache) ThemeBasic" |
---|
2159 | return |
---|
2160 | fi |
---|
2161 | ogBootLoaderSetTheme $@ |
---|
2162 | return $? |
---|
2163 | } |
---|
2164 | |
---|
2165 | #/** |
---|
2166 | # ogBurgSetTheme num_disk num_part str_theme |
---|
2167 | #@brief ver ogBootLoaderSetTheme |
---|
2168 | #@see ogBootLoaderSetTheme |
---|
2169 | #*/ ## |
---|
2170 | function ogBurgSetTheme () |
---|
2171 | { |
---|
2172 | # Si se solicita, mostrar ayuda. |
---|
2173 | if [ "$*" == "help" ]; then |
---|
2174 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_themeName" \ |
---|
2175 | "$FUNCNAME 1 4 ThemeBasic" \ |
---|
2176 | "$FUNCNAME \$(ogFindCache) ThemeBasic" |
---|
2177 | echo "Temas disponibles:\ $(ls $OGCAC/boot/burg/themes/)" |
---|
2178 | |
---|
2179 | return |
---|
2180 | fi |
---|
2181 | ogBootLoaderSetTheme $@ |
---|
2182 | return $? |
---|
2183 | } |
---|
2184 | |
---|
2185 | |
---|
2186 | #/** |
---|
2187 | # ogRefindSetTheme str_theme |
---|
2188 | #@brief ver ogBootLoaderSetTheme |
---|
2189 | #@see ogBootLoaderSetTheme |
---|
2190 | #*/ ## |
---|
2191 | function ogRefindSetTheme () { |
---|
2192 | local PART DIRTHEME CFGFILE |
---|
2193 | # Si se solicita, mostrar ayuda. |
---|
2194 | if [ "$*" == "help" ]; then |
---|
2195 | ogHelp "$FUNCNAME" "$FUNCNAME str_themeName" \ |
---|
2196 | "$FUNCNAME ThemeBasic" |
---|
2197 | echo -e "\nThemes in $OGLIB/refind:\n$(ls $OGLIB/refind/themes/ 2>/dev/null)" |
---|
2198 | |
---|
2199 | return |
---|
2200 | fi |
---|
2201 | |
---|
2202 | # Detectamos partición ESP |
---|
2203 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
2204 | |
---|
2205 | PART=$(ogMount $EFIDISK $EFIPART) || return $? |
---|
2206 | DIRTHEME="$PART/EFI/refind/themes" |
---|
2207 | CFGFILE="$PART/EFI/refind/refind.conf" |
---|
2208 | |
---|
2209 | # Para utilizar ogBootLoaderSetTheme es necesario la entrada set theme_name |
---|
2210 | if [ -f $CFGFILE ]; then |
---|
2211 | sed -i '1 i\set theme_name=none' $CFGFILE |
---|
2212 | else |
---|
2213 | ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2214 | fi |
---|
2215 | # Creamos el directorio para los temas |
---|
2216 | [ -d $DIRTHEME ] || mkdir $DIRTHEME |
---|
2217 | |
---|
2218 | ogBootLoaderSetTheme $EFIDISK $EFIPART $@ |
---|
2219 | return $? |
---|
2220 | } |
---|
2221 | |
---|
2222 | |
---|
2223 | #/** |
---|
2224 | # ogBootLoaderSetTheme |
---|
2225 | #@brief asigna un tema al BURG |
---|
2226 | #@param int_disk_SecondStage |
---|
2227 | #@param int_part_SecondStage |
---|
2228 | #@param str_theme_name |
---|
2229 | #@return |
---|
2230 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2231 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2232 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg refind.conf. |
---|
2233 | #@exception OG_ERR_NOTFOUND Entrada deltema no encontrada en burg.cfg. |
---|
2234 | #@exception OG_ERR_NOTFOUND Fichero de configuración del tema no encontrado: theme.conf (sólo refind). |
---|
2235 | #@note El tema debe situarse en OGLIB/BOOTLOADER/themes |
---|
2236 | #@version 1.1.0 - Primeras pruebas con Burg. grub no soportado. |
---|
2237 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
2238 | #@date 2018-01-24 |
---|
2239 | #@version 1.1.1 - Soporta rEFInd (ticket #802 #888). |
---|
2240 | #@author Irina Gomez. Universidad de Sevilla |
---|
2241 | #@date 2019-03-22 |
---|
2242 | #*/ ## |
---|
2243 | function ogBootLoaderSetTheme () |
---|
2244 | { |
---|
2245 | |
---|
2246 | # Variables locales. |
---|
2247 | local FUNC PART CFGFILE THEME NEWTHEME BOOTLOADER MSG NEWTHEMECFG |
---|
2248 | |
---|
2249 | # Si se solicita, mostrar ayuda. |
---|
2250 | if [ "$*" == "help" ]; then |
---|
2251 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetTheme, ogBurgSetTheme or ogRefindSetTheme." |
---|
2252 | return |
---|
2253 | fi |
---|
2254 | |
---|
2255 | |
---|
2256 | NEWTHEME="$3" |
---|
2257 | |
---|
2258 | # Nombre de la función que llama a esta. |
---|
2259 | FUNC="${FUNCNAME[@]:1}" |
---|
2260 | FUNC="${FUNC%%\ *}" |
---|
2261 | |
---|
2262 | |
---|
2263 | |
---|
2264 | # Error si no se reciben 3 parametros. |
---|
2265 | [ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_themeName" || return $? |
---|
2266 | |
---|
2267 | # Error si no puede montar sistema de archivos. |
---|
2268 | PART=$(ogMount $1 $2) || return $? |
---|
2269 | # La función debe ser llamanda desde ogGrubSetTheme, ogBurgSetTheme or ogRefindSetTheme. |
---|
2270 | case "$FUNC" in |
---|
2271 | ogGrubSetTheme) |
---|
2272 | BOOTLOADER="grub" |
---|
2273 | BOOTLOADERDIR="boot/grubMBR" |
---|
2274 | CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" |
---|
2275 | ogRaiseError $OG_ERR_FORMAT "ogGrubSetTheme not sopported" |
---|
2276 | return $? |
---|
2277 | ;; |
---|
2278 | ogBurgSetTheme) |
---|
2279 | BOOTLOADER="burg" |
---|
2280 | BOOTLOADERDIR="boot/burg" |
---|
2281 | CFGFILE="$PART/boot/burg/burg.cfg" |
---|
2282 | ;; |
---|
2283 | ogRefindSetTheme) |
---|
2284 | BOOTLOADER="refind" |
---|
2285 | BOOTLOADERDIR="EFI/refind" |
---|
2286 | CFGFILE="$PART/EFI/refind/refind.conf" |
---|
2287 | ;; |
---|
2288 | *) |
---|
2289 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetTheme, ogBurgSetTheme or ogRefindSetTheme." |
---|
2290 | return $? |
---|
2291 | ;; |
---|
2292 | esac |
---|
2293 | |
---|
2294 | # Comprobamos que exista fichero de configuración |
---|
2295 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2296 | |
---|
2297 | # Detectamos cual es el tema asignado |
---|
2298 | THEME=$(grep "set theme_name=" $CFGFILE | grep ^set | cut -d= -f2) |
---|
2299 | # Si no existe entrada de theme_name nos salimos |
---|
2300 | [ -z "$THEME" ] && (ogRaiseError $OG_ERR_NOTFOUND "theme_name in $CFGFILE" || return $?) |
---|
2301 | |
---|
2302 | #Actualizamos el tema del servidor a la particion |
---|
2303 | if [ -d $OGLIB/$BOOTLOADER/themes/$NEWTHEME ]; then |
---|
2304 | # Para refind es necesario que exista theme.conf en el directorio del tema. |
---|
2305 | if [ "$BOOTLOADER" == "refind" ]; then |
---|
2306 | NEWTHEMECFG="$OGLIB/$BOOTLOADER/themes/$NEWTHEME/theme.conf" |
---|
2307 | [ -f $NEWTHEMECFG ] || ogRaiserError $OG_ERR_NOTFOUND "theme.conf" || return $? |
---|
2308 | grep -v "^#" $NEWTHEMECFG >> $CFGFILE |
---|
2309 | # eliminamos "set theme" es de grub y no de refind |
---|
2310 | sed -i '/theme_name/d' $CFGFILE |
---|
2311 | fi |
---|
2312 | cp -pr $OGLIB/$BOOTLOADER/themes/$NEWTHEME $PART/$BOOTLOADERDIR/themes/ |
---|
2313 | fi |
---|
2314 | |
---|
2315 | #Verificamos que el tema esta en la particion |
---|
2316 | if ! [ -d $PART/$BOOTLOADERDIR/themes/$NEWTHEME ]; then |
---|
2317 | ogRaiseError $OG_ERR_NOTFOUND "theme_name=$NEWTHEME in $PART/$BOOTLOADERDIR/themes/" || return $? |
---|
2318 | fi |
---|
2319 | |
---|
2320 | #Cambiamos la entrada el fichero de configuración. |
---|
2321 | sed --regexp-extended -i s/"set theme_name=$THEME"/"set theme_name=$NEWTHEME"/g $CFGFILE |
---|
2322 | |
---|
2323 | |
---|
2324 | } |
---|
2325 | |
---|
2326 | #/** |
---|
2327 | # ogGrubSetAdminKeys num_disk num_part str_theme |
---|
2328 | #@brief ver ogBootLoaderSetTheme |
---|
2329 | #@see ogBootLoaderSetTheme |
---|
2330 | #*/ ## |
---|
2331 | function ogGrubSetAdminKeys () |
---|
2332 | { |
---|
2333 | # Si se solicita, mostrar ayuda. |
---|
2334 | if [ "$*" == "help" ]; then |
---|
2335 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_bolean" \ |
---|
2336 | "$FUNCNAME 1 4 FALSE "\ |
---|
2337 | "$FUNCNAME \$(ogFindCache) ThemeBasic" |
---|
2338 | return |
---|
2339 | fi |
---|
2340 | ogBootLoaderSetAdminKeys $@ |
---|
2341 | return $? |
---|
2342 | } |
---|
2343 | |
---|
2344 | #/** |
---|
2345 | # ogBurgSetAdminKeys num_disk num_part str_bolean |
---|
2346 | #@brief ver ogBootLoaderSetAdminKeys |
---|
2347 | #@see ogBootLoaderSetAdminKeys |
---|
2348 | #*/ ## |
---|
2349 | function ogBurgSetAdminKeys () |
---|
2350 | { |
---|
2351 | # Si se solicita, mostrar ayuda. |
---|
2352 | if [ "$*" == "help" ]; then |
---|
2353 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_bolean" \ |
---|
2354 | "$FUNCNAME 1 4 TRUE" \ |
---|
2355 | "$FUNCNAME \$(ogFindCache) FALSE" |
---|
2356 | return |
---|
2357 | fi |
---|
2358 | ogBootLoaderSetAdminKeys $@ |
---|
2359 | return $? |
---|
2360 | } |
---|
2361 | |
---|
2362 | |
---|
2363 | |
---|
2364 | #/** |
---|
2365 | # ogBootLoaderSetAdminKeys |
---|
2366 | #@brief Activa/Desactica las teclas de administracion |
---|
2367 | #@param int_disk_SecondStage |
---|
2368 | #@param int_part_SecondStage |
---|
2369 | #@param Boolean TRUE/FALSE |
---|
2370 | #@return |
---|
2371 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2372 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2373 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg. |
---|
2374 | #@exception OG_ERR_NOTFOUND Entrada deltema no encontrada en burg.cfg. |
---|
2375 | #@version 1.1.0 - Primeras pruebas con Burg. grub no soportado. |
---|
2376 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
2377 | #@date 2018-01-24 |
---|
2378 | #*/ ## |
---|
2379 | function ogBootLoaderSetAdminKeys () |
---|
2380 | { |
---|
2381 | |
---|
2382 | # Variables locales. |
---|
2383 | local FUNC PART CFGFILE BOOTLOADER BOOTLOADERDIR CFGFILE MSG |
---|
2384 | |
---|
2385 | # Si se solicita, mostrar ayuda. |
---|
2386 | if [ "$*" == "help" ]; then |
---|
2387 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetSetAdminKeys ogBurgSetSetAdminKeys" |
---|
2388 | return |
---|
2389 | fi |
---|
2390 | |
---|
2391 | |
---|
2392 | # Nombre de la función que llama a esta. |
---|
2393 | FUNC="${FUNCNAME[@]:1}" |
---|
2394 | FUNC="${FUNC%%\ *}" |
---|
2395 | |
---|
2396 | |
---|
2397 | # Error si no se reciben 2 parametros. |
---|
2398 | [ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_bolean" || return $? |
---|
2399 | |
---|
2400 | # Error si no puede montar sistema de archivos. |
---|
2401 | PART=$(ogMount $1 $2) || return $? |
---|
2402 | # La función debe ser llamanda desde ogGrubSetAdminKeys or ogBurgSetAdminKeys. |
---|
2403 | case "$FUNC" in |
---|
2404 | ogGrubSetAdminKeys) |
---|
2405 | BOOTLOADER="grub" |
---|
2406 | BOOTLOADERDIR="grubMBR" |
---|
2407 | CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" |
---|
2408 | ogRaiseError $OG_ERR_FORMAT "ogGrubSetAdminKeys not sopported" |
---|
2409 | return $? |
---|
2410 | ;; |
---|
2411 | ogBurgSetAdminKeys) |
---|
2412 | BOOTLOADER="burg" |
---|
2413 | BOOTLOADERDIR="burg" |
---|
2414 | CFGFILE="$PART/boot/burg/burg.cfg" |
---|
2415 | ;; |
---|
2416 | *) |
---|
2417 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetAdminKeys" |
---|
2418 | return $? |
---|
2419 | ;; |
---|
2420 | esac |
---|
2421 | |
---|
2422 | |
---|
2423 | # Comprobamos que exista fichero de configuración |
---|
2424 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2425 | |
---|
2426 | |
---|
2427 | case "$3" in |
---|
2428 | true|TRUE) |
---|
2429 | [ -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 |
---|
2430 | ;; |
---|
2431 | false|FALSE) |
---|
2432 | [ -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 |
---|
2433 | ;; |
---|
2434 | *) |
---|
2435 | ogRaiseError $OG_ERR_FORMAT "str bolean unknow " |
---|
2436 | return $? |
---|
2437 | ;; |
---|
2438 | esac |
---|
2439 | } |
---|
2440 | |
---|
2441 | |
---|
2442 | |
---|
2443 | #/** |
---|
2444 | # ogGrubSetTimeOut num_disk num_part int_timeout_seconds |
---|
2445 | #@brief ver ogBootLoaderSetTimeOut |
---|
2446 | #@see ogBootLoaderSetTimeOut |
---|
2447 | #*/ ## |
---|
2448 | function ogGrubSetTimeOut () |
---|
2449 | { |
---|
2450 | # Si se solicita, mostrar ayuda. |
---|
2451 | if [ "$*" == "help" ]; then |
---|
2452 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage int_timeout_seconds" \ |
---|
2453 | "$FUNCNAME 1 4 50 "\ |
---|
2454 | "$FUNCNAME \$(ogFindCache) 50" |
---|
2455 | return |
---|
2456 | fi |
---|
2457 | ogBootLoaderSetTimeOut $@ |
---|
2458 | return $? |
---|
2459 | } |
---|
2460 | |
---|
2461 | #/** |
---|
2462 | # ogBurgSetTimeOut num_disk num_part str_bolean |
---|
2463 | #@brief ver ogBootLoaderSetTimeOut |
---|
2464 | #@see ogBootLoaderSetTimeOut |
---|
2465 | #*/ ## |
---|
2466 | function ogBurgSetTimeOut () |
---|
2467 | { |
---|
2468 | # Si se solicita, mostrar ayuda. |
---|
2469 | if [ "$*" == "help" ]; then |
---|
2470 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage str_timeout_seconds" \ |
---|
2471 | "$FUNCNAME 1 4 50" \ |
---|
2472 | "$FUNCNAME \$(ogFindCache) 50" |
---|
2473 | return |
---|
2474 | fi |
---|
2475 | ogBootLoaderSetTimeOut $@ |
---|
2476 | return $? |
---|
2477 | } |
---|
2478 | |
---|
2479 | |
---|
2480 | #/** |
---|
2481 | # ogRefindSetTimeOut int_timeout_second |
---|
2482 | #@brief ver ogBootLoaderSetTimeOut |
---|
2483 | #@see ogBootLoaderSetTimeOut |
---|
2484 | #*/ ## |
---|
2485 | function ogRefindSetTimeOut () |
---|
2486 | { |
---|
2487 | local EFIDISK EFIPART |
---|
2488 | # Si se solicita, mostrar ayuda. |
---|
2489 | if [ "$*" == "help" ]; then |
---|
2490 | ogHelp "$FUNCNAME" "$FUNCNAME int_timeout_seconds" \ |
---|
2491 | "$FUNCNAME 50" |
---|
2492 | return |
---|
2493 | fi |
---|
2494 | |
---|
2495 | read EFIDISK EFIPART <<< $(ogGetEsp) |
---|
2496 | ogBootLoaderSetTimeOut $EFIDISK $EFIPART $@ |
---|
2497 | return $? |
---|
2498 | } |
---|
2499 | |
---|
2500 | #/** |
---|
2501 | # ogBootLoaderSetTimeOut |
---|
2502 | #@brief Define el tiempo (segundos) que se muestran las opciones de inicio |
---|
2503 | #@param int_disk_SecondStage |
---|
2504 | #@param int_part_SecondStage |
---|
2505 | #@param int_timeout_seconds |
---|
2506 | #@return |
---|
2507 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2508 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2509 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg. |
---|
2510 | #@exception OG_ERR_NOTFOUND Entrada deltema no encontrada en burg.cfg. |
---|
2511 | #@version 1.1.0 - Primeras pruebas con Burg. GRUB solo si está instalado en MBR |
---|
2512 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
2513 | #@date 2018-01-24 |
---|
2514 | #*/ ## |
---|
2515 | function ogBootLoaderSetTimeOut () |
---|
2516 | { |
---|
2517 | |
---|
2518 | # Variables locales. |
---|
2519 | local FUNC PART CFGFILE TIMEOUT BOOTLOADER BOOTLOADERDIR CFGFILE MSG |
---|
2520 | |
---|
2521 | # Si se solicita, mostrar ayuda. |
---|
2522 | if [ "$*" == "help" ]; then |
---|
2523 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetTimeOut, ogBurgSetTimeOut or ogRefindSetTimeOut" |
---|
2524 | return |
---|
2525 | fi |
---|
2526 | |
---|
2527 | ogCheckStringInReg $3 "^[0-9]{1,10}$" && TIMEOUT="$3" || ogRaiseError $OG_ERR_FORMAT "param 3 is not a integer" |
---|
2528 | |
---|
2529 | # Nombre de la función que llama a esta. |
---|
2530 | FUNC="${FUNCNAME[@]:1}" |
---|
2531 | FUNC="${FUNC%%\ *}" |
---|
2532 | |
---|
2533 | # Error si no se reciben 3 parametros. |
---|
2534 | [ $# -eq 3 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage int_timeout_seconds" || return $? |
---|
2535 | |
---|
2536 | # Error si no puede montar sistema de archivos. |
---|
2537 | PART=$(ogMount $1 $2) || return $? |
---|
2538 | # La función debe ser llamanda desde ogGrubSetTimeOut, ogBurgSetTimeOut or ogRefindSetTimeOut. |
---|
2539 | case "$FUNC" in |
---|
2540 | ogGrubSetTimeOut) |
---|
2541 | BOOTLOADER="grub" |
---|
2542 | BOOTLOADERDIR="boot/grubMBR" |
---|
2543 | CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" |
---|
2544 | ;; |
---|
2545 | ogBurgSetTimeOut) |
---|
2546 | BOOTLOADER="burg" |
---|
2547 | BOOTLOADERDIR="boot/burg" |
---|
2548 | CFGFILE="$PART/boot/burg/burg.cfg" |
---|
2549 | ;; |
---|
2550 | ogRefindSetTimeOut) |
---|
2551 | BOOTLOADER="refind" |
---|
2552 | BOOTLOADERDIR="EFI/refind" |
---|
2553 | CFGFILE="$PART/EFI/refind/refind.conf" |
---|
2554 | ;; |
---|
2555 | *) |
---|
2556 | ogRaiseError $OG_ERR_FORMAT "Use ogGrubSetTimeOut, ogBurgSetTimeOut or ogRefindSetTimeOut." |
---|
2557 | return $? |
---|
2558 | ;; |
---|
2559 | esac |
---|
2560 | |
---|
2561 | # Comprobamos que exista fichero de configuración |
---|
2562 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2563 | |
---|
2564 | # Asignamos el timeOut. |
---|
2565 | if [ "$BOOTLOADER" == "refind" ]; then |
---|
2566 | sed -i s/timeout.*$/"timeout $TIMEOUT"/g $CFGFILE |
---|
2567 | else |
---|
2568 | sed -i s/timeout=.*$/timeout=$TIMEOUT/g $CFGFILE |
---|
2569 | fi |
---|
2570 | } |
---|
2571 | |
---|
2572 | |
---|
2573 | #/** |
---|
2574 | # ogGrubSetResolution num_disk num_part int_resolution |
---|
2575 | #@brief ver ogBootLoaderSetResolution |
---|
2576 | #@see ogBootLoaderSetResolution |
---|
2577 | #*/ ## |
---|
2578 | function ogGrubSetResolution () |
---|
2579 | { |
---|
2580 | # Si se solicita, mostrar ayuda. |
---|
2581 | if [ "$*" == "help" ]; then |
---|
2582 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [str_resolution]" \ |
---|
2583 | "$FUNCNAME 1 4 1024x768" \ |
---|
2584 | "$FUNCNAME \$(ogFindCache) 1024x768" \ |
---|
2585 | "$FUNCNAME 1 4" |
---|
2586 | return |
---|
2587 | fi |
---|
2588 | ogBootLoaderSetResolution $@ |
---|
2589 | return $? |
---|
2590 | } |
---|
2591 | |
---|
2592 | #/** |
---|
2593 | # ogBurgSetResolution num_disk num_part str_bolean |
---|
2594 | #@brief ver ogBootLoaderSetResolution |
---|
2595 | #@see ogBootLoaderSetResolution |
---|
2596 | #*/ ## |
---|
2597 | function ogBurgSetResolution () |
---|
2598 | { |
---|
2599 | # Si se solicita, mostrar ayuda. |
---|
2600 | if [ "$*" == "help" ]; then |
---|
2601 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [str_resolution]" \ |
---|
2602 | "$FUNCNAME 1 4 1024x768" \ |
---|
2603 | "$FUNCNAME \$(ogFindCache) 1024x768" \ |
---|
2604 | "$FUNCNAME 1 4" |
---|
2605 | return |
---|
2606 | fi |
---|
2607 | ogBootLoaderSetResolution $@ |
---|
2608 | return $? |
---|
2609 | } |
---|
2610 | |
---|
2611 | |
---|
2612 | |
---|
2613 | #/** |
---|
2614 | # ogBootLoaderSetResolution |
---|
2615 | #@brief Define la resolucion que usuara el thema del gestor de arranque |
---|
2616 | #@param int_disk_SecondStage |
---|
2617 | #@param int_part_SecondStage |
---|
2618 | #@param str_resolution (Opcional) |
---|
2619 | #@return |
---|
2620 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2621 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2622 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg. |
---|
2623 | #@version 1.1.0 - Primeras pruebas con Burg. grub no soportado. |
---|
2624 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
2625 | #@date 2018-01-24 |
---|
2626 | #*/ ## |
---|
2627 | function ogBootLoaderSetResolution () |
---|
2628 | { |
---|
2629 | |
---|
2630 | # Variables locales. |
---|
2631 | local FUNC PART CFGFILE RESOLUTION NEWRESOLUTION DEFAULTRESOLUTION BOOTLOADER BOOTLOADERDIR CFGFILE MSG |
---|
2632 | |
---|
2633 | # Si se solicita, mostrar ayuda. |
---|
2634 | if [ "$*" == "help" ]; then |
---|
2635 | ogHelp "$FUNCNAME" "$MSG_SEE ogGrubSetResolution, ogBurgSetResolution or ogRefindSetResolution." |
---|
2636 | return |
---|
2637 | fi |
---|
2638 | |
---|
2639 | |
---|
2640 | # Nombre de la función que llama a esta. |
---|
2641 | FUNC="${FUNCNAME[@]:1}" |
---|
2642 | FUNC="${FUNC%%\ *}" |
---|
2643 | |
---|
2644 | |
---|
2645 | # Error si no se reciben 2 parametros. |
---|
2646 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage [str_resolution]" || return $? |
---|
2647 | |
---|
2648 | # Error si no puede montar sistema de archivos. |
---|
2649 | PART=$(ogMount $1 $2) || return $? |
---|
2650 | # La función debe ser llamanda desde ogGrugSetResolution, ogBurgSetResolution or ogRefindSetResolution. |
---|
2651 | case "$FUNC" in |
---|
2652 | ogGrubSetResolution) |
---|
2653 | BOOTLOADER="grub" |
---|
2654 | BOOTLOADERDIR="grubMBR" |
---|
2655 | CFGFILE="$PART/boot/grubMBR/boot/grub/grub.cfg" |
---|
2656 | ogRaiseError $OG_ERR_FORMAT "ogGrubSetResolution not sopported" |
---|
2657 | return $? |
---|
2658 | ;; |
---|
2659 | ogBurgSetResolution) |
---|
2660 | BOOTLOADER="burg" |
---|
2661 | BOOTLOADERDIR="burg" |
---|
2662 | CFGFILE="$PART/boot/burg/burg.cfg" |
---|
2663 | ;; |
---|
2664 | *) |
---|
2665 | ogRaiseError $OG_ERR_FORMAT "Use GrugSetResolution, ogBurgSetResolution or ogRefindSetResolution." |
---|
2666 | return $? |
---|
2667 | ;; |
---|
2668 | esac |
---|
2669 | |
---|
2670 | DEFAULTRESOLUTION=1024x768 |
---|
2671 | |
---|
2672 | # Comprobamos que exista fichero de configuración |
---|
2673 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2674 | |
---|
2675 | #controlar variable a consierar vga (default template) o video (menu) |
---|
2676 | #Si solo dos parametros autoconfiguracion basado en el parametro vga de las propiedad menu. si no hay menu asignado es 788 por defecto |
---|
2677 | if [ $# -eq 2 ] ; then |
---|
2678 | if [ -n $video ]; then |
---|
2679 | NEWRESOLUTION=$(echo "$video" | cut -f2 -d: | cut -f1 -d-) |
---|
2680 | fi |
---|
2681 | if [ -n $vga ] ; then |
---|
2682 | case "$vga" in |
---|
2683 | 788|789|814) |
---|
2684 | NEWRESOLUTION=800x600 |
---|
2685 | ;; |
---|
2686 | 791|792|824) |
---|
2687 | NEWRESOLUTION=1024x768 |
---|
2688 | ;; |
---|
2689 | 355) |
---|
2690 | NEWRESOLUTION=1152x864 |
---|
2691 | ;; |
---|
2692 | 794|795|829) |
---|
2693 | NEWRESOLUTION=1280x1024 |
---|
2694 | ;; |
---|
2695 | esac |
---|
2696 | fi |
---|
2697 | fi |
---|
2698 | |
---|
2699 | if [ $# -eq 3 ] ; then |
---|
2700 | #comprobamos que el parametro 3 cumple formato NNNNxNNNN |
---|
2701 | 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" |
---|
2702 | fi |
---|
2703 | |
---|
2704 | # Si no existe NEWRESOLUCION asignamos la defaulT |
---|
2705 | [ -z "$NEWRESOLUTION" ] && NEWRESOLUTION=$DEFAULRESOLUTION |
---|
2706 | |
---|
2707 | #Cambiamos la entrada el fichero de configuración. |
---|
2708 | sed -i s/gfxmode=.*$/gfxmode=$NEWRESOLUTION/g $CFGFILE |
---|
2709 | } |
---|
2710 | |
---|
2711 | |
---|
2712 | |
---|
2713 | |
---|
2714 | #/** |
---|
2715 | # ogBootLoaderSetResolution |
---|
2716 | #@brief Define la resolucion que usuara el thema del gestor de arranque |
---|
2717 | #@param int_resolution1 |
---|
2718 | #@param int_resolution2 (Opcional) |
---|
2719 | #@return |
---|
2720 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2721 | #@exception OG_ERR_PARTITION Partición errónea o desconocida (ogMount). |
---|
2722 | #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg. |
---|
2723 | #*/ ## |
---|
2724 | function ogRefindSetResolution () { |
---|
2725 | local PART CFGFILE |
---|
2726 | # Si se solicita, mostrar ayuda. |
---|
2727 | if [ "$*" == "help" ]; then |
---|
2728 | ogHelp "$FUNCNAME" "$FUNCNAME int_resolution1 [int_resolution2]" \ |
---|
2729 | "$FUNCNAME 1366 768" \ |
---|
2730 | "$FUNCNAME 1" |
---|
2731 | return |
---|
2732 | fi |
---|
2733 | |
---|
2734 | # Error si no se reciben 2 parametros. |
---|
2735 | [ $# -ge 1 ] || ogRaiseError $OG_ERR_FORMAT "$FUNCNAME int_resolution1 [int_resolution2]" || return $? |
---|
2736 | |
---|
2737 | # Error si no puede montar sistema de archivos. |
---|
2738 | PART=$(ogMount $(ogGetEsp)) || return $? |
---|
2739 | |
---|
2740 | # Comprobamos que exista fichero de configuración |
---|
2741 | CFGFILE=$PART/EFI/refind/refind.conf |
---|
2742 | [ -f $CFGFILE ] || ogRaiseError $OG_ERR_NOTFOUND "$CFGFILE" || return $? |
---|
2743 | |
---|
2744 | # Borramos resolucion anterior y configuramos la nueva |
---|
2745 | sed -i /^resolution/d $CFGFILE |
---|
2746 | |
---|
2747 | sed -i "1 i\resolution $1 $2" $CFGFILE |
---|
2748 | } |
---|
2749 | |
---|
2750 | # ogRefindInstall bool_autoconfig |
---|
2751 | #@brief Instala y actualiza el gestor rEFInd en la particion EFI |
---|
2752 | #@param bolean_Check__auto_config true | false[default] |
---|
2753 | #@return |
---|
2754 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2755 | #@exception OG_ERR_NOTFOUND No se encuentra la partición ESP. |
---|
2756 | #@exception OG_ERR_NOTFOUND No se encuentra shimx64.efi.signed. |
---|
2757 | #@exception OG_ERR_NOTFOUND No se encuentra refind-install o refind en OGLIB |
---|
2758 | #@exception OG_ERR_PARTITION No se puede montar la partición ESP. |
---|
2759 | #@note Refind debe estar instalado en el ogLive o compartido en OGLIB |
---|
2760 | #@version 1.1.0 - Primeras pruebas. |
---|
2761 | #@author Juan Carlos Garcia. Universidad de ZAragoza. |
---|
2762 | #@date 2017-06-26 |
---|
2763 | #@version 1.1.1 - Usa refind-install. Obtiene partición con ogGetEsp. Configura Part-X-Y y ogLive. |
---|
2764 | #@author Irina Gomez. Universidad de Sevilla. |
---|
2765 | #@date 2019-03-22 |
---|
2766 | #*/ ## |
---|
2767 | function ogRefindInstall () { |
---|
2768 | # Variables locales. |
---|
2769 | local CONFIG EFIDISK EFIPART EFIDEVICE EFIMNT EFIDIR SHIM REFINDDIR |
---|
2770 | local CACHEDEVICE OGLIVE OGLIVEDIR CMDLINE OGICON CFGFILE DEVICES |
---|
2771 | local LNXCFGFILE NUMENTRY DIR |
---|
2772 | |
---|
2773 | # Si se solicita, mostrar ayuda. |
---|
2774 | if [ "$*" == "help" ]; then |
---|
2775 | ogHelp "$FUNCNAME" "$FUNCNAME boolean_autoconfig " \ |
---|
2776 | "$FUNCNAME TRUE" |
---|
2777 | return |
---|
2778 | fi |
---|
2779 | |
---|
2780 | # Recogemos parametros |
---|
2781 | CONFIG=${1:-"FALSE"} |
---|
2782 | |
---|
2783 | read -e EFIDISK EFIPART <<< $(ogGetEsp) |
---|
2784 | EFIDEVICE=$(ogDiskToDev $EFIDISK $EFIPART) || ogRaiseError $OG_ERR_NOTFOUND "ESP" || return $? |
---|
2785 | EFIMNT=$(ogMount $EFIDISK $EFIPART) || ogRaiseError $OG_ERR_PARTITION "$MSG_ERROR mount ESP" || return $? |
---|
2786 | EFIDIR="$EFIMNT/EFI" |
---|
2787 | [ -d $EFIDIR ] || mkdir $EFIDIR |
---|
2788 | |
---|
2789 | # Comprobamos que exista shimx64 |
---|
2790 | SHIM=$(ogGetPath /usr/lib/shim/shimx64.efi.signed) |
---|
2791 | [ "$SHIM" == "" ] && return $(ogRaiseError $OG_ERR_NOTFOUND "shimx64.efi.signed") |
---|
2792 | |
---|
2793 | # Si existe configuración anterior de refind la borro |
---|
2794 | [ -d "$EFIDIR/refind" ] && rm -rf $EFIDIR/refind |
---|
2795 | |
---|
2796 | # Instalamos rEFInd. |
---|
2797 | refind-install --yes --alldrivers --root $EFIMNT --shim $SHIM |
---|
2798 | |
---|
2799 | # Firmo refind con certificado de OpenGnsys |
---|
2800 | mv $EFIDIR/refind/grubx64.efi $EFIDIR/refind/grubx64.efi-unsigned |
---|
2801 | sbsign --key $OGETC/ssl/private/opengnsys.key --cert $OGETC/ssl/certs/opengnsys.crt --output $EFIDIR/refind/grubx64.efi $EFIDIR/refind/grubx64.efi-unsigned |
---|
2802 | |
---|
2803 | # Copio los certificados |
---|
2804 | cp /etc/refind.d/keys/* $EFIDIR/refind/keys |
---|
2805 | # Copio certificado opengnsys |
---|
2806 | cp $OGETC/ssl/certs/opengnsys.* $EFIDIR/refind/keys |
---|
2807 | |
---|
2808 | # Ponemos la entrada en NVRAM en el segundo lugar del orden de arranque |
---|
2809 | NEWORDER="$(ogNvramGetOrder|awk '{gsub(",", " "); printf "%x %x %s\n", $2, $1, substr($0, index($0,$3))}')" |
---|
2810 | ogNvramSetOrder $NEWORDER |
---|
2811 | |
---|
2812 | # Borramos configuración linux |
---|
2813 | [ -f $EFIMNT/boot/refind_linux.conf ] && mv $EFIMNT/boot/refind_linux.conf{,.ogbackup} |
---|
2814 | |
---|
2815 | # Eliminamos punto de motaje (por si ejecutamos más de una vez) |
---|
2816 | umount $EFIMNT/boot/efi |
---|
2817 | |
---|
2818 | # Para la configuración del ogLive |
---|
2819 | ogMountCache &>/dev/null |
---|
2820 | if [ $? -eq 0 ]; then |
---|
2821 | # Detectamos si hay ogLive |
---|
2822 | CACHEDEVICE=$(ogDiskToDev $(ogFindCache)) |
---|
2823 | OGLIVE=$(find $OGCAC/boot -name ogvmlinuz|head -1) |
---|
2824 | # Obtenemos parametros del kernel y sustituimos root |
---|
2825 | # La línea de opciones no puede contener la cadena initrd. |
---|
2826 | CMDLINE="$(cat /proc/cmdline|sed -e 's/^.*ogvmlinuz.efi //g' -e 's/^.*ogvmlinuz //g' -e 's|root=/dev/[a-z]* ||g' \ |
---|
2827 | -e 's/ogupdateinitrd=[a-z]* //g')" |
---|
2828 | CMDLINE="root=$CACHEDEVICE ${CMDLINE#*ogvmlinuz}" |
---|
2829 | |
---|
2830 | # Icono para la entrada de menú |
---|
2831 | OGICON=$(ls $OGLIB/refind/icons/so_opengnsys.png 2>/dev/null) |
---|
2832 | [ "$OGICON" == "" ] && OGICON="${EFIDIR}/refind/icons/os_unknown.png" |
---|
2833 | cp "$OGICON" "$OGCAC/.VolumeIcon.png" |
---|
2834 | fi |
---|
2835 | |
---|
2836 | # Configuramos rEFInd si es necesario |
---|
2837 | CFGFILE="${EFIDIR}/refind/refind.conf" |
---|
2838 | if [ "$CONFIG" == "TRUE" ]; then |
---|
2839 | echo -e "\n\n# Configuración OpenGnsys" >> $CFGFILE |
---|
2840 | # Excluimos dispositivos distintos de ESP y CACHE |
---|
2841 | DEVICES=$(blkid -s PARTUUID |awk -v D=$EFIDEVICE -v C=$CACHEDEVICE '$1!=D":" && $1!=C":" {gsub(/PARTUUID=/,"");gsub(/"/,""); aux = aux" "$2","} END {print aux}') |
---|
2842 | echo "dont_scan_volumes $DEVICES" >> $CFGFILE |
---|
2843 | # Excluimos en la ESP los directorios de los sistemas operativos |
---|
2844 | echo "dont_scan_dirs EFI/microsoft,EFI/ubuntu,EFI/grub" >> $CFGFILE |
---|
2845 | echo "use_graphics_for osx,linux,windows" >> $CFGFILE |
---|
2846 | echo "showtools reboot, shutdown" >> $CFGFILE |
---|
2847 | |
---|
2848 | # Configuramos ogLive |
---|
2849 | if [ "$OGLIVE" != "" ]; then |
---|
2850 | # Cambiamos nombre de kernel e initrd para que lo detecte refind |
---|
2851 | OGLIVEDIR="$(dirname $OGLIVE)" |
---|
2852 | cp "$OGLIVE" "${OGLIVE}.efi" |
---|
2853 | cp "$OGLIVEDIR/oginitrd.img" "$OGLIVEDIR/initrd.img" |
---|
2854 | |
---|
2855 | # Incluimos el directorio de ogLive. |
---|
2856 | echo "also_scan_dirs +,boot/$(basename $OGLIVEDIR)" >> $CFGFILE |
---|
2857 | # Fichero de configuración de refind para kernel de linux. |
---|
2858 | LNXCFGFILE="$OGLIVEDIR/refind_linux.conf" |
---|
2859 | echo "\"OpenGnsys Live\" \"$CMDLINE\"" > $LNXCFGFILE |
---|
2860 | |
---|
2861 | # Ponemos ogLive como la entrada por defecto |
---|
2862 | NUMENTRY=$(ls -d $EFIDIR/Part-??-??|wc -l) |
---|
2863 | echo "default_selection $((NUMENTRY+1))" >> $CFGFILE |
---|
2864 | fi |
---|
2865 | else |
---|
2866 | # Renombramos la configuración por defecto |
---|
2867 | mv $CFGFILE ${CFGFILE}.auto |
---|
2868 | |
---|
2869 | # Creamos nueva configuración |
---|
2870 | echo "# Configuración OpenGnsys" >> $CFGFILE |
---|
2871 | echo "timeout 20" > $CFGFILE |
---|
2872 | echo "showtools reboot, shutdown" >> $CFGFILE |
---|
2873 | echo -e "scanfor manual\n" >> $CFGFILE |
---|
2874 | # Configuración para sistemas restaurados con OpenGnsys |
---|
2875 | for DIR in $(ls -d /mnt/sda1/EFI/Part-*-* 2>/dev/null); do |
---|
2876 | echo "menuentry \"${DIR##*/}\" {" >> $CFGFILE |
---|
2877 | echo " loader /EFI/${DIR##*/}/Boot/ogloader.efi" >> $CFGFILE |
---|
2878 | [ -f $DIR/Boot/bootmgfw.efi ] && echo " icon /EFI/refind/icons/os_win8.png" >> $CFGFILE |
---|
2879 | [ -f $DIR/Boot/grubx64.efi ] && echo " icon /EFI/refind/icons/os_linux.png" >> $CFGFILE |
---|
2880 | echo "}" >> $CFGFILE |
---|
2881 | done |
---|
2882 | # Configuración ogLive si secureboot no está activado |
---|
2883 | if ! dmesg|grep secureboot.*enabled &>/dev/null; then |
---|
2884 | if [ "$OGLIVE" != "" ]; then |
---|
2885 | echo "menuentry \"OpenGnsys Live\" {" >> $CFGFILE |
---|
2886 | echo " volume CACHE" >> $CFGFILE |
---|
2887 | echo " ostype Linux" >> $CFGFILE |
---|
2888 | echo " loader /boot/$(basename ${OGLIVE%/*})/ogvmlinuz" >> $CFGFILE |
---|
2889 | echo " initrd /boot/$(basename ${OGLIVE%/*})/oginitrd.img" >> $CFGFILE |
---|
2890 | echo " options \"$CMDLINE\"" >> $CFGFILE |
---|
2891 | echo "}" >> $CFGFILE |
---|
2892 | |
---|
2893 | # Ponemos ogLive como la entrada por defecto |
---|
2894 | sed -i '1 i\default_selection "OpenGnsys Live"' $CFGFILE |
---|
2895 | fi |
---|
2896 | fi |
---|
2897 | fi |
---|
2898 | } |
---|
2899 | |
---|
2900 | #/** |
---|
2901 | # ogGrub4dosInstallMbr int_ndisk |
---|
2902 | #@brief Genera un nuevo Codigo de arranque en el MBR del disco indicado, compatible con los SO tipo Windows, Linux. |
---|
2903 | #@param int_ndisk nº de orden del disco |
---|
2904 | #@param int_ndisk nº de orden del particion |
---|
2905 | #@return |
---|
2906 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
2907 | #@exception OG_ERR_NOTFOUND Tipo de partición desconocido o no se puede montar. |
---|
2908 | #@exception OG_ERR_NOTBIOS Equipo no firmware BIOS legacy |
---|
2909 | #@exception OG_ERR_NOMSDOS Disco duro no particioniado en modo msdos |
---|
2910 | #@exception OG_ERR_NOTWRITE Particion no modificable. |
---|
2911 | #@version 1.1.1 - Adaptacion a OpenGnSys. |
---|
2912 | #@author Alberto GarcÃa Padilla / Antonio J. Doblas Viso. Universidad de Malaga |
---|
2913 | #@date 2009-10-17 |
---|
2914 | #*/ ## |
---|
2915 | |
---|
2916 | function ogGrub4dosInstallMbr () |
---|
2917 | { |
---|
2918 | # Variables locales. |
---|
2919 | local DISK PART DEVICE MOUNTDISK GRUBDISK BINBDIR |
---|
2920 | |
---|
2921 | # Si se solicita, mostrar ayuda. |
---|
2922 | if [ "$*" == "help" ]; then |
---|
2923 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_part " \ |
---|
2924 | "$FUNCNAME 1 1 " |
---|
2925 | return |
---|
2926 | fi |
---|
2927 | # Error si no se recibe 2 parámetros. |
---|
2928 | [ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
2929 | |
---|
2930 | DISK="$1" |
---|
2931 | PART="$2" |
---|
2932 | |
---|
2933 | #Controlar existencia de disco y particion |
---|
2934 | DEVICE=$(ogDiskToDev $DISK) || ogRaiseError $OG_ERR_NOTFOUND || return $? |
---|
2935 | MOUNTDISK=$(ogMount $DISK $PART) || ogRaiseError $OG_ERR_PARTITION "$MSG_ERROR " || return $? |
---|
2936 | #Controlar acceso de escritura a la particion |
---|
2937 | ogIsReadonly $DISK $PART && return $(ogRaiseError $OG_ERR_NOTWRITE ": $DISK $PART" || echo $?) |
---|
2938 | #Controlar disco no uefi |
---|
2939 | ogIsEfiActive && return $(ogRaiseError $OG_ERR_NOTBIOS " : grub4dos solo soporta PC con bios legacy"; echo $?) |
---|
2940 | #Controlar particionado tipo msdos |
---|
2941 | ogCheckStringInGroup $(ogGetPartitionTableType $DISK) "MSDOS" || return $(ogRaiseError $OG_ERR_NOMSDOS ": grub2dos requiere particionado tipo MSDOS"; echo $?) |
---|
2942 | #Controlar la existencia del grub4dos con acceso a ntfs |
---|
2943 | BINDIR="${OGLIB}/grub4dos/grub4dos-0.4.6a" |
---|
2944 | [ -f ${BINDIR}/bootlace.com ] || ogRaiseError $OG_ERR_NOTFOUND ": ${BINDIR}/bootlace.com" || return $? |
---|
2945 | |
---|
2946 | #instalar el bootloader de grlrd en el MBR |
---|
2947 | ${BINDIR}/bootlace64.com $DEVICE &>/dev/null |
---|
2948 | #copiar grld a la particion |
---|
2949 | cp ${BINDIR}/grldr $MOUNTDISK |
---|
2950 | #Instalar y configurar grub4dos |
---|
2951 | if [[ -f $MOUNTDISK/boot/grub/menu.lst ]]; then |
---|
2952 | rm $MOUNTDISK/boot/grub/menu.lst |
---|
2953 | rmdir /$MOUNTDISK/boot/grub |
---|
2954 | fi |
---|
2955 | if [[ ! -f $MOUNTDISK/boot/grub/menu.lst ]]; then |
---|
2956 | mkdir -p /$MOUNTDISK/boot/grub |
---|
2957 | touch /$MOUNTDISK/boot/grub/menu.lst |
---|
2958 | |
---|
2959 | GRUBDISK=$[$1-1] |
---|
2960 | |
---|
2961 | cat << EOT >/$MOUNTDISK/boot/grub/menu.lst |
---|
2962 | ##NO-TOCAR-ESTA-LINEA MBR |
---|
2963 | timeout 0 |
---|
2964 | title MBR |
---|
2965 | root (hd$GRUBDISK,0) |
---|
2966 | chainloader (hd$GRUBDISK,0)+1 |
---|
2967 | boot |
---|
2968 | EOT |
---|
2969 | |
---|
2970 | fi |
---|
2971 | } |
---|