From 7739d1863cb6ea5de819e1ae1c1ee10e8109d32b Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Tue, 21 Apr 2020 23:10:07 -0400 Subject: POSIXify, add docs, other changes --- make | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'make') diff --git a/make b/make index 9f35483..1abf52b 100755 --- a/make +++ b/make @@ -1,17 +1,27 @@ #!/bin/sh -set -e +[ -n "$compressor" ] || compressor="lz4 --best --favor-decSpeed -l" +#[ -n "$compressor" ] || compressor="xz -c --check=crc32 --x86 --lzma2=preset=9e" -compressor="lz4 --best --favor-decSpeed -l" +# for comp_bench +[ -n "$outfile" ] || outfile=initramfs.img + +toppid=$$ +die() { + fmt=$1 + shift + printf "error building initramfs: $fmt\n" "$@" >&2 + kill "$toppid" + trap '' EXIT + exit 1 +} # generate a cpio entry for a command gen_cmd() { cmd=$1 - cmdp="$(command -v "$cmd")" - # builtin - if [ "$cmd" = "$cmdp" ]; then - return - fi + cmdp="$(command -v "$cmd")" || die 'command not found: %s' "$cmd" + # ignore builtins + [ "$cmd" != "$cmdp" ] || return printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp" ldd "$cmdp" | grep / | while read line; do tmp=${line% *} @@ -26,8 +36,11 @@ gen_cpio_list() { sed -e '/^#/d' cpio_list.txt gen_cmd e2fsck gen_cmd dropbear + # cryptsetup argon2 uses pthread_cancel, glibc dlopens libgcc_s.so.1 + # ldd will find the correct libgcc_s.so.1 based on ld.so.conf export LD_PRELOAD=libgcc_s.so.1 gen_cmd cryptsetup + # LD_PRELOAD unset at end of subshell } # filter the list and insert parent directory entries @@ -65,9 +78,13 @@ if ! [ -e cpio_list.txt ] || ! [ -e gen_init_cpio ]; then cd "${0%/*}" fi +trap 'test -L initramfs.img || test -f initramfs.img && rm -f initramfs.img; exit 1' HUP INT QUIT TERM EXIT + gen_cpio_list | \ gen_dir_ents | \ sort -u | \ gen_depfile 3>initramfs.d | \ ./gen_init_cpio -t 0 - | \ -$compressor > initramfs.img +$compressor > $outfile + +trap '' EXIT -- cgit v1.2.3-54-g00ecf