improvements

This commit is contained in:
illiliti 2020-01-12 00:12:24 +03:00
parent 6ea379fd89
commit 70d48c2687

View File

@ -50,27 +50,52 @@ done
# TODO rewrite drivers installing | handle $drivers config var # TODO rewrite drivers installing | handle $drivers config var
# install drivers # install drivers
find "$moddir/$kernel/kernel/drivers/virtio" "$moddir/$kernel/kernel/arch" "$moddir/$kernel/kernel/crypto" "$moddir/$kernel/kernel/fs" "$moddir/$kernel/kernel/lib" "$moddir/$kernel/kernel/drivers/block" "$moddir/$kernel/kernel/drivers/ata" "$moddir/$kernel/kernel/drivers/md" "$moddir/$kernel/kernel/drivers/scsi" "$moddir/$kernel/kernel/drivers/usb/storage" "$moddir/$kernel/kernel/drivers/usb/host" -type f -exec cp --parents "{}" "$tmpdir" ";" find \
"$moddir/$kernel/kernel/drivers/virtio" \
"$moddir/$kernel/kernel/arch" \
"$moddir/$kernel/kernel/crypto" \
"$moddir/$kernel/kernel/fs" \
"$moddir/$kernel/kernel/lib" \
"$moddir/$kernel/kernel/drivers/block" \
"$moddir/$kernel/kernel/drivers/ata" \
"$moddir/$kernel/kernel/drivers/md" \
"$moddir/$kernel/kernel/drivers/scsi" \
"$moddir/$kernel/kernel/drivers/usb/storage" \
"$moddir/$kernel/kernel/drivers/usb/host" \
-type f | cpio -pd "$tmpdir" 2>/dev/null
# install list of drivers
cp "$moddir/$kernel/modules.softdep" "$moddir/$kernel/modules.builtin" "$moddir/$kernel/modules.order" "$tmpdir/$moddir/$kernel" cp "$moddir/$kernel/modules.softdep" "$moddir/$kernel/modules.builtin" "$moddir/$kernel/modules.order" "$tmpdir/$moddir/$kernel"
# create modules.* files # generate dependencies list of drivers
depmod -b "$tmpdir" "$kernel" depmod -b "$tmpdir" "$kernel"
# install binaries # install and strip binaries and libraries
for b in $(echo $binaries); do for b in $(echo $binaries); do
cp "$(which $b)" "$tmpdir/usr/bin/$b" && chmod +x "$tmpdir/usr/bin/$b" cp "$(command -v $b)" "$tmpdir/usr/bin"
# check statically linking chmod +x "$tmpdir/usr/bin/$b"
ldd "$(which $b)" >/dev/null || continue strip -s "$tmpdir/usr/bin/$b"
# handle .so symlinks for dymanically linked binaries # check statically linking
for l in $(ldd "$(which $b)" | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p' -e 's,.*(/lib.*/ld.*.so.*) .*,\1,p'); do ldd "$(command -v $b)" >/dev/null || continue
# handle libraries symlinks for dymanically linked binaries
for l in $(ldd "$(command -v $b)" | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p' -e 's,.*(/lib.*/ld.*.so.*) .*,\1,p'); do
# check symlink
if [ -h "$l" ]; then if [ -h "$l" ]; then
# check file exists
if [ ! -e "$tmpdir/usr/lib/${l##*/}" ] && [ ! -e "$tmpdir/usr/lib/$(readlink $l)" ]; then
# regular # regular
cp -n --parents "$(readlink -f $l)" "$tmpdir" cp "$(readlink -f $l)" "$tmpdir/usr/lib"
strip -s "$tmpdir/usr/lib/$(readlink $l)"
# symlink # symlink
cp -n -a --parents "$l" "$tmpdir" cp -a "$l" "$tmpdir/usr/lib"
fi
else else
cp -n --parents "$(readlink -f $l)" "$tmpdir" if [ ! -e "$tmpdir/usr/lib/$(readlink $l)" ]; then
cp "$(readlink -f $l)" "$tmpdir/usr/lib"
strip -s "$tmpdir/usr/lib/$(readlink $l)"
fi
fi fi
done done
done done
@ -79,10 +104,6 @@ done
cp ./init "$tmpdir/init" && chmod +x "$tmpdir/init" cp ./init "$tmpdir/init" && chmod +x "$tmpdir/init"
cp ./busybox "$tmpdir/usr/bin/busybox" && chmod +x "$tmpdir/usr/bin/busybox" cp ./busybox "$tmpdir/usr/bin/busybox" && chmod +x "$tmpdir/usr/bin/busybox"
# strip binaries and libraries
# uncomment this if your initramfs are huge
find "$tmpdir" -type f -executable -exec strip -s "{}" ";"
# initialize config # initialize config
cat <<EOF > "$tmpdir/config" cat <<EOF > "$tmpdir/config"
root="$root" root="$root"
@ -98,7 +119,7 @@ drivers="$drivers"
EOF EOF
# packing # packing
if ! ( cd "$tmpdir" && find . | cpio --create --verbose --format=newc | gzip --best ) > "./initramfs-$kernel.img.gz"; then if ! ( cd "$tmpdir" && find . | cpio --create --verbose --format=newc | gzip --best ) > "./initramfs-$kernel.img.gz" 2>/dev/null; then
echo "failed" echo "failed"
exit 1 exit 1
fi fi