]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
refactor(squash): move the post install scripts into the module-setup.sh
authorKairui Song <kasong@redhat.com>
Mon, 15 Feb 2021 14:22:08 +0000 (22:22 +0800)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Tue, 9 Mar 2021 13:40:35 +0000 (13:40 +0000)
No function change, just move the post install code to 99squash to clean
up dracut.sh.

dracut.sh
modules.d/99squash/init.sh
modules.d/99squash/module-setup.sh

index 1d54a7d90863dda78d809268261e4ff4215a330a..ca9907ae19ade7239ea1cc6c519e08ae6d776ff2 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -2020,49 +2020,11 @@ if [[ $hostonly_cmdline == "yes" ]] ; then
 fi
 
 if dracut_module_included "squash"; then
-    dinfo "*** Install squash loader ***"
     readonly squash_dir="$initdir/squash/root"
     readonly squash_img="$initdir/squash/root.img"
-    readonly squash_candidate=( "usr" "etc" )
-
-    # shellcheck disable=SC2174
-    mkdir -m 0755 -p "$squash_dir"
-    for folder in "${squash_candidate[@]}"; do
-        mv "$initdir/$folder" "$squash_dir/$folder"
-    done
-
-    # Move some files out side of the squash image, including:
-    # - Files required to boot and mount the squashfs image
-    # - Files need to be accessible without mounting the squash image
-    # - Initramfs marker
-    for file in \
-        "$squash_dir"/usr/lib/modules/*/modules.* \
-        "$squash_dir"/usr/lib/dracut/* \
-        "$squash_dir"/etc/initrd-release
-    do
-        [[ -f $file ]] || continue
-        DRACUT_RESOLVE_DEPS=1 dracutsysrootdir="$squash_dir" inst "${file#$squash_dir}"
-        rm "$file"
-    done
-
-    mv "$initdir"/init "$initdir"/init.stock
-    ln -s squash/init.sh "$initdir"/init
-
-    # Reinstall required files for the squash image setup script.
-    # We have moved them inside the squashed image, but they need to be
-    # accessible before mounting the image.
-    inst_multiple "echo" "sh" "mount" "modprobe" "mkdir"
-    hostonly="" instmods "loop" "squashfs" "overlay"
-    # Only keep systemctl outsite if we need switch root
-    if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
-      inst "systemctl"
-    fi
 
-    # Remove duplicated files
-    for folder in "${squash_candidate[@]}"; do
-        find "$initdir/$folder/" -not -type d \
-            -exec bash -c 'mv -f "$squash_dir${1#$initdir}" "$1"' -- "{}" \;
-    done
+    dinfo "*** Install squash loader ***"
+    DRACUT_SQUASH_POST_INST=1 module_install "squash"
 fi
 
 if [[ $kernel_only != yes ]]; then
index bca49db53e5a9038e6996754186be63df19909c1..d8b2cbba934a32cf51f21e9ad9a55f94df6e0d90 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 /squash/setup-squash.sh
 
-exec /init.stock
+exec /init.orig
 
 echo "Something went wrong when trying to start original init executable!"
 exit 1
index ecf95cc6b55ca607c40051ff35ffdcb5dec57a9a..18aaf429a62daf9390f7f86623c589c6a6955748 100644 (file)
@@ -22,11 +22,55 @@ installkernel() {
     hostonly="" instmods squashfs loop overlay
 }
 
-install() {
-    inst_multiple kmod modprobe mount mkdir ln echo
+installpost() {
+    local squash_candidate=( "usr" "etc" )
+
+    # shellcheck disable=SC2174
+    mkdir -m 0755 -p "$squash_dir"
+    for folder in "${squash_candidate[@]}"; do
+        mv "$initdir/$folder" "$squash_dir/$folder"
+    done
+
+    # Move some files out side of the squash image, including:
+    # - Files required to boot and mount the squashfs image
+    # - Files need to be accessible without mounting the squash image
+    # - Initramfs marker
+    for file in \
+        "$squash_dir"/usr/lib/modules/*/modules.* \
+        "$squash_dir"/usr/lib/dracut/* \
+        "$squash_dir"/etc/initrd-release
+    do
+        [[ -f $file ]] || continue
+        DRACUT_RESOLVE_DEPS=1 dracutsysrootdir="$squash_dir" inst "${file#$squash_dir}"
+        rm "$file"
+    done
+
+    # Install required files for the squash image setup script.
+    hostonly="" instmods "loop" "squashfs" "overlay"
+    inst_multiple modprobe mount mkdir ln echo
     inst "$moddir"/setup-squash.sh /squash/setup-squash.sh
     inst "$moddir"/clear-squash.sh /squash/clear-squash.sh
-    inst "$moddir"/init.sh /squash/init.sh
+
+    mv "$initdir"/init "$initdir"/init.orig
+    inst "$moddir"/init.sh "$initdir"/init
+
+    # Keep systemctl outsite if we need switch root
+    if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
+      inst "systemctl"
+    fi
+
+    # Remove duplicated files
+    for folder in "${squash_candidate[@]}"; do
+        find "$initdir/$folder/" -not -type d \
+            -exec bash -c 'mv -f "$squash_dir${1#$initdir}" "$1"' -- "{}" \;
+    done
+}
+
+install() {
+    if [[ $DRACUT_SQUASH_POST_INST ]]; then
+        installpost
+        return
+    fi
 
     inst "$moddir/squash-mnt-clear.service" "$systemdsystemunitdir/squash-mnt-clear.service"
     $SYSTEMCTL -q --root "$initdir" add-wants initrd-switch-root.target squash-mnt-clear.service