a5bd9f6
From 2b7cc814ca7d780576f2fd7fa41058a5a15a589a Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Thu, 4 Apr 2013 19:59:59 +0200
a5bd9f6
Subject: [PATCH 254/364] 	Unify file copying setup across different
a5bd9f6
 install scripts. Add 	options for performing partial install.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                 |   5 ++
a5bd9f6
 Makefile.util.def         |   7 ++
a5bd9f6
 gentpl.py                 |   4 +-
a5bd9f6
 util/grub-install.in      |  47 +++-----------
a5bd9f6
 util/grub-install_header  | 161 ++++++++++++++++++++++++++++++++++++++++++++++
a5bd9f6
 util/grub-mknetdir.in     |  47 +++-----------
a5bd9f6
 util/grub-mkrescue.in     |  42 +++---------
a5bd9f6
 util/grub-mkstandalone.in |  44 +++----------
a5bd9f6
 8 files changed, 212 insertions(+), 145 deletions(-)
a5bd9f6
 create mode 100644 util/grub-install_header
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 400a071..94f2631 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,4 +1,9 @@
a5bd9f6
 2013-04-04  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
+	Unify file copying setup across different install scripts. Add
a5bd9f6
+	options for performing partial install.
a5bd9f6
+
a5bd9f6
+2013-04-04  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 2013-04-04  Peter Jones <pjones@redhat.com>
a5bd9f6
 
a5bd9f6
 	* grub-core/disk/efi/efidisk.c: Handle partitions on non-512B disks.
