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