diff --git a/main/postmarketos-mkinitfs/APKBUILD b/main/postmarketos-mkinitfs/APKBUILD index 84937ef0d..525df7b6d 100644 --- a/main/postmarketos-mkinitfs/APKBUILD +++ b/main/postmarketos-mkinitfs/APKBUILD @@ -1,5 +1,5 @@ pkgname=postmarketos-mkinitfs -pkgver=0.5.1 +pkgver=0.5.2 pkgrel=0 pkgdesc="Tool to generate initramfs images for postmarketOS" url="https://github.com/postmarketOS" @@ -23,4 +23,4 @@ package() { } sha512sums="e1849a13ee696e76dc6c734eda984bcc6a6e2e3d8a62a4df0778a8e338dc0bf9d967fa263ae6e57c14a0cb516c6004c6e251262a1711ad47f1ce4c622727a1d7 init.sh.in d6eb7c1cd5ddf110996db1523db68a9cf13b980f25dc60a7bfc79d7c911558f46487708299bd84499ef04f61e129ab0b8186e4b1761c1479c6fec0f92232e001 init_functions.sh -3948f1f49a6d9b9817dbc4ac14f2609b10e9bd6f819b6556477d400bae0226dc64cb2702ca7afd75c10aa8917fe82622b39cbf5df94412df9bcd97d84687e245 mkinitfs.sh" +1048ebb20e2534c9ac3c259443b89323e09f87a68eab9f1c8b8c42130bf9fe2ea99cdca32be0595c65e827007c4171be047441156dd03e1d81c0554f947828f8 mkinitfs.sh" diff --git a/main/postmarketos-mkinitfs/mkinitfs.sh b/main/postmarketos-mkinitfs/mkinitfs.sh index a6c80a2c6..769b75c19 100644 --- a/main/postmarketos-mkinitfs/mkinitfs.sh +++ b/main/postmarketos-mkinitfs/mkinitfs.sh @@ -84,9 +84,22 @@ get_modules() } # Get the paths to all binaries and their dependencies +BINARIES="/bin/busybox /bin/busybox-extras /usr/sbin/telnetd /sbin/kpartx" +BINARIES_EXTRA=" + /sbin/cryptsetup + /sbin/dmsetup + /usr/sbin/parted + /sbin/e2fsck + /usr/sbin/resize2fs + /usr/bin/osk-sdl + /usr/lib/libGL.so.1 + /usr/lib/ts/* + /usr/lib/libts* + $(find /usr/lib/directfb-* -name '*.so') + /lib/libz.so.1 +" get_binaries() { - BINARIES="/bin/busybox /bin/busybox-extras /usr/sbin/telnetd /sbin/kpartx" if [ "${deviceinfo_msm_refresher}" == "true" ]; then BINARIES="${BINARIES} /usr/sbin/msm-fb-refresher" fi @@ -113,19 +126,6 @@ get_osk_config() get_binaries_extra() { - BINARIES_EXTRA=" - /sbin/cryptsetup - /sbin/dmsetup - /usr/sbin/parted - /sbin/e2fsck - /usr/sbin/resize2fs - /usr/bin/osk-sdl - /usr/lib/libGL.so.1 - /usr/lib/ts/* - /usr/lib/libts* - $(find /usr/lib/directfb-* -name '*.so') - /lib/libz.so.1 - " tmp1=$(mktemp /tmp/mkinitfs.XXXXXX) get_binaries > "$tmp1" tmp2=$(mktemp /tmp/mkinitfs.XXXXXX) @@ -287,6 +287,44 @@ append_device_tree() cat $kernel $dtb > "${kernel}-dtb" } +# Create the initramfs-extra archive +# $1: outfile +generate_initramfs_extra() +{ + echo "==> initramfs: creating $1" + + osk_conf="$(get_osk_config)" + if [ $? -eq 1 ]; then + echo "ERROR: Font specified in /etc/osk.conf does not exist!" + exit 1 + fi + + # Ensure cache folder exists + mkinitfs_cache_dir="/var/cache/postmarketos-mkinitfs" + mkdir -p "$mkinitfs_cache_dir" + + # Generate cache output filename (initfs_extra_cache) by hashing all input files + initfs_extra_files=$(echo "$BINARIES_EXTRA$osk_conf" | xargs -0 -I{} sh -c 'ls $1 2>/dev/null' -- {} | sort -u) + initfs_extra_files_hashes="$(md5sum $initfs_extra_files)" + initfs_extra_hash="$(echo "$initfs_extra_files_hashes" | md5sum | awk '{ print $1 }')" + initfs_extra_cache="$mkinitfs_cache_dir/$(basename $1)_${initfs_extra_hash}" + + if ! [ -e "$initfs_extra_cache" ]; then + # If a cached file is missing, clear the whole cache and create it + rm -f ${mkinitfs_cache_dir}/* + + # Set up initramfs-extra in temp folder + tmpdir_extra=$(mktemp -d /tmp/mkinitfs.XXXXXX) + mkdir -p "$tmpdir_extra" + copy_files "$(get_binaries_extra)" "$tmpdir_extra" + copy_files "$osk_conf" "$tmpdir_extra" + create_cpio_image "$tmpdir_extra" "$initfs_extra_cache" + rm -rf "$tmpdir_extra" + fi + + cp "$initfs_extra_cache" "$1" +} + # initialize source_deviceinfo parse_commandline "$1" "$2" "$3" @@ -322,23 +360,6 @@ create_bootimg rm -rf "$tmpdir" -# initialize initramfs-extra -echo "==> initramfs: creating $outfile_extra" -tmpdir_extra=$(mktemp -d /tmp/mkinitfs.XXXXXX) - -# set up initfs-extra in temp folder -mkdir -p "$tmpdir_extra" -copy_files "$(get_binaries_extra)" "$tmpdir_extra" -osk_conf="$(get_osk_config)" -if [ $? -eq 1 ]; then - echo "ERROR: Font specified in /etc/osk.conf does not exist!" - exit 1 -fi -copy_files "$osk_conf" "$tmpdir_extra" - -# finish up -create_cpio_image "$tmpdir_extra" "$outfile_extra" - -rm -rf "$tmpdir_extra" +generate_initramfs_extra "$outfile_extra" exit 0