summaryrefslogtreecommitdiff
path: root/make
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-21 23:10:07 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-21 23:35:14 -0400
commit7739d1863cb6ea5de819e1ae1c1ee10e8109d32b (patch)
treea9eeabbf583cc19ee1539bed51e08075d226132e /make
parent542cfed39c3b3b93e5bab3f7c45d741b71e7c3d7 (diff)
downloadminitramfs-7739d1863cb6ea5de819e1ae1c1ee10e8109d32b.tar.xz
minitramfs-7739d1863cb6ea5de819e1ae1c1ee10e8109d32b.zip
POSIXify, add docs, other changes
Diffstat (limited to 'make')
-rwxr-xr-xmake33
1 files changed, 25 insertions, 8 deletions
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