dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0311-Add-option-to-compress-files-on-install-image-creati.patch

f96e0b
From a0404f547d5b693dd86a2773f1fd64ca207ad2bf Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sun, 14 Apr 2013 19:24:05 +0200
f96e0b
Subject: [PATCH 311/482] 	Add option to compress files on install/image
f96e0b
 creation.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                 |  4 ++++
f96e0b
 util/grub-install.in      |  8 +++----
f96e0b
 util/grub-install_header  | 61 ++++++++++++++++++++++++++++++++++++++++-------
f96e0b
 util/grub-mkimage.c       |  2 +-
f96e0b
 util/grub-mknetdir.in     |  2 +-
f96e0b
 util/grub-mkrescue.in     |  6 ++---
f96e0b
 util/grub-mkstandalone.in |  4 ++--
f96e0b
 7 files changed, 67 insertions(+), 20 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index c01ae94..8cbf241 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,7 @@
f96e0b
+2013-04-14  Szymon Janc <szymon@janc.net.pl>
f96e0b
+
f96e0b
+	Add option to compress files on install/image creation.
f96e0b
+
f96e0b
 2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* docs/grub-dev.texi: Rearrange menu to match the section order.
f96e0b
diff --git a/util/grub-install.in b/util/grub-install.in
f96e0b
index 016b161..32a3be3 100644
f96e0b
--- a/util/grub-install.in
f96e0b
+++ b/util/grub-install.in
f96e0b
@@ -684,9 +684,9 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
f96e0b
 esac
f96e0b
 
f96e0b
 if [ x"$config_opt_file" = x ]; then
f96e0b
-    "$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
f96e0b
+    "$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $grub_decompression_module $modules || exit 1
f96e0b
 else
f96e0b
-    "$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $modules || exit 1
f96e0b
+    "$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/core.${imgext}" --prefix="${prefix_drive}${relative_grubdir}" $grub_decompression_module $modules || exit 1
f96e0b
 fi
f96e0b
 
f96e0b
 # Backward-compatibility kludges
f96e0b
@@ -697,9 +697,9 @@ elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-ieee1275" ]
f96e0b
 elif [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "i386-efi" ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = "x86_64-efi" ]; then
f96e0b
 
f96e0b
     if [ x"$config_opt_file" = x ]; then
f96e0b
-	"$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $modules || exit 1
f96e0b
+	"$grub_mkimage" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $grub_decompression_module $modules || exit 1
f96e0b
     else
f96e0b
-	"$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $modules || exit 1
f96e0b
+	"$grub_mkimage" -c "${config_opt_file}" -d "${source_dir}" -O "${mkimage_target}" --output="${grubdir}/${grub_modinfo_target_cpu}-$grub_modinfo_platform/grub.efi" --prefix="" $grub_decompression_module $modules || exit 1
f96e0b
     fi
f96e0b
 fi
f96e0b
 
f96e0b
diff --git a/util/grub-install_header b/util/grub-install_header
f96e0b
index 69aac46..805fc4f 100644
f96e0b
--- a/util/grub-install_header
f96e0b
+++ b/util/grub-install_header
f96e0b
@@ -19,6 +19,14 @@ set -e
f96e0b
 pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst \
f96e0b
 handler.lst video.lst crypto.lst terminal.lst"
f96e0b
 