a5bd9f6
diff --git a/Makefile.util.def b/Makefile.util.def
a5bd9f6
index 62bcf2d..513dc38 100644
a5bd9f6
--- a/Makefile.util.def
a5bd9f6
+++ b/Makefile.util.def
a5bd9f6
@@ -451,9 +451,13 @@ script = {
a5bd9f6
 script = {
a5bd9f6
   mansection = 1;
a5bd9f6
   name = grub-mkrescue;
a5bd9f6
+  x86 = util/grub-install_header;
a5bd9f6
   x86 = util/grub-mkrescue.in;
a5bd9f6
+  mips_qemu_mips = util/grub-install_header;
a5bd9f6
   mips_qemu_mips = util/grub-mkrescue.in;
a5bd9f6
+  mips_loongson = util/grub-install_header;
a5bd9f6
   mips_loongson = util/grub-mkrescue.in;
a5bd9f6
+  ia64_efi = util/grub-install_header;
a5bd9f6
   ia64_efi = util/grub-mkrescue.in;
a5bd9f6
   powerpc_ieee1275 = util/powerpc/ieee1275/grub-mkrescue.in;
a5bd9f6
   enable = i386_pc;
a5bd9f6
@@ -471,6 +475,7 @@ script = {
a5bd9f6
 script = {
a5bd9f6
   mansection = 1;
a5bd9f6
   name = grub-mkstandalone;
a5bd9f6
+  common = util/grub-install_header;
a5bd9f6
   common = util/grub-mkstandalone.in;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
@@ -479,6 +484,7 @@ script = {
a5bd9f6
   installdir = sbin;
a5bd9f6
   name = grub-install;
a5bd9f6
 
a5bd9f6
+  common = util/grub-install_header;
a5bd9f6
   common = util/grub-install.in;
a5bd9f6
   enable = noemu;
a5bd9f6
 };
a5bd9f6
@@ -488,6 +494,7 @@ script = {
a5bd9f6
   installdir = bin;
a5bd9f6
   name = grub-mknetdir;
a5bd9f6
 
a5bd9f6
+  common = util/grub-install_header;
a5bd9f6
   common = util/grub-mknetdir.in;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
diff --git a/gentpl.py b/gentpl.py
a5bd9f6
index 6d7f613..b159795 100644
a5bd9f6
--- a/gentpl.py
a5bd9f6
+++ b/gentpl.py
a5bd9f6
@@ -535,8 +535,8 @@ def script(platform):
a5bd9f6
     r += "[+ IF mansection +]" + manpage("grub-mkconfig_lib") + "[+ ENDIF +]"
a5bd9f6
     r += "[+ ENDIF +]"
a5bd9f6
 
a5bd9f6
-    r += rule("[+ name +]", platform_sources(platform) + " $(top_builddir)/config.status", """
a5bd9f6
-$(top_builddir)/config.status --file=$@:$<
a5bd9f6
+    r += rule("[+ name +]", "$(top_builddir)/config.status " + platform_sources(platform), """
a5bd9f6
+(skip=1; for x in $^; do if [ $$skip = 1 ]; then skip=0; else cat "$$x"; fi; done) | $(top_builddir)/config.status --file=$@:-
a5bd9f6
 chmod a+x [+ name +]
a5bd9f6
 """)
a5bd9f6
 
a5bd9f6
diff --git a/util/grub-install.in b/util/grub-install.in
a5bd9f6
index 9e63cf5..016b161 100644
a5bd9f6
--- a/util/grub-install.in
a5bd9f6
+++ b/util/grub-install.in
a5bd9f6
@@ -88,6 +88,8 @@ usage () {
a5bd9f6
     print_option_help "-h, --help" "$(gettext "print this message and exit")"
a5bd9f6
     print_option_help "-v, --version" "$(gettext "print the version information and exit")"
a5bd9f6
     print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
a5bd9f6
+    grub_print_install_files_help
a5bd9f6
+
a5bd9f6
     dirmsg="$(gettext_printf "install GRUB images under the directory DIR/%s instead of the %s directory" "@grubdirname@" "$grubdir")"
a5bd9f6
     print_option_help "--boot-directory=$(gettext "DIR")" "$dirmsg"
a5bd9f6
     # TRANSLATORS: "TARGET" as in "target platform".
a5bd9f6
@@ -120,17 +122,6 @@ echo
a5bd9f6
 gettext "Report bugs to <bug-grub@gnu.org>."; echo
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-argument () {
a5bd9f6
-  opt="$1"
a5bd9f6
-  shift
a5bd9f6
-
a5bd9f6
-  if test $# -eq 0; then
a5bd9f6
-      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
a5bd9f6
-      exit 1
a5bd9f6
-  fi
a5bd9f6
-  echo "$1"
a5bd9f6
-}
a5bd9f6
-
a5bd9f6
 allow_floppy=""
a5bd9f6
 force_file_id=
a5bd9f6
 efidir=
a5bd9f6
@@ -138,6 +129,12 @@ efidir=
a5bd9f6
 # Check the arguments.
a5bd9f6
 while test $# -gt 0
a5bd9f6
 do
a5bd9f6
+    grub_process_install_options "$@"
a5bd9f6
+    case "$grub_process_install_options_consumed" in
a5bd9f6
+	1) shift; continue;;
a5bd9f6
+	2) shift; shift; continue;;
a5bd9f6
+    esac
a5bd9f6
+
a5bd9f6
     option=$1
a5bd9f6
     shift
a5bd9f6
 
a5bd9f6
@@ -519,14 +516,8 @@ else
a5bd9f6
 fi
a5bd9f6
 
a5bd9f6
 # Copy the GRUB images to the GRUB directory.
a5bd9f6
-for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.mod "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.lst "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/*.img "${grubdir}"/${grub_modinfo_target_cpu}-$grub_modinfo_platform/efiemu??.o; do
a5bd9f6
-    if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
a5bd9f6
-	rm -f "$file" || exit 1
a5bd9f6
-    fi
a5bd9f6
-done
a5bd9f6
-for file in "${source_dir}"/*.mod "${source_dir}"/*.lst; do
a5bd9f6
-    cp -f "$file" "${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform" || exit 1
a5bd9f6
-done
a5bd9f6
+grub_install_files "${source_dir}" "${grubdir}" "${grub_modinfo_target_cpu}-$grub_modinfo_platform" all
a5bd9f6
+
a5bd9f6
 if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "sparc64-ieee1275" ] ; then
a5bd9f6
     for file in "${source_dir}"/*.img "${source_dir}"/efiemu??.o; do
a5bd9f6
 	if test -f "$file"; then
a5bd9f6
@@ -535,24 +526,6 @@ if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-pc" ] || [ "$
a5bd9f6
     done
a5bd9f6
 fi
a5bd9f6
 
a5bd9f6
-# Copy gettext files
a5bd9f6
-mkdir -p "${grubdir}"/locale/
a5bd9f6
-for dir in "${localedir}"/*; do
a5bd9f6
-    if test -f "$dir/LC_MESSAGES/grub.mo"; then
a5bd9f6
-        cp -f "$dir/LC_MESSAGES/grub.mo" "${grubdir}/locale/${dir##*/}.mo"
a5bd9f6
-    fi
a5bd9f6
-done
a5bd9f6
-
a5bd9f6
-if test -f "${pkgdatadir}"/themes/starfield/theme.txt; then
a5bd9f6
-    mkdir -p "${grubdir}"/themes/starfield
a5bd9f6
-    cp "${pkgdatadir}"/themes/starfield/* "${grubdir}"/themes/starfield
a5bd9f6
-fi
a5bd9f6
-
a5bd9f6
-if test -f "${pkgdatadir}"/unicode.pf2; then
a5bd9f6
-    mkdir -p "${grubdir}"/fonts
a5bd9f6
-    cp "${pkgdatadir}"/unicode.pf2 "${grubdir}"/fonts
a5bd9f6
-fi
a5bd9f6
-
a5bd9f6
 if ! is_path_readable_by_grub "${grubdir}"; then
a5bd9f6
     gettext_printf "Path \`%s' is not readable by GRUB on boot. Installation is impossible. Aborting.\n" "${grubdir}" 1>&2
a5bd9f6
     exit 1
a5bd9f6
diff --git a/util/grub-install_header b/util/grub-install_header
a5bd9f6
new file mode 100644
a5bd9f6
index 0000000..7c2c0a5
a5bd9f6
--- /dev/null
a5bd9f6
+++ b/util/grub-install_header
a5bd9f6
@@ -0,0 +1,161 @@
a5bd9f6
+#! /bin/sh
a5bd9f6
+set -e
a5bd9f6
+
a5bd9f6
+# Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012  Free Software Foundation, Inc.
a5bd9f6
+#
a5bd9f6
+# GRUB is free software: you can redistribute it and/or modify
a5bd9f6
+# it under the terms of the GNU General Public License as published by
a5bd9f6
+# the Free Software Foundation, either version 3 of the License, or
a5bd9f6
+# (at your option) any later version.
a5bd9f6
+#
a5bd9f6
+# GRUB is distributed in the hope that it will be useful,
a5bd9f6
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f6
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f6
+# GNU General Public License for more details.
a5bd9f6
+#
a5bd9f6
+# You should have received a copy of the GNU General Public License
a5bd9f6
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a5bd9f6
+
a5bd9f6
+pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst \
a5bd9f6
+handler.lst video.lst crypto.lst terminal.lst"
a5bd9f6
+
a5bd9f6
+grub_install_files () {
a5bd9f6
+    grub_install_files_source_directory="$1"
a5bd9f6
+    grub_install_files_target_directory="$2"
a5bd9f6
+    grub_install_files_platform="$3"
a5bd9f6
+    
a5bd9f6
+    mkdir -p "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
a5bd9f6
+    
a5bd9f6
+    for file in "${grub_install_files_target_directory}"/*.mod \
a5bd9f6
+"${grub_install_files_target_directory}"/*.lst \
a5bd9f6
+"${grub_install_files_target_directory}"/*.img \
a5bd9f6
+"${grub_install_files_target_directory}"/efiemu??.o \
a5bd9f6
+"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.mod \
a5bd9f6
+"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.lst \
a5bd9f6
+"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/*.img \
a5bd9f6
+"${grub_install_files_target_directory}"/"${grub_install_files_platform}"/efiemu??.o;
a5bd9f6
+    do
a5bd9f6
+	if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
a5bd9f6
+	    rm -f "$file" || exit 1
a5bd9f6
+	fi
a5bd9f6
+    done
a5bd9f6
+
a5bd9f6
+    if [ x"$install_modules" = xall ]; then
a5bd9f6
+	for file in "${grub_install_files_source_directory}/"*.mod; do
a5bd9f6
+	    cp -f "$file" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
a5bd9f6
+	done
a5bd9f6
+    else
a5bd9f6
+	modules1=
a5bd9f6
+	modules2="$install_modules"
a5bd9f6
+	while [ x"$modules2" != x ]; do
a5bd9f6
+	    modules3=
a5bd9f6
+	    for x in $modules2; do
a5bd9f6
+		modules3="$modules3 $(grep "^$x:" "${grub_install_files_source_directory}/moddep.lst" | sed 's,^[^:]*:,,')"
a5bd9f6
+	    done
a5bd9f6
+	    modules1="$modules1 $modules2"
a5bd9f6
+	    modules2="$modules3"
a5bd9f6
+	done
a5bd9f6
+	for file in $(echo "$modules1" | sed 's, ,\n,g' |sort -u); do
a5bd9f6
+	    cp -f "${grub_install_files_source_directory}/$file.mod" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
a5bd9f6
+	done
a5bd9f6
+    fi
a5bd9f6
+    
a5bd9f6
+    for file in ${pkglib_DATA} efiemu32.o efiemu64.o; do
a5bd9f6
+	if test -f "${grub_install_files_source_directory}/${file}"; then
a5bd9f6
+            cp -f "${grub_install_files_source_directory}/${file}" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
a5bd9f6
+	fi
a5bd9f6
+    done
a5bd9f6
+    
a5bd9f6
+    # Copy gettext files
a5bd9f6
+    mkdir -p "${grub_install_files_target_directory}"/locale
a5bd9f6
+
a5bd9f6
+    for file in "${grub_install_files_target_directory}"/locale/*.mo; do
a5bd9f6
+	if test -f "$file"; then
a5bd9f6
+	    rm -f "$file" || exit 1
a5bd9f6
+	fi
a5bd9f6
+    done
a5bd9f6
+
a5bd9f6
+    if [ x"$install_locales" = xall ]; then
a5bd9f6
+	for file in "${grub_install_files_source_directory}"/po/*.mo; do
a5bd9f6
+	    if test -f "$file"; then
a5bd9f6
+		cp -f "$file" "${grub_install_files_target_directory}"/locale/
a5bd9f6
+	    fi
a5bd9f6
+	done
a5bd9f6
+	for dir in "${localedir}"/*; do
a5bd9f6
+	    if test -f "$dir/LC_MESSAGES/grub.mo" && ! test -f "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"; then
a5bd9f6
+		cp -f "$dir/LC_MESSAGES/grub.mo" "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"
a5bd9f6
+	    fi
a5bd9f6
+	done
a5bd9f6
+    else
a5bd9f6
+	for locale in $install_locales; do
a5bd9f6
+	    if test -f "${grub_install_files_source_directory}"/po/$locale.mo; then
a5bd9f6
+		cp -f " "${grub_install_files_source_directory}"/po/$locale.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
a5bd9f6
+	    elif test -f "${localedir}/$locale/LC_MESSAGES/grub.mo"; then
a5bd9f6
+		cp -f "${localedir}/$locale/LC_MESSAGES/grub.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
a5bd9f6
+	    fi
a5bd9f6
+	done
a5bd9f6
+    fi
a5bd9f6
+    for theme in ${install_themes} ; do
a5bd9f6
+	if test -f "${pkgdatadir}"/themes/"${theme}"/theme.txt; then
a5bd9f6
+	    mkdir -p "${grub_install_files_target_directory}"/themes/"${theme}"
a5bd9f6
+	    cp "${pkgdatadir}"/themes/"${theme}"/* "${grub_install_files_target_directory}"/themes/"${theme}"
a5bd9f6
+	fi
a5bd9f6
+    done
a5bd9f6
+
a5bd9f6
+    for font in ${install_fonts} ; do
a5bd9f6
+	if test -f "${pkgdatadir}"/"$font".pf2; then
a5bd9f6
+	    mkdir -p "${grub_install_files_target_directory}"/fonts
a5bd9f6
+	    cp "${pkgdatadir}"/"$font".pf2 "${grub_install_files_target_directory}"/fonts
a5bd9f6
+	fi
a5bd9f6
+    done
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+grub_print_install_files_help () {
a5bd9f6
+    print_option_help "--install-modules=$(gettext "MODULES")" "$(gettext "install only MODULES and their dependencies [default=all]")"
a5bd9f6
+    print_option_help "--themes=THEMES" "$(gettext_printf "install THEMES [default=%s]" "starfield")"
a5bd9f6
+    print_option_help "--fonts=FONTS" "$(gettext_printf "install FONTS [default=%s]" "unicode")"
a5bd9f6
+    print_option_help "--locales=LOCALES" "$(gettext_printf "install only LOCALES [default=all]")"
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+install_modules=all
a5bd9f6
+install_themes=starfield
a5bd9f6
+install_fonts=unicode
a5bd9f6
+install_locales=all
a5bd9f6
+
a5bd9f6
+argument () {
a5bd9f6
+  opt=$1
a5bd9f6
+  shift
a5bd9f6
+
a5bd9f6
+  if test $# -eq 0; then
a5bd9f6
+      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
a5bd9f6
+      exit 1
a5bd9f6
+  fi
a5bd9f6
+  echo $1
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+grub_process_install_options () {
a5bd9f6
+    option=$1
a5bd9f6
+    shift
a5bd9f6
+
a5bd9f6
+    grub_process_install_options_consumed=0
a5bd9f6
+
a5bd9f6
+    case "$option" in
a5bd9f6
+	--install-modules)
a5bd9f6
+	    install_modules=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
a5bd9f6
+	--install-modules=*)
a5bd9f6
+            install_modules=`echo "$option" | sed 's/--install-modules=//'`; grub_process_install_options_consumed=1; return ;;
a5bd9f6
+	--themes)
a5bd9f6
+	    install_themes=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
a5bd9f6
+	--themes=*)
a5bd9f6
+            install_themes=`echo "$option" | sed 's/--themes=//'`; grub_process_install_options_consumed=1; return ;;
a5bd9f6
+	--fonts)
a5bd9f6
+	    install_fonts=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
a5bd9f6
+	--fonts=*)
a5bd9f6
+            install_fonts=`echo "$option" | sed 's/--fonts=//'`; grub_process_install_options_consumed=1; return ;;
a5bd9f6
+	--locales)
a5bd9f6
+	    install_locales=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
a5bd9f6
+	--locales=*)
a5bd9f6
+            install_locales=`echo "$option" | sed 's/--locales=//'`; grub_process_install_options_consumed=1; return ;;
a5bd9f6
+    esac
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in
a5bd9f6
index e235af3..6df761a 100644
a5bd9f6
--- a/util/grub-mknetdir.in
a5bd9f6
+++ b/util/grub-mknetdir.in
a5bd9f6
@@ -1,5 +1,3 @@
a5bd9f6
-#! /bin/sh
a5bd9f6
-
a5bd9f6
 # Install GRUB on your drive.
a5bd9f6
 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
a5bd9f6
 #
a5bd9f6
@@ -26,7 +24,6 @@ PACKAGE_NAME=@PACKAGE_NAME@
a5bd9f6
 PACKAGE_TARNAME=@PACKAGE_TARNAME@
a5bd9f6
 PACKAGE_VERSION=@PACKAGE_VERSION@
a5bd9f6
 host_os=@host_os@
a5bd9f6
-pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
a5bd9f6
 datadir="@datadir@"
a5bd9f6
 if [ "x$pkgdatadir" = x ]; then
a5bd9f6
     pkgdatadir="${datadir}/@PACKAGE@"
a5bd9f6
@@ -65,6 +62,7 @@ usage () {
a5bd9f6
     print_option_help "-h, --help" "$(gettext "print this message and exit")"
a5bd9f6
     print_option_help "-v, --version" "$(gettext "print the version information and exit")"
a5bd9f6
     print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
a5bd9f6
+    grub_print_install_files_help
a5bd9f6
     print_option_help "--net-directory=$(gettext "DIR")" "$(gettext "root directory of TFTP server")"
a5bd9f6
     print_option_help "--subdir=$(gettext "DIR")" "$(gettext "relative subdirectory on network server")"
a5bd9f6
     print_option_help "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
a5bd9f6
@@ -77,20 +75,15 @@ usage () {
a5bd9f6
     gettext "Report bugs to <bug-grub@gnu.org>."; echo
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-argument () {
a5bd9f6
-  opt=$1
a5bd9f6
-  shift
a5bd9f6
-
a5bd9f6
-  if test $# -eq 0; then
a5bd9f6
-      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
a5bd9f6
-      exit 1
a5bd9f6
-  fi
a5bd9f6
-  echo $1
a5bd9f6
-}
a5bd9f6
-
a5bd9f6
 # Check the arguments.
a5bd9f6
 while test $# -gt 0
a5bd9f6
 do
a5bd9f6
+    grub_process_install_options "$@"
a5bd9f6
+    case "$grub_process_install_options_consumed" in
a5bd9f6
+	1) shift; continue;;
a5bd9f6
+	2) shift; shift; continue;;
a5bd9f6
+    esac
a5bd9f6
+
a5bd9f6
     option=$1
a5bd9f6
     shift
a5bd9f6
 
a5bd9f6
@@ -166,32 +159,10 @@ process_input_dir ()
a5bd9f6
     platform="$2"
a5bd9f6
     grubdir="${rootdir}/${subdir}/${platform}"
a5bd9f6
     config_opt=
a5bd9f6
-    mkdir -p "$grubdir" || exit 1
a5bd9f6
-
a5bd9f6
-    for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o; do
a5bd9f6
-	if test -f "$file" && [ "`basename $file`" != menu.lst ]; then
a5bd9f6
-	    rm -f "$file" || exit 1
a5bd9f6
-	fi
a5bd9f6
-    done
a5bd9f6
-    for file in "${input_dir}"/*.mod; do
a5bd9f6
-        if test -f "$file"; then
a5bd9f6
-            cp -f "$file" "$grubdir/"
a5bd9f6
-        fi
a5bd9f6
-    done
a5bd9f6
-    for file in ${pkglib_DATA}; do
a5bd9f6
-	if test -f "${input_dir}/${file}"; then
a5bd9f6
-            cp -f "${input_dir}/${file}" "$grubdir/"
a5bd9f6
-	fi
a5bd9f6
-    done
a5bd9f6
 
a5bd9f6
-    mkdir -p "$grubdir/locale"
a5bd9f6
-    for file in ${input_dir}/po/*.mo; do
a5bd9f6
-        if test -f "$file"; then
a5bd9f6
-	    cp -f "$file" "$grubdir/locale/"
a5bd9f6
-	fi
a5bd9f6
-    done
a5bd9f6
+    grub_install_files "${input_dir}" "${rootdir}/${subdir}" "${platform}"
a5bd9f6
 
a5bd9f6
-    rm -f ${grubdir}/load.cfg
a5bd9f6
+    rm -f "${grubdir}"/load.cfg
a5bd9f6
 
a5bd9f6
     if [ "x${debug_image}" != x ]; then
a5bd9f6
        echo "set debug='${debug_image}'" >> ${grubdir}/load.cfg
a5bd9f6
diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in
a5bd9f6
index d279a9d..c57a0d9 100644
a5bd9f6
--- a/util/grub-mkrescue.in
a5bd9f6
+++ b/util/grub-mkrescue.in
a5bd9f6
@@ -1,5 +1,3 @@
a5bd9f6
-#! /bin/sh
a5bd9f6
-set -e
a5bd9f6
 
a5bd9f6
 # Make GRUB rescue image
a5bd9f6
 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
a5bd9f6
@@ -70,6 +68,8 @@ usage () {
a5bd9f6
     print_option_help "-v, --version" "$(gettext "print the version information and exit")"
a5bd9f6
     print_option_help "-o, --output=$filetrans" "$(gettext "save output in FILE [required]")"
a5bd9f6
     print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
a5bd9f6
+    grub_print_install_files_help
a5bd9f6
+    print_option_help "--install-modules=$(gettext "MODULES")" "$(gettext "install only MODULES and their dependencies on bootable media")"
a5bd9f6
     print_option_help "--rom-directory=$(gettext "DIR")" "$(gettext "save ROM images in DIR [optional]")"
a5bd9f6
     # TRANSLATORS: xorriso is a program for creating ISOs and burning CDs
a5bd9f6
     print_option_help "--xorriso=$filetrans" "$(gettext "use FILE as xorriso [optional]")"
a5bd9f6
@@ -83,20 +83,15 @@ usage () {
a5bd9f6
     gettext "Mail xorriso support requests to <bug-xorriso@gnu.org>."; echo
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-argument () {
a5bd9f6
-  opt=$1
a5bd9f6
-  shift
a5bd9f6
-
a5bd9f6
-  if test $# -eq 0; then
a5bd9f6
-      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
a5bd9f6
-      exit 1
a5bd9f6
-  fi
a5bd9f6
-  echo $1
a5bd9f6
-}
a5bd9f6
-
a5bd9f6
 # Check the arguments.
a5bd9f6
 while test $# -gt 0
a5bd9f6
 do
a5bd9f6
+    grub_process_install_options "$@"
a5bd9f6
+    case "$grub_process_install_options_consumed" in
a5bd9f6
+	1) shift; continue;;
a5bd9f6
+	2) shift; shift; continue;;
a5bd9f6
+    esac
a5bd9f6
+
a5bd9f6
     option=$1
a5bd9f6
     shift
a5bd9f6
 
a5bd9f6
@@ -171,26 +166,7 @@ mkdir -p ${iso9660_dir}/boot/grub
a5bd9f6
 
a5bd9f6
 process_input_dir ()
a5bd9f6
 {
a5bd9f6
-    input_dir="$1"
a5bd9f6
-    platform="$2"
a5bd9f6
-    mkdir -p "${iso9660_dir}/boot/grub/${platform}"
a5bd9f6
-    for file in "${input_dir}/"*.mod "${input_dir}/"efiemu32.o "${input_dir}/"efiemu64.o; do
a5bd9f6
-        if test -f "$file"; then
a5bd9f6
-            cp -f "$file" "${iso9660_dir}/boot/grub/${platform}/"
a5bd9f6
-        fi
a5bd9f6
-    done
a5bd9f6
-    for file in ${pkglib_DATA}; do
a5bd9f6
-	if test -f "${input_dir}/${file}"; then
a5bd9f6
-            cp -f "${input_dir}/${file}" "${iso9660_dir}/boot/grub/${platform}/"
a5bd9f6
-	fi
a5bd9f6
-    done
a5bd9f6
-
a5bd9f6
-    mkdir -p "${iso9660_dir}/boot/grub/locale"
a5bd9f6
-    for dir in "${localedir}"/*; do
a5bd9f6
-	if test -f "$dir/LC_MESSAGES/grub.mo"; then
a5bd9f6
-            cp -f "$dir/LC_MESSAGES/grub.mo" "${iso9660_dir}/boot/grub/locale/${dir##*/}.mo"
a5bd9f6
-	fi
a5bd9f6
-    done
a5bd9f6
+    grub_install_files "$1" "${iso9660_dir}/boot/grub" "$2"
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 make_image ()
a5bd9f6
diff --git a/util/grub-mkstandalone.in b/util/grub-mkstandalone.in
a5bd9f6
index 78b83e0..a5434c4 100644
a5bd9f6
--- a/util/grub-mkstandalone.in
a5bd9f6
+++ b/util/grub-mkstandalone.in
a5bd9f6
@@ -1,5 +1,4 @@
a5bd9f6
-#! /bin/sh
a5bd9f6
-set -e
a5bd9f6
+#!/bin/sh
a5bd9f6
 
a5bd9f6
 # Make GRUB rescue image
a5bd9f6
 # Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012  Free Software Foundation, Inc.
a5bd9f6
@@ -27,7 +26,6 @@ libdir="@libdir@"
a5bd9f6
 PACKAGE_NAME=@PACKAGE_NAME@
a5bd9f6
 PACKAGE_TARNAME=@PACKAGE_TARNAME@
a5bd9f6
 PACKAGE_VERSION=@PACKAGE_VERSION@
a5bd9f6
-pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst"
a5bd9f6
 datadir="@datadir@"
a5bd9f6
 if [ "x$pkgdatadir" = x ]; then
a5bd9f6
     pkgdatadir="${datadir}/@PACKAGE@"
a5bd9f6
@@ -64,25 +62,21 @@ usage () {
a5bd9f6
     echo
a5bd9f6
     print_option_help "-C, --compression=(xz|none|auto)" "$(gettext "choose the compression to use")"
a5bd9f6
     print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
a5bd9f6
+    grub_print_install_files_help
a5bd9f6
     print_option_help  "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
a5bd9f6
     echo
a5bd9f6
     gettext "Report bugs to <bug-grub@gnu.org>."; echo
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-argument () {
a5bd9f6
-  opt=$1
a5bd9f6
-  shift
a5bd9f6
-
a5bd9f6
-  if test $# -eq 0; then
a5bd9f6
-      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
a5bd9f6
-      exit 1
a5bd9f6
-  fi
a5bd9f6
-  echo $1
a5bd9f6
-}
a5bd9f6
-
a5bd9f6
 # Check the arguments.
a5bd9f6
 while test $# -gt 0
a5bd9f6
 do
a5bd9f6
+    grub_process_install_options "$@"
a5bd9f6
+    case "$grub_process_install_options_consumed" in
a5bd9f6
+	1) shift; continue;;
a5bd9f6
+	2) shift; shift; continue;;
a5bd9f6
+    esac
a5bd9f6
+
a5bd9f6
     option=$1
a5bd9f6
     shift
a5bd9f6
 
a5bd9f6
@@ -167,27 +161,7 @@ else
a5bd9f6
 fi
a5bd9f6
 
a5bd9f6
 memdisk_dir="`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
a5bd9f6
-mkdir -p "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
a5bd9f6
-
a5bd9f6
-for file in "${source_directory}/"*.mod "${source_directory}/"efiemu32.o "${source_directory}/"efiemu64.o; do
a5bd9f6
-    if test -f "$file"; then
a5bd9f6
-        cp -f "$file" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
a5bd9f6
-    fi
a5bd9f6
-done
a5bd9f6
-
a5bd9f6
-for file in ${pkglib_DATA}; do
a5bd9f6
-    if test -f "${source_directory}/${file}"; then
a5bd9f6
-        cp -f "${source_directory}/${file}" "${memdisk_dir}"/boot/grub/"${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
a5bd9f6
-    fi
a5bd9f6
-done
a5bd9f6
-
a5bd9f6
-mkdir -p "${memdisk_dir}"/boot/grub/locale
a5bd9f6
-for file in "${source_directory}"/po/*.mo; do
a5bd9f6
-    if test -f "$file"; then
a5bd9f6
-	cp -f "$file" "${memdisk_dir}"/boot/grub/locale/
a5bd9f6
-    fi
a5bd9f6
-done
a5bd9f6
-
a5bd9f6
+grub_install_files "${source_directory}" "${memdisk_dir}"/boot/grub "${grub_modinfo_target_cpu}-${grub_modinfo_platform}"
a5bd9f6
 for file in $source; do
a5bd9f6
     cp -f "$file" "${memdisk_dir}"/"$file";
a5bd9f6
 done
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6