From 10a2bde198877d240a20d45a93cb523df13d35a0 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sun, 8 Apr 2012 20:27:08 +0200 Subject: [PATCH] Refactor code selecting best available initrd compression --- gen_initramfs.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index 066c389..082d525 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -715,17 +715,21 @@ create_initramfs() { xz|lzma|bzip2|gzip|lzop) compression=${COMPRESS_INITRD_TYPE} ;; lzo) compression=lzop ;; best) - if grep -sq '^CONFIG_RD_XZ=y' ${KERNEL_DIR}/.config && test -n "${cmd_xz}" ; then - compression=xz - elif grep -sq '^CONFIG_RD_LZMA=y' ${KERNEL_DIR}/.config && test -n "${cmd_lzma}" ; then - compression=lzma - elif grep -sq '^CONFIG_RD_BZIP2=y' ${KERNEL_DIR}/.config && test -n "${cmd_bzip2}" ; then - compression=bzip2 - elif grep -sq '^CONFIG_RD_GZIP=y' ${KERNEL_DIR}/.config && test -n "${cmd_gzip}" ; then - compression=gzip - elif grep -sq '^CONFIG_RD_LZO=y' ${KERNEL_DIR}/.config && test -n "${cmd_lzop}" ; then - compression=lzop - fi ;; + for tuple in \ + 'CONFIG_RD_XZ cmd_xz xz' \ + 'CONFIG_RD_LZMA cmd_lzma lzma' \ + 'CONFIG_RD_BZIP2 cmd_bzip2 bzip' \ + 'CONFIG_RD_GZIP cmd_gzip gzip' \ + 'CONFIG_RD_LZO cmd_lzop lzop'; do + set -- ${tuple} + kernel_option=$1 + cmd_variable_name=$2 + if grep -sq "^${kernel_option}=y" ${KERNEL_DIR}/.config && test -n "${!cmd_variable_name}" ; then + compression=$3 + break + fi + done + ;; *) gen_die "Compression '${COMPRESS_INITRD_TYPE}' unknown" ;; -- 2.26.2