9f65cc
From 0a2f7b1779ddcac1c4e79aa58212c7ee528ac6e1 Mon Sep 17 00:00:00 2001
9f65cc
From: Kairui Song <kasong@redhat.com>
9f65cc
Date: Mon, 15 Feb 2021 23:15:26 +0800
9f65cc
Subject: [PATCH] feat: squash module follow --compress option
9f65cc
9f65cc
Try to make mksquashfs follow --compress option if squash module is
9f65cc
included, if not specified or invalid, fall back to use mksquashfs's
9f65cc
default compressor.
9f65cc
9f65cc
(cherry picked from commit 5d05ffbd87bc27e27f517ebc3454d50729c687e6)
9f65cc
9f65cc
Cherry-picked from: 5d05ffbd
9f65cc
Resolves: #1959336
9f65cc
---
9f65cc
 dracut.sh | 17 ++++++++++++++---
9f65cc
 1 file changed, 14 insertions(+), 3 deletions(-)
9f65cc
9f65cc
diff --git a/dracut.sh b/dracut.sh
9f65cc
index b403f401..d9a66c5a 100755
9f65cc
--- a/dracut.sh
9f65cc
+++ b/dracut.sh
9f65cc
@@ -1781,14 +1781,25 @@ fi
9f65cc
 
9f65cc
 if dracut_module_included "squash"; then
9f65cc
     dinfo "*** Squashing the files inside the initramfs ***"
9f65cc
-    mksquashfs $squash_dir $squash_img -no-xattrs -no-exports -noappend -always-use-fragments -comp xz -Xdict-size 100% -no-progress 1> /dev/null
9f65cc
+    declare squash_compress_arg
9f65cc
+    # shellcheck disable=SC2086
9f65cc
+    if [[ $compress ]]; then
9f65cc
+        if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $compress &>/dev/null; then
9f65cc
+            dwarn "mksquashfs doesn't support compressor '$compress', failing back to default compressor."
9f65cc
+        else
9f65cc
+            squash_compress_arg="$compress"
9f65cc
+        fi
9f65cc
+    fi
9f65cc
 
9f65cc
-    if [[ $? != 0 ]]; then
9f65cc
+    # shellcheck disable=SC2086
9f65cc
+    if ! mksquashfs "$squash_dir" "$squash_img" \
9f65cc
+        -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
9f65cc
+        -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev/null; then
9f65cc
         dfatal "dracut: Failed making squash image"
9f65cc
         exit 1
9f65cc
     fi
9f65cc
 
9f65cc
-    rm -rf $squash_dir
9f65cc
+    rm -rf "$squash_dir"
9f65cc
     dinfo "*** Squashing the files inside the initramfs done ***"
9f65cc
 fi
9f65cc
 
9f65cc