]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/99squash/module-setup.sh
refactor(squash): move all setup code to init-squash.sh
[thirdparty/dracut.git] / modules.d / 99squash / module-setup.sh
1 #!/bin/bash
2
3 check() {
4 require_binaries mksquashfs unsquashfs || return 1
5
6 for i in CONFIG_SQUASHFS CONFIG_BLK_DEV_LOOP CONFIG_OVERLAY_FS ; do
7 if ! check_kernel_config $i; then
8 dinfo "dracut-squash module requires kernel configuration $i (y or m)"
9 return 1
10 fi
11 done
12
13 return 255
14 }
15
16 depends() {
17 echo "systemd-initrd"
18 return 0
19 }
20
21 installkernel() {
22 hostonly="" instmods squashfs loop overlay
23 }
24
25 installpost() {
26 local squash_candidate=( "usr" "etc" )
27
28 # shellcheck disable=SC2174
29 mkdir -m 0755 -p "$squash_dir"
30 for folder in "${squash_candidate[@]}"; do
31 mv "$initdir/$folder" "$squash_dir/$folder"
32 done
33
34 # Move some files out side of the squash image, including:
35 # - Files required to boot and mount the squashfs image
36 # - Files need to be accessible without mounting the squash image
37 # - Initramfs marker
38 for file in \
39 "$squash_dir"/usr/lib/modules/*/modules.* \
40 "$squash_dir"/usr/lib/dracut/* \
41 "$squash_dir"/etc/initrd-release
42 do
43 [[ -f $file ]] || continue
44 DRACUT_RESOLVE_DEPS=1 dracutsysrootdir="$squash_dir" inst "${file#$squash_dir}"
45 rm "$file"
46 done
47
48 # Install required files for the squash image setup script.
49 hostonly="" instmods "loop" "squashfs" "overlay"
50 inst_multiple modprobe mount mkdir ln echo
51
52 mv "$initdir"/init "$initdir"/init.orig
53 inst "$moddir"/init-squash.sh /init
54 inst "$moddir"/clear-squash.sh /squash/clear-squash.sh
55
56 # Keep systemctl outsite if we need switch root
57 if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
58 inst "systemctl"
59 fi
60
61 # Remove duplicated files
62 for folder in "${squash_candidate[@]}"; do
63 find "$initdir/$folder/" -not -type d \
64 -exec bash -c 'mv -f "$squash_dir${1#$initdir}" "$1"' -- "{}" \;
65 done
66 }
67
68 install() {
69 if [[ $DRACUT_SQUASH_POST_INST ]]; then
70 installpost
71 return
72 fi
73
74 inst "$moddir/squash-mnt-clear.service" "$systemdsystemunitdir/squash-mnt-clear.service"
75 $SYSTEMCTL -q --root "$initdir" add-wants initrd-switch-root.target squash-mnt-clear.service
76 }