f96e0b
+grub_compress_file () {
f96e0b
+    if [ "$compressor" != "" ] ; then
f96e0b
+        "$compressor" $compressor_opts "$1" > "$2"
f96e0b
+    else
f96e0b
+        cp -f "$1" "$2"
f96e0b
+    fi
f96e0b
+}
f96e0b
+
f96e0b
 grub_install_files () {
f96e0b
     grub_install_files_source_directory="$1"
f96e0b
     grub_install_files_target_directory="$2"
f96e0b
@@ -42,7 +50,7 @@ grub_install_files () {
f96e0b
 
f96e0b
     if [ x"$install_modules" = xall ]; then
f96e0b
 	for file in "${grub_install_files_source_directory}/"*.mod; do
f96e0b
-	    cp -f "$file" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
f96e0b
+	    grub_compress_file "$file" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/$(basename "$file")"
f96e0b
 	done
f96e0b
     else
f96e0b
 	modules1=
f96e0b
@@ -56,13 +64,13 @@ grub_install_files () {
f96e0b
 	    modules2="$modules3"
f96e0b
 	done
f96e0b
 	for file in $(echo "$modules1" | sed 's, ,\n,g' |sort -u); do
f96e0b
-	    cp -f "${grub_install_files_source_directory}/$file.mod" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
f96e0b
+	    grub_compress_file "${grub_install_files_source_directory}/$file.mod" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/$file.mod"
f96e0b
 	done
f96e0b
     fi
f96e0b
     
f96e0b
     for file in ${pkglib_DATA} efiemu32.o efiemu64.o; do
f96e0b
 	if test -f "${grub_install_files_source_directory}/${file}"; then
f96e0b
-            cp -f "${grub_install_files_source_directory}/${file}" "${grub_install_files_target_directory}"/"${grub_install_files_platform}"
f96e0b
+            grub_compress_file "${grub_install_files_source_directory}/${file}" "${grub_install_files_target_directory}"/"${grub_install_files_platform}/${file}"
f96e0b
 	fi
f96e0b
     done
f96e0b
     
f96e0b
@@ -78,34 +86,36 @@ grub_install_files () {
f96e0b
     if [ x"$install_locales" = xall ]; then
f96e0b
 	for file in "${grub_install_files_source_directory}"/po/*.mo; do
f96e0b
 	    if test -f "$file"; then
f96e0b
-		cp -f "$file" "${grub_install_files_target_directory}"/locale/
f96e0b
+		grub_compress_file "$file" "${grub_install_files_target_directory}"/locale/"$(basename "$file")"
f96e0b
 	    fi
f96e0b
 	done
f96e0b
 	for dir in "${localedir}"/*; do
f96e0b
 	    if test -f "$dir/LC_MESSAGES/@PACKAGE@.mo" && ! test -f "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"; then
f96e0b
-		cp -f "$dir/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"
f96e0b
+		grub_compress_file "$dir/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/"${dir##*/}.mo"
f96e0b
 	    fi
f96e0b
 	done
f96e0b
     else
f96e0b
 	for locale in $install_locales; do
f96e0b
 	    if test -f "${grub_install_files_source_directory}"/po/$locale.mo; then
f96e0b
-		cp -f " "${grub_install_files_source_directory}"/po/$locale.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
f96e0b
+		grub_compress_file "${grub_install_files_source_directory}"/po/locale.mo "${grub_install_files_target_directory}"/locale/$locale.mo
f96e0b
 	    elif test -f "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo"; then
f96e0b
-		cp -f "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
f96e0b
+		grub_compress_file "${localedir}/$locale/LC_MESSAGES/@PACKAGE@.mo" "${grub_install_files_target_directory}"/locale/$locale.mo
f96e0b
 	    fi
f96e0b
 	done
f96e0b
     fi
f96e0b
     for theme in ${install_themes} ; do
f96e0b
 	if test -f "${pkgdatadir}"/themes/"${theme}"/theme.txt; then
f96e0b
 	    mkdir -p "${grub_install_files_target_directory}"/themes/"${theme}"
f96e0b
-	    cp "${pkgdatadir}"/themes/"${theme}"/* "${grub_install_files_target_directory}"/themes/"${theme}"
f96e0b
+	    for file in "${pkgdatadir}"/themes/"${theme}"/*; do
f96e0b
+		grub_compress_file "$file" "${grub_install_files_target_directory}"/themes/"${theme}"/"$(basename "$file")"
f96e0b
+	    done
f96e0b
 	fi
f96e0b
     done
f96e0b
 
f96e0b
     for font in ${install_fonts} ; do
f96e0b
 	if test -f "${pkgdatadir}"/"$font".pf2; then
f96e0b
 	    mkdir -p "${grub_install_files_target_directory}"/fonts
f96e0b
-	    cp "${pkgdatadir}"/"$font".pf2 "${grub_install_files_target_directory}"/fonts
f96e0b
+	    grub_compress_file "${pkgdatadir}"/"$font".pf2 "${grub_install_files_target_directory}"/fonts/"$font".pf2
f96e0b
 	fi
f96e0b
     done
f96e0b
 }
f96e0b
@@ -115,12 +125,17 @@ grub_print_install_files_help () {
f96e0b
     print_option_help "--themes=THEMES" "$(gettext_printf "install THEMES [default=%s]" "starfield")"
f96e0b
     print_option_help "--fonts=FONTS" "$(gettext_printf "install FONTS [default=%s]" "unicode")"
f96e0b
     print_option_help "--locales=LOCALES" "$(gettext_printf "install only LOCALES [default=all]")"
f96e0b
+    print_option_help "--compress[=no,xz,gz,lzo]" "$(gettext "compress GRUB files [optional]")"
f96e0b
 }
f96e0b
 
f96e0b
 install_modules=all
f96e0b
 install_themes=starfield
f96e0b
 install_fonts=unicode
f96e0b
 install_locales=all
f96e0b
+compress=no
f96e0b
+grub_decompression_module=""
f96e0b
+compressor=""
f96e0b
+compressor_opts=""
f96e0b
 
f96e0b
 argument () {
f96e0b
   opt=$1
f96e0b
@@ -133,6 +148,29 @@ argument () {
f96e0b
   echo $1
f96e0b
 }
f96e0b
 
f96e0b
+grub_parse_compress () {
f96e0b
+    compress="$1"
f96e0b
+    case x"$compress" in
f96e0b
+	xno) ;;
f96e0b
+	xgz)
f96e0b
+	    compressor=`which gzip || true`
f96e0b
+	    grub_decompression_module="gzio"
f96e0b
+	    compressor_opts="--best --stdout";;
f96e0b
+	xxz)
f96e0b
+	    compressor=`which xz || true`
f96e0b
+	    grub_decompression_module="xzio gcry_crc"
f96e0b
+	    compressor_opts="--lzma2=dict=128KiB --check=none --stdout";;
f96e0b
+	xlzo)
f96e0b
+	    compressor=`which lzop || true`
f96e0b
+	    grub_decompression_module="lzopio adler32 gcry_crc"
f96e0b
+	    compressor_opts="-9 -c";;
f96e0b
+	*)
f96e0b
+	    gettext_printf "Unrecognized compression \`%s'\n" "$compress" 1>&2
f96e0b
+	    usage
f96e0b
+	    exit 1
f96e0b
+    esac
f96e0b
+}
f96e0b
+
f96e0b
 grub_process_install_options () {
f96e0b
     option=$1
f96e0b
     shift
f96e0b
@@ -156,6 +194,11 @@ grub_process_install_options () {
f96e0b
 	    install_locales=`argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
f96e0b
 	--locales=*)
f96e0b
             install_locales=`echo "$option" | sed 's/--locales=//'`; grub_process_install_options_consumed=1; return ;;
f96e0b
+	--compress)
f96e0b
+	    grub_parse_compress `argument $option "$@"`; grub_process_install_options_consumed=2; return ;;
f96e0b
+        --compress=*)
f96e0b
+            grub_parse_compress `echo "${option}" | sed 's/--compress=//'`; grub_process_install_options_consumed=1; return ;;
f96e0b
     esac
f96e0b
 }
f96e0b
 
f96e0b
+export grub_decompression_module
f96e0b
diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
f96e0b
index 96279a4..0acc61e 100644
f96e0b
--- a/util/grub-mkimage.c
f96e0b
+++ b/util/grub-mkimage.c
f96e0b
@@ -1740,7 +1740,7 @@ static struct argp_option options[] = {
f96e0b
   {"note",   'n', 0, 0, N_("add NOTE segment for CHRP IEEE1275"), 0},
f96e0b
   {"output",  'o', N_("FILE"), 0, N_("output a generated image to FILE [default=stdout]"), 0},
f96e0b
   {"format",  'O', N_("FORMAT"), 0, 0, 0},
f96e0b
-  {"compression",  'C', "(xz|none|auto)", 0, N_("choose the compression to use"), 0},
f96e0b
+  {"compression",  'C', "(xz|none|auto)", 0, N_("choose the compression to use for core image"), 0},
f96e0b
   {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
f96e0b
   { 0, 0, 0, 0, 0, 0 }
f96e0b
 };
f96e0b
diff --git a/util/grub-mknetdir.in b/util/grub-mknetdir.in
f96e0b
index 6df761a..d32de46 100644
f96e0b
--- a/util/grub-mknetdir.in
f96e0b
+++ b/util/grub-mknetdir.in
f96e0b
@@ -191,7 +191,7 @@ process_input_dir ()
f96e0b
 source ${subdir}/grub.cfg
f96e0b
 EOF
f96e0b
 
f96e0b
-    "$grub_mkimage" ${config_opt} -d "${input_dir}" -O ${mkimage_target} "--output=${grubdir}/core.$ext" "--prefix=$prefix" $modules $netmodules tftp || exit 1
f96e0b
+    "$grub_mkimage" ${config_opt} -d "${input_dir}" -O ${mkimage_target} "--output=${grubdir}/core.$ext" "--prefix=$prefix" $modules $grub_decompression_module $netmodules tftp || exit 1
f96e0b
     # TRANSLATORS: First %s is replaced by platform name. Second one by filename.
f96e0b
     gettext_printf "Netboot directory for %s created. Configure your DHCP server to point to %s\n" "${platform}" "${subdir}/${platform}/core.$ext"
f96e0b
 }
f96e0b
diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in
f96e0b
index b97d674..7270d7f 100644
f96e0b
--- a/util/grub-mkrescue.in
f96e0b
+++ b/util/grub-mkrescue.in
f96e0b
@@ -248,7 +248,7 @@ EOF
f96e0b
     done ; ) > "${load_cfg}"
f96e0b
 
f96e0b
     "$grub_mkimage" -O ${platform} -d "${source_directory}" -c "${load_cfg}" -o "$3" \
f96e0b
-        search iso9660 $4
f96e0b
+        $grub_decompression_module search iso9660 $4
f96e0b
     rm -rf "${load_cfg}"
f96e0b
 }
f96e0b
 
f96e0b
@@ -263,7 +263,7 @@ make_image_fwdisk ()
f96e0b
     gettext_printf "Enabling %s support ...\n" "$2"
f96e0b
 
f96e0b
     "$grub_mkimage" -O ${platform} -d "${source_directory}" -p '()/boot/grub' -o "$3" \
f96e0b
-        iso9660 $4
f96e0b
+        $grub_decompression_module iso9660 $4
f96e0b
 }
f96e0b
 
f96e0b
 if [ "${override_dir}" = "" ] ; then
f96e0b
@@ -362,7 +362,7 @@ if test -e "${pc_dir}" ; then
f96e0b
     done ;) > "${load_cfg}"
f96e0b
 
f96e0b
     "$grub_mkimage" -O i386-pc -d "${pc_dir}/" -o "${core_img}" -c "$load_cfg" --prefix=/boot/grub \
f96e0b
-        iso9660 biosdisk
f96e0b
+        $grub_decompression_module iso9660 biosdisk
f96e0b
     cat "${pc_dir}/cdboot.img" "${core_img}" > "${iso9660_dir}/boot/grub/i386-pc/eltorito.img"
f96e0b
 
f96e0b
     grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-load-size 4 -boot-info-table"
f96e0b
diff --git a/util/grub-mkstandalone.in b/util/grub-mkstandalone.in
f96e0b
index a5434c4..927075b 100644
f96e0b
--- a/util/grub-mkstandalone.in
f96e0b
+++ b/util/grub-mkstandalone.in
f96e0b
@@ -60,7 +60,7 @@ usage () {
f96e0b
     print_option_help "-O, --format=$(gettext "FORMAT")" "$(gettext "generate an image in FORMAT")"; echo
f96e0b
     print_option_help "" "$(gettext "available formats:") $formats"
f96e0b
     echo
f96e0b
-    print_option_help "-C, --compression=(xz|none|auto)" "$(gettext "choose the compression to use")"
f96e0b
+    print_option_help "-C, --compression=(xz|none|auto)" "$(gettext "choose the compression to use for core image")"
f96e0b
     print_option_help "--modules=$(gettext "MODULES")" "$(gettext "pre-load specified modules MODULES")"
f96e0b
     grub_print_install_files_help
f96e0b
     print_option_help  "--grub-mkimage=$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
f96e0b
@@ -170,7 +170,7 @@ memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
f96e0b
 
f96e0b
 (cd "${memdisk_dir}"; tar -cf - * $source) > "${memdisk_img}"
f96e0b
 rm -rf "${memdisk_dir}"
f96e0b
-"$grub_mkimage" -O "${format}" -C "$compression" -d "${source_directory}" -m "${memdisk_img}" -o "$output_image" --prefix='(memdisk)/boot/grub' memdisk tar $modules
f96e0b
+"$grub_mkimage" -O "${format}" -C "$compression" -d "${source_directory}" -m "${memdisk_img}" -o "$output_image" --prefix='(memdisk)/boot/grub' memdisk tar $grub_decompression_module $modules
f96e0b
 rm -rf "${memdisk_img}"
f96e0b
 
f96e0b
 exit 0
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b