2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
21 #include <grub/emu/misc.h>
22 #include <grub/util/misc.h>
23 #include <grub/misc.h>
24 #include <grub/device.h>
25 #include <grub/disk.h>
26 #include <grub/file.h>
29 #include <grub/term.h>
31 #include <grub/lib/hexdump.h>
32 #include <grub/crypto.h>
33 #include <grub/command.h>
34 #include <grub/i18n.h>
35 #include <grub/zfs/zfs.h>
36 #include <grub/util/install.h>
37 #include <grub/util/resolve.h>
38 #include <grub/emu/hostfile.h>
39 #include <grub/emu/config.h>
40 #include <grub/emu/hostfile.h>
48 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
51 grub_install_help_filter (int key
, const char *text
,
52 void *input
__attribute__ ((unused
)))
56 case GRUB_INSTALL_OPTIONS_INSTALL_THEMES
:
57 return xasprintf(text
, "starfield");
58 case GRUB_INSTALL_OPTIONS_INSTALL_FONTS
:
59 return xasprintf(text
, "unicode");
60 case GRUB_INSTALL_OPTIONS_DIRECTORY
:
61 case GRUB_INSTALL_OPTIONS_DIRECTORY2
:
62 return xasprintf(text
, grub_util_get_pkglibdir ());
63 case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY
:
64 return xasprintf(text
, grub_util_get_localedir ());
65 case GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY
:
66 return grub_util_path_concat (2, grub_util_get_pkgdatadir (), "themes");
72 #pragma GCC diagnostic error "-Wformat-nonliteral"
74 static int (*compress_func
) (const char *src
, const char *dest
) = NULL
;
75 char *grub_install_copy_buffer
;
79 grub_install_copy_file (const char *src
,
83 grub_util_fd_t in
, out
;
86 grub_util_info ("copying `%s' -> `%s'", src
, dst
);
88 in
= grub_util_fd_open (src
, GRUB_UTIL_FD_O_RDONLY
);
89 if (!GRUB_UTIL_FD_IS_VALID (in
))
92 grub_util_error (_("cannot open `%s': %s"), src
, grub_util_fd_strerror ());
94 grub_util_info (_("cannot open `%s': %s"), src
, grub_util_fd_strerror ());
97 out
= grub_util_fd_open (dst
, GRUB_UTIL_FD_O_WRONLY
98 | GRUB_UTIL_FD_O_CREATTRUNC
);
99 if (!GRUB_UTIL_FD_IS_VALID (out
))
101 grub_util_error (_("cannot open `%s': %s"), dst
,
102 grub_util_fd_strerror ());
103 grub_util_fd_close (in
);
107 if (!grub_install_copy_buffer
)
108 grub_install_copy_buffer
= xmalloc (GRUB_INSTALL_COPY_BUFFER_SIZE
);
112 r
= grub_util_fd_read (in
, grub_install_copy_buffer
, GRUB_INSTALL_COPY_BUFFER_SIZE
);
115 r
= grub_util_fd_write (out
, grub_install_copy_buffer
, r
);
119 if (grub_util_fd_sync (out
) < 0)
121 if (grub_util_fd_close (in
) < 0)
123 if (grub_util_fd_close (out
) < 0)
127 grub_util_error (_("cannot copy `%s' to `%s': %s"),
128 src
, dst
, grub_util_fd_strerror ());
134 grub_install_compress_file (const char *in_name
,
135 const char *out_name
,
141 ret
= grub_install_copy_file (in_name
, out_name
, is_needed
);
144 grub_util_info ("compressing `%s' -> `%s'", in_name
, out_name
);
145 ret
= !compress_func (in_name
, out_name
);
146 if (!ret
&& is_needed
)
147 grub_util_warn (_("can't compress `%s' to `%s'"), in_name
, out_name
);
150 if (!ret
&& is_needed
)
151 grub_util_error (_("cannot copy `%s' to `%s': %s"),
152 in_name
, out_name
, grub_util_fd_strerror ());
158 is_path_separator (char c
)
160 #if defined (__MINGW32__) || defined (__CYGWIN__)
170 grub_install_mkdir_p (const char *dst
)
172 char *t
= xstrdup (dst
);
176 if (is_path_separator (*p
))
189 clean_grub_dir (const char *di
)
191 grub_util_fd_dir_t d
;
192 grub_util_fd_dirent_t de
;
194 d
= grub_util_fd_opendir (di
);
196 grub_util_error (_("cannot open directory `%s': %s"),
197 di
, grub_util_fd_strerror ());
199 while ((de
= grub_util_fd_readdir (d
)))
201 const char *ext
= strrchr (de
->d_name
, '.');
202 if ((ext
&& (strcmp (ext
, ".mod") == 0
203 || strcmp (ext
, ".lst") == 0
204 || strcmp (ext
, ".img") == 0
205 || strcmp (ext
, ".mo") == 0)
206 && strcmp (de
->d_name
, "menu.lst") != 0)
207 || strcmp (de
->d_name
, "efiemu32.o") == 0
208 || strcmp (de
->d_name
, "efiemu64.o") == 0)
210 char *x
= grub_util_path_concat (2, di
, de
->d_name
);
211 if (grub_util_unlink (x
) < 0)
212 grub_util_error (_("cannot delete `%s': %s"), x
,
213 grub_util_fd_strerror ());
217 grub_util_fd_closedir (d
);
228 struct install_list install_modules
= { 1, 0, 0, 0 };
229 struct install_list modules
= { 1, 0, 0, 0 };
230 struct install_list install_locales
= { 1, 0, 0, 0 };
231 struct install_list install_fonts
= { 1, 0, 0, 0 };
232 struct install_list install_themes
= { 1, 0, 0, 0 };
233 char *grub_install_source_directory
= NULL
;
234 char *grub_install_locale_directory
= NULL
;
235 char *grub_install_themes_directory
= NULL
;
238 grub_install_push_module (const char *val
)
240 modules
.is_default
= 0;
241 if (modules
.n_entries
+ 1 >= modules
.n_alloc
)
243 modules
.n_alloc
<<= 1;
244 if (modules
.n_alloc
< 16)
245 modules
.n_alloc
= 16;
246 modules
.entries
= xrealloc (modules
.entries
,
247 modules
.n_alloc
* sizeof (*modules
.entries
));
249 modules
.entries
[modules
.n_entries
++] = xstrdup (val
);
250 modules
.entries
[modules
.n_entries
] = NULL
;
254 grub_install_pop_module (void)
257 free (modules
.entries
[modules
.n_entries
]);
258 modules
.entries
[modules
.n_entries
] = NULL
;
263 handle_install_list (struct install_list
*il
, const char *val
,
272 if (strcmp (val
, "all") == 0 && default_all
)
280 while (*ptr
&& grub_isspace (*ptr
))
284 while (*ptr
&& !grub_isspace (*ptr
))
288 il
->n_alloc
= il
->n_entries
+ 1;
289 il
->entries
= xmalloc (il
->n_alloc
* sizeof (il
->entries
[0]));
291 for (ce
= il
->entries
; ; ce
++)
294 while (*ptr
&& grub_isspace (*ptr
))
299 while (*ptr
&& !grub_isspace (*ptr
))
301 *ce
= xmalloc (ptr
- bptr
+ 1);
302 memcpy (*ce
, bptr
, ptr
- bptr
);
303 (*ce
)[ptr
- bptr
] = '\0';
308 static char **pubkeys
;
309 static size_t npubkeys
;
310 static grub_compression_t compression
;
313 grub_install_parse (int key
, char *arg
)
318 if (grub_strcmp (arg
, "xz") == 0)
321 compression
= GRUB_COMPRESSION_XZ
;
323 grub_util_error ("%s",
324 _("grub-mkimage is compiled without XZ support"));
327 else if (grub_strcmp (arg
, "none") == 0)
328 compression
= GRUB_COMPRESSION_NONE
;
329 else if (grub_strcmp (arg
, "auto") == 0)
330 compression
= GRUB_COMPRESSION_AUTO
;
332 grub_util_error (_("Unknown compression format %s"), arg
);
335 pubkeys
= xrealloc (pubkeys
,
338 pubkeys
[npubkeys
++] = xstrdup (arg
);
341 case GRUB_INSTALL_OPTIONS_VERBOSITY
:
345 case GRUB_INSTALL_OPTIONS_DIRECTORY
:
346 case GRUB_INSTALL_OPTIONS_DIRECTORY2
:
347 free (grub_install_source_directory
);
348 grub_install_source_directory
= xstrdup (arg
);
350 case GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY
:
351 free (grub_install_locale_directory
);
352 grub_install_locale_directory
= xstrdup (arg
);
354 case GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY
:
355 free (grub_install_themes_directory
);
356 grub_install_themes_directory
= xstrdup (arg
);
358 case GRUB_INSTALL_OPTIONS_INSTALL_MODULES
:
359 handle_install_list (&install_modules
, arg
, 0);
361 case GRUB_INSTALL_OPTIONS_MODULES
:
362 handle_install_list (&modules
, arg
, 0);
364 case GRUB_INSTALL_OPTIONS_INSTALL_LOCALES
:
365 handle_install_list (&install_locales
, arg
, 0);
367 case GRUB_INSTALL_OPTIONS_INSTALL_THEMES
:
368 handle_install_list (&install_themes
, arg
, 0);
370 case GRUB_INSTALL_OPTIONS_INSTALL_FONTS
:
371 handle_install_list (&install_fonts
, arg
, 0);
373 case GRUB_INSTALL_OPTIONS_DTB
:
378 case GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS
:
379 if (strcmp (arg
, "no") == 0
380 || strcmp (arg
, "none") == 0)
382 compress_func
= NULL
;
385 if (strcmp (arg
, "gz") == 0)
387 compress_func
= grub_install_compress_gzip
;
390 if (strcmp (arg
, "xz") == 0)
392 compress_func
= grub_install_compress_xz
;
395 if (strcmp (arg
, "lzo") == 0)
397 compress_func
= grub_install_compress_lzop
;
400 grub_util_error (_("Unrecognized compression `%s'"), arg
);
401 case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE
:
411 if (compress_func
== grub_install_compress_gzip
)
413 grub_install_push_module ("gzio");
416 if (compress_func
== grub_install_compress_xz
)
418 grub_install_push_module ("xzio");
419 grub_install_push_module ("gcry_crc");
422 if (compress_func
== grub_install_compress_lzop
)
424 grub_install_push_module ("lzopio");
425 grub_install_push_module ("adler32");
426 grub_install_push_module ("gcry_crc");
433 grub_install_make_image_wrap_file (const char *dir
, const char *prefix
,
434 FILE *fp
, const char *outname
,
437 const char *mkimage_target
, int note
)
439 const struct grub_install_image_target_desc
*tgt
;
440 const char *const compnames
[] =
442 [GRUB_COMPRESSION_AUTO
] = "auto",
443 [GRUB_COMPRESSION_NONE
] = "none",
444 [GRUB_COMPRESSION_XZ
] = "xz",
445 [GRUB_COMPRESSION_LZMA
] = "lzma",
447 grub_size_t slen
= 1;
450 int dc
= decompressors ();
453 slen
+= 20 + grub_strlen (memdisk_path
);
455 slen
+= 20 + grub_strlen (config_path
);
457 for (pk
= pubkeys
; pk
< pubkeys
+ npubkeys
; pk
++)
458 slen
+= 20 + grub_strlen (*pk
);
460 for (md
= modules
.entries
; *md
; md
++)
462 slen
+= 10 + grub_strlen (*md
);
465 p
= s
= xmalloc (slen
);
468 p
= grub_stpcpy (p
, "--memdisk '");
469 p
= grub_stpcpy (p
, memdisk_path
);
475 p
= grub_stpcpy (p
, "--config '");
476 p
= grub_stpcpy (p
, config_path
);
480 for (pk
= pubkeys
; pk
< pubkeys
+ npubkeys
; pk
++)
482 p
= grub_stpcpy (p
, "--pubkey '");
483 p
= grub_stpcpy (p
, *pk
);
488 for (md
= modules
.entries
; *md
; md
++)
491 p
= grub_stpcpy (p
, *md
);
498 grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'"
501 "--format '%s' --compression '%s' %s %s\n",
503 outname
, dtb
? : "", mkimage_target
,
504 compnames
[compression
], note
? "--note" : "", s
);
507 tgt
= grub_install_get_image_target (mkimage_target
);
509 grub_util_error (_("unknown target format %s"), mkimage_target
);
511 grub_install_generate_image (dir
, prefix
, fp
, outname
,
512 modules
.entries
, memdisk_path
,
513 pubkeys
, npubkeys
, config_path
, tgt
,
514 note
, compression
, dtb
);
516 grub_install_pop_module ();
520 grub_install_make_image_wrap (const char *dir
, const char *prefix
,
521 const char *outname
, char *memdisk_path
,
523 const char *mkimage_target
, int note
)
527 fp
= grub_util_fopen (outname
, "wb");
529 grub_util_error (_("cannot open `%s': %s"), outname
,
531 grub_install_make_image_wrap_file (dir
, prefix
, fp
, outname
,
532 memdisk_path
, config_path
,
533 mkimage_target
, note
);
534 if (grub_util_file_sync (fp
) < 0)
535 grub_util_error (_("cannot sync `%s': %s"), outname
, strerror (errno
));
540 copy_by_ext (const char *srcd
,
545 grub_util_fd_dir_t d
;
546 grub_util_fd_dirent_t de
;
548 d
= grub_util_fd_opendir (srcd
);
552 grub_util_error (_("cannot open directory `%s': %s"),
553 srcd
, grub_util_fd_strerror ());
555 while ((de
= grub_util_fd_readdir (d
)))
557 const char *ext
= strrchr (de
->d_name
, '.');
558 if (ext
&& strcmp (ext
, extf
) == 0)
560 char *srcf
= grub_util_path_concat (2, srcd
, de
->d_name
);
561 char *dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
562 grub_install_compress_file (srcf
, dstf
, 1);
567 grub_util_fd_closedir (d
);
571 copy_all (const char *srcd
,
574 grub_util_fd_dir_t d
;
575 grub_util_fd_dirent_t de
;
577 d
= grub_util_fd_opendir (srcd
);
579 grub_util_error (_("cannot open directory `%s': %s"),
580 srcd
, grub_util_fd_strerror ());
582 while ((de
= grub_util_fd_readdir (d
)))
586 if (strcmp (de
->d_name
, ".") == 0
587 || strcmp (de
->d_name
, "..") == 0)
589 srcf
= grub_util_path_concat (2, srcd
, de
->d_name
);
590 if (grub_util_is_special_file (srcf
)
591 || grub_util_is_directory (srcf
))
593 dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
594 grub_install_compress_file (srcf
, dstf
, 1);
598 grub_util_fd_closedir (d
);
601 #if !(defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS)
605 if (grub_install_locale_directory
)
606 return grub_install_locale_directory
;
608 return grub_util_get_localedir ();
612 copy_locales (const char *dstd
)
614 grub_util_fd_dir_t d
;
615 grub_util_fd_dirent_t de
;
616 const char *locale_dir
= get_localedir ();
618 d
= grub_util_fd_opendir (locale_dir
);
621 grub_util_warn (_("cannot open directory `%s': %s"),
622 locale_dir
, grub_util_fd_strerror ());
626 while ((de
= grub_util_fd_readdir (d
)))
631 if (strcmp (de
->d_name
, ".") == 0)
633 if (strcmp (de
->d_name
, "..") == 0)
635 ext
= grub_strrchr (de
->d_name
, '.');
636 if (ext
&& (grub_strcmp (ext
, ".mo") == 0
637 || grub_strcmp (ext
, ".gmo") == 0))
639 srcf
= grub_util_path_concat (2, locale_dir
, de
->d_name
);
640 dstf
= grub_util_path_concat (2, dstd
, de
->d_name
);
641 ext
= grub_strrchr (dstf
, '.');
642 grub_strcpy (ext
, ".mo");
646 srcf
= grub_util_path_concat_ext (4, locale_dir
, de
->d_name
,
647 "LC_MESSAGES", PACKAGE
, ".mo");
648 dstf
= grub_util_path_concat_ext (2, dstd
, de
->d_name
, ".mo");
650 grub_install_compress_file (srcf
, dstf
, 0);
654 grub_util_fd_closedir (d
);
659 grub_install_copy_nls(const char *src
__attribute__ ((unused
)),
660 const char *dst
__attribute__ ((unused
)))
662 #if !(defined (GRUB_UTIL) && defined(ENABLE_NLS) && ENABLE_NLS)
665 dst_locale
= grub_util_path_concat (2, dst
, "locale");
666 grub_install_mkdir_p (dst_locale
);
667 clean_grub_dir (dst_locale
);
669 if (install_locales
.is_default
)
671 char *srcd
= grub_util_path_concat (2, src
, "po");
672 copy_by_ext (srcd
, dst_locale
, ".mo", 0);
673 copy_locales (dst_locale
);
679 const char *locale_dir
= get_localedir ();
681 for (i
= 0; i
< install_locales
.n_entries
; i
++)
683 char *srcf
= grub_util_path_concat_ext (3, src
, "po",
684 install_locales
.entries
[i
],
686 char *dstf
= grub_util_path_concat_ext (2, dst_locale
,
687 install_locales
.entries
[i
],
689 if (grub_install_compress_file (srcf
, dstf
, 0))
696 srcf
= grub_util_path_concat_ext (4, locale_dir
,
697 install_locales
.entries
[i
],
698 "LC_MESSAGES", PACKAGE
, ".mo");
699 if (grub_install_compress_file (srcf
, dstf
, 0) == 0)
700 grub_util_error (_("cannot find locale `%s'"),
701 install_locales
.entries
[i
]);
713 const char *platform
;
714 } platforms
[GRUB_INSTALL_PLATFORM_MAX
] =
716 [GRUB_INSTALL_PLATFORM_I386_PC
] = { "i386", "pc" },
717 [GRUB_INSTALL_PLATFORM_I386_EFI
] = { "i386", "efi" },
718 [GRUB_INSTALL_PLATFORM_I386_QEMU
] = { "i386", "qemu" },
719 [GRUB_INSTALL_PLATFORM_I386_COREBOOT
] = { "i386", "coreboot" },
720 [GRUB_INSTALL_PLATFORM_I386_MULTIBOOT
] = { "i386", "multiboot" },
721 [GRUB_INSTALL_PLATFORM_I386_IEEE1275
] = { "i386", "ieee1275" },
722 [GRUB_INSTALL_PLATFORM_X86_64_EFI
] = { "x86_64", "efi" },
723 [GRUB_INSTALL_PLATFORM_I386_XEN
] = { "i386", "xen" },
724 [GRUB_INSTALL_PLATFORM_X86_64_XEN
] = { "x86_64", "xen" },
725 [GRUB_INSTALL_PLATFORM_I386_XEN_PVH
] = { "i386", "xen_pvh" },
726 [GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON
] = { "mipsel", "loongson" },
727 [GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS
] = { "mipsel", "qemu_mips" },
728 [GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS
] = { "mips", "qemu_mips" },
729 [GRUB_INSTALL_PLATFORM_MIPSEL_ARC
] = { "mipsel", "arc" },
730 [GRUB_INSTALL_PLATFORM_MIPS_ARC
] = { "mips", "arc" },
731 [GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275
] = { "sparc64", "ieee1275" },
732 [GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275
] = { "powerpc", "ieee1275" },
733 [GRUB_INSTALL_PLATFORM_IA64_EFI
] = { "ia64", "efi" },
734 [GRUB_INSTALL_PLATFORM_ARM_EFI
] = { "arm", "efi" },
735 [GRUB_INSTALL_PLATFORM_ARM64_EFI
] = { "arm64", "efi" },
736 [GRUB_INSTALL_PLATFORM_MIPS64EL_EFI
] = { "mips64el","efi" },
737 [GRUB_INSTALL_PLATFORM_ARM_UBOOT
] = { "arm", "uboot" },
738 [GRUB_INSTALL_PLATFORM_ARM_COREBOOT
] = { "arm", "coreboot" },
739 [GRUB_INSTALL_PLATFORM_RISCV32_EFI
] = { "riscv32", "efi" },
740 [GRUB_INSTALL_PLATFORM_RISCV64_EFI
] = { "riscv64", "efi" },
744 grub_install_get_platforms_string (void)
746 char **arr
= xmalloc (sizeof (char *) * ARRAY_SIZE (platforms
));
747 int platform_strins_len
= 0;
748 char *platforms_string
;
751 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
753 arr
[i
] = xasprintf ("%s-%s", platforms
[i
].cpu
,
754 platforms
[i
].platform
);
755 platform_strins_len
+= strlen (arr
[i
]) + 2;
757 ptr
= platforms_string
= xmalloc (platform_strins_len
);
758 qsort (arr
, ARRAY_SIZE (platforms
), sizeof (char *), grub_qsort_strcmp
);
759 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
761 strcpy (ptr
, arr
[i
]);
762 ptr
+= strlen (arr
[i
]);
770 return platforms_string
;
774 grub_install_get_platform_name (enum grub_install_plat platid
)
776 return xasprintf ("%s-%s", platforms
[platid
].cpu
,
777 platforms
[platid
].platform
);
781 grub_install_get_platform_cpu (enum grub_install_plat platid
)
783 return platforms
[platid
].cpu
;
787 grub_install_get_platform_platform (enum grub_install_plat platid
)
789 return platforms
[platid
].platform
;
794 grub_install_copy_files (const char *src
,
796 enum grub_install_plat platid
)
798 char *dst_platform
, *dst_fonts
;
799 const char *pkgdatadir
= grub_util_get_pkgdatadir ();
804 platform
= xasprintf ("%s-%s", platforms
[platid
].cpu
,
805 platforms
[platid
].platform
);
806 dst_platform
= grub_util_path_concat (2, dst
, platform
);
809 dst_fonts
= grub_util_path_concat (2, dst
, "fonts");
810 grub_install_mkdir_p (dst_platform
);
811 clean_grub_dir (dst
);
812 clean_grub_dir (dst_platform
);
814 grub_install_copy_nls(src
, dst
);
816 if (install_modules
.is_default
)
817 copy_by_ext (src
, dst_platform
, ".mod", 1);
820 struct grub_util_path_list
*path_list
, *p
;
822 path_list
= grub_util_resolve_dependencies (src
, "moddep.lst",
823 install_modules
.entries
);
824 for (p
= path_list
; p
; p
= p
->next
)
826 const char *srcf
= p
->name
;
830 dir
= grub_strrchr (srcf
, '/');
835 dstf
= grub_util_path_concat (2, dst_platform
, dir
);
836 grub_install_compress_file (srcf
, dstf
, 1);
840 grub_util_free_path_list (path_list
);
843 const char *pkglib_DATA
[] = {"efiemu32.o", "efiemu64.o",
844 "moddep.lst", "command.lst",
845 "fs.lst", "partmap.lst",
847 "video.lst", "crypto.lst",
848 "terminal.lst", "modinfo.sh" };
851 for (i
= 0; i
< ARRAY_SIZE (pkglib_DATA
); i
++)
853 char *srcf
= grub_util_path_concat (2, src
, pkglib_DATA
[i
]);
854 char *dstf
= grub_util_path_concat (2, dst_platform
, pkglib_DATA
[i
]);
855 if (i
== 0 || i
== 1)
856 grub_install_compress_file (srcf
, dstf
, 0);
858 grub_install_compress_file (srcf
, dstf
, 1);
863 if (install_themes
.is_default
)
865 install_themes
.is_default
= 0;
866 install_themes
.n_entries
= 1;
867 install_themes
.entries
= xmalloc (2 * sizeof (install_themes
.entries
[0]));
868 install_themes
.entries
[0] = xstrdup ("starfield");
869 install_themes
.entries
[1] = NULL
;
872 if (grub_install_themes_directory
)
873 themes_dir
= xstrdup (grub_install_themes_directory
);
875 themes_dir
= grub_util_path_concat (2, grub_util_get_pkgdatadir (),
878 for (i
= 0; i
< install_themes
.n_entries
; i
++)
880 char *srcf
= grub_util_path_concat (3, themes_dir
,
881 install_themes
.entries
[i
],
883 if (grub_util_is_regular (srcf
))
885 char *srcd
= grub_util_path_concat (2, themes_dir
,
886 install_themes
.entries
[i
]);
887 char *dstd
= grub_util_path_concat (3, dst
, "themes",
888 install_themes
.entries
[i
]);
889 grub_install_mkdir_p (dstd
);
890 copy_all (srcd
, dstd
);
899 if (install_fonts
.is_default
)
901 install_fonts
.is_default
= 0;
902 install_fonts
.n_entries
= 1;
903 install_fonts
.entries
= xmalloc (2 * sizeof (install_fonts
.entries
[0]));
904 install_fonts
.entries
[0] = xstrdup ("unicode");
905 install_fonts
.entries
[1] = NULL
;
908 grub_install_mkdir_p (dst_fonts
);
910 for (i
= 0; i
< install_fonts
.n_entries
; i
++)
912 char *srcf
= grub_util_path_concat_ext (2, pkgdatadir
,
913 install_fonts
.entries
[i
],
915 char *dstf
= grub_util_path_concat_ext (2, dst_fonts
,
916 install_fonts
.entries
[i
],
919 grub_install_compress_file (srcf
, dstf
, 0);
928 enum grub_install_plat
929 grub_install_get_target (const char *src
)
937 fn
= grub_util_path_concat (2, src
, "modinfo.sh");
938 f
= grub_util_fd_open (fn
, GRUB_UTIL_FD_O_RDONLY
);
939 if (!GRUB_UTIL_FD_IS_VALID (f
))
940 grub_util_error (_("%s doesn't exist. Please specify --target or --directory"),
942 r
= grub_util_fd_read (f
, buf
, sizeof (buf
) - 1);
944 grub_util_error (_("cannot read `%s': %s"), fn
, strerror (errno
));
945 grub_util_fd_close (f
);
947 c
= strstr (buf
, "grub_modinfo_target_cpu=");
948 if (!c
|| (c
!= buf
&& !grub_isspace (*(c
-1))))
949 grub_util_error (_("invalid modinfo file `%s'"), fn
);
950 pl
= strstr (buf
, "grub_modinfo_platform=");
951 if (!pl
|| (pl
!= buf
&& !grub_isspace (*(pl
-1))))
952 grub_util_error (_("invalid modinfo file `%s'"), fn
);
953 c
+= sizeof ("grub_modinfo_target_cpu=") - 1;
954 pl
+= sizeof ("grub_modinfo_platform=") - 1;
955 for (p
= c
; *p
&& !grub_isspace (*p
); p
++);
957 for (p
= pl
; *p
&& !grub_isspace (*p
); p
++);
960 for (i
= 0; i
< ARRAY_SIZE (platforms
); i
++)
961 if (strcmp (platforms
[i
].cpu
, c
) == 0
962 && strcmp (platforms
[i
].platform
, pl
) == 0)
967 grub_util_error (_("Unknown platform `%s-%s'"), c
, pl
);
972 grub_util_unlink_recursive (const char *name
)
974 grub_util_fd_dir_t d
;
975 grub_util_fd_dirent_t de
;
977 d
= grub_util_fd_opendir (name
);
979 while ((de
= grub_util_fd_readdir (d
)))
982 if (strcmp (de
->d_name
, ".") == 0)
984 if (strcmp (de
->d_name
, "..") == 0)
986 fp
= grub_util_path_concat (2, name
, de
->d_name
);
987 if (grub_util_is_special_file (fp
))
992 if (grub_util_is_regular (fp
))
993 grub_util_unlink (fp
);
994 else if (grub_util_is_directory (fp
))
995 grub_util_unlink_recursive (fp
);
998 grub_util_rmdir (name
);
999 grub_util_fd_closedir (d
);