diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2020-02-16 22:21:11 -0500 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2020-02-16 22:21:11 -0500 |
commit | 7395bc29e6d762619fb5a45f76c7cdf8d92d4689 (patch) | |
tree | a7b035a9e5bafd4907dabf6eda215ee804898d90 /make | |
parent | cf0b5d4433b6486c8f76be1a92a00ea5bd936190 (diff) | |
download | minitramfs-7395bc29e6d762619fb5a45f76c7cdf8d92d4689.tar.xz minitramfs-7395bc29e6d762619fb5a45f76c7cdf8d92d4689.zip |
update
Diffstat (limited to 'make')
-rwxr-xr-x | make | 98 |
1 files changed, 43 insertions, 55 deletions
@@ -2,65 +2,41 @@ set -e -scriptloc=${BASH_SOURCE:-$0} -scriptdir=${scriptloc%/*} +compressor="lz4 --best --favor-decSpeed -l" -gen_cpio_list() { - cat << EOF -dir /dev 0755 0 0 -dir /mnt 0755 0 0 -dir /proc 0755 0 0 -dir /run 0755 0 0 -dir /run/cryptsetup 0755 0 0 -dir /sys 0755 0 0 - -nod /dev/console 0600 0 0 c 5 1 - -slink /bin/sh busybox 0755 0 0 -slink /etc/mtab /proc/self/mounts 0755 0 0 - -slink /usr/lib64/libgcc_s.so libgcc_s.so.1 0755 0 0 -file /usr/lib64/libgcc_s.so.1 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc_s.so.1 0755 0 0 - -file /bin/busybox /bin/busybox 0755 0 0 -file /etc/passwd $scriptdir/passwd 0644 0 0 -file /etc/dropbear/dropbear_rsa_host_key $scriptdir/dropbear_rsa_host_key 0600 0 0 -file /etc/dropbear/dropbear_ecdsa_host_key $scriptdir/dropbear_ecdsa_host_key 0600 0 0 -file /init $scriptdir/init 0755 0 0 -file /lib/firmware/radeon/CAYMAN_mc.bin /lib/firmware/radeon/CAYMAN_mc.bin 0644 0 0 -file /lib/firmware/radeon/CAYMAN_me.bin /lib/firmware/radeon/CAYMAN_me.bin 0644 0 0 -file /lib/firmware/radeon/CAYMAN_pfp.bin /lib/firmware/radeon/CAYMAN_pfp.bin 0644 0 0 -file /lib/firmware/radeon/CAYMAN_rlc.bin /lib/firmware/radeon/CAYMAN_rlc.bin 0644 0 0 -file /lib/firmware/radeon/CAYMAN_smc.bin /lib/firmware/radeon/CAYMAN_smc.bin 0644 0 0 -file /lib/firmware/radeon/SUMO_uvd.bin /lib/firmware/radeon/SUMO_uvd.bin 0644 0 0 -file /lib/firmware/rtl_nic/rtl8168h-2.fw /lib/firmware/rtl_nic/rtl8168h-2.fw 0644 0 0 -file /lib64/libnss_files.so.2 /lib64/libnss_files.so.2 0755 0 0 -file /root/.ssh/authorized_keys $scriptdir/authorized_keys 0600 0 0 -file /unlock $scriptdir/unlock 0755 0 0 -EOF - for cmd in cryptsetup e2fsck dropbear; do - cmdp="$(command -v "$cmd")" - # builtin - if [ "$cmd" = "$cmdp" ]; then - continue - fi - ldd "$cmdp" | while read a b c d; do - if [ "$b" = '=>' ]; then - printf 'file /lib64/%s %s 0755 0 0\n' "${c##*/}" "$c" - else - # interpreter - case "$a" in - /*) printf 'file %s %s 0755 0 0\n' "$a" "$a" ;; - esac - fi - done - printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp" +# generate a cpio entry for a command +gen_cmd() { + cmd=$1 + cmdp="$(command -v "$cmd")" + # builtin + if [ "$cmd" = "$cmdp" ]; then + return + fi + printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp" + ldd "$cmdp" | grep / | while read line; do + tmp=${line% *} + lib=/${tmp#*/} + # don't bother with ld.so.conf + printf 'file /lib64/%s %s 0755 0 0\n' "${lib##*/}" "$lib" done } +# generate the main file list +gen_cpio_list() { + sed -e '/^#/d' cpio_list.txt + gen_cmd e2fsck + gen_cmd dropbear + export LD_PRELOAD=libgcc_s.so.1 + gen_cmd cryptsetup +} + +# filter the list and insert parent directory entries gen_dir_ents() { while read type target args; do + # re-print the original entry printf '%s %s %s\n' "$type" "$target" "$args" + # print the necessary directory entries. duplicates will be + # filtered by sort -u later while [ "${target%/*}" != '' ]; do target=${target%/*} printf 'dir %s 0755 0 0\n' "$target" @@ -68,18 +44,30 @@ gen_dir_ents() { done } +# filter the list and generate the make dependency file gen_depfile() { - deps='make' + deps='cpio_list.txt make' while read type target source args; do + # re-print the original entry printf '%s %s %s %s\n' "$type" "$target" "$source" "$args" + # accumulate the dependencies in a list to avoid make bugs. + # there will be no duplicates since the list was previously sorted if [ "$type" = file ]; then deps="$deps $source" + # avoid "No rule to make target" when deps disappear echo "$source:" >&3 fi done echo "initramfs.img: $deps" >&3 } -gen_cpio_list | gen_dir_ents | sort -u | gen_depfile 3>initramfs.d | "${scriptdir}"/gen_init_cpio -t 0 - | xz --x86 --lzma2=preset=9e --check=crc32 -c > initramfs.img +if ! [ -e cpio_list.txt ] || ! [ -e gen_init_cpio ]; then + cd "${0%/*}" +fi -# vim:ft=sh: +gen_cpio_list | \ +gen_dir_ents | \ +sort -u | \ +gen_depfile 3>initramfs.d | \ +./gen_init_cpio -t 0 - | \ +$compressor > initramfs.img |