refactor install_all_drivers

This commit is contained in:
illiliti 2020-02-12 04:18:02 +03:00
parent b0ae8ec446
commit 56b2550e48

View File

@ -227,6 +227,9 @@ install_luks() {
# install drivers and deps # install drivers and deps
install_drivers() { install_drivers() {
printf "%s\n" "$@" | while read -r driver; do printf "%s\n" "$@" | while read -r driver; do
# strip path and extension
driver="${driver##*/}"
driver="${driver%%.*}"
for driver_dep in $(modprobe -D "$driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do for driver_dep in $(modprobe -D "$driver" 2> /dev/null | grep -v builtin | cut -d " " -f 2); do
install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}" install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}"
done done
@ -242,7 +245,7 @@ install_hostonly_drivers() {
[ -n "$root_type" ] || msg panic "hostonly mode required root_type option to be configured" [ -n "$root_type" ] || msg panic "hostonly mode required root_type option to be configured"
# perform autodetection of drivers via /sys # perform autodetection of drivers via /sys
install_drivers $(find /sys/devices -name modalias -exec sort -u "{}" "+") install_drivers $(find /sys -name modalias -exec sort -u "{}" "+")
# TODO autodetect root fs driver # TODO autodetect root fs driver
# TODO separate root type option # TODO separate root type option
@ -255,24 +258,28 @@ install_hostonly_drivers() {
# find and install all drivers # find and install all drivers
install_all_drivers() { install_all_drivers() {
# TODO use install_drivers function instead of cpio
msg info "installing all drivers" msg info "installing all drivers"
find \ modker="${moddir}/${kernel}/kernel"
"${modker}/kernel/arch" \
"${modker}/kernel/crypto" \ install_drivers \
"${modker}/kernel/fs" \ $(find \
"${modker}/kernel/lib" \ "${modker}/arch" \
"${modker}/kernel/drivers/block" \ "${modker}/crypto" \
"${modker}/kernel/drivers/ata" \ "${modker}/fs" \
"${modker}/kernel/drivers/md" \ "${modker}/lib" \
"${modker}/kernel/drivers/scsi" \ "${modker}/drivers/block" \
"${modker}/kernel/drivers/usb/storage" \ "${modker}/drivers/ata" \
"${modker}/kernel/drivers/usb/host" \ "${modker}/drivers/md" \
"${modker}/kernel/drivers/virtio" \ "${modker}/drivers/scsi" \
-type f | cpio -pd "$tmpdir" > /dev/null 2>&1 "${modker}/drivers/usb/storage" \
"${modker}/drivers/usb/host" \
"${modker}/drivers/virtio" \
-type f 2> /dev/null)
# TODO implement monolithic kernel support # TODO implement monolithic kernel support
[ -e "${tmpdir}/lib/modules" ] || msg panic "failed to install drivers" [ -e "${tmpdir}/lib/modules" ] || msg panic "failed to install drivers"
modker="${moddir}/${kernel}"
} }
# generate "modules" files # generate "modules" files
@ -415,7 +422,6 @@ check_currentdir
tmpdir="$(create_tmpdir)" || msg panic "failed to create working directory" tmpdir="$(create_tmpdir)" || msg panic "failed to create working directory"
kernel="${kernel:-$(uname -r)}" kernel="${kernel:-$(uname -r)}"
moddir="/lib/modules" moddir="/lib/modules"
modker="${moddir}/${kernel}"
check_requirements check_requirements
create_structure create_structure