huge rework

This commit is contained in:
illiliti 2020-02-25 13:51:20 +03:00
parent 347d0d2d01
commit 81f7aac01a
2 changed files with 114 additions and 104 deletions

View File

@ -66,7 +66,7 @@ setup_mdev() {
done
# load drivers
find /sys -name modalias -type f -exec sort -u "{}" "+" |
find /sys -name modalias -type f -exec sort -u {} + |
xargs modprobe -qba
}

118
tinyramfs
View File

@ -96,14 +96,20 @@ install_requirements() {
# install user specified binaries
[ "$binaries" ] &&
install_binary "$binaries"
for custom_binary in $binaries; do
install_binary "$custom_binary"
done
# install util-linux binaries
[ "$util_linux" = 1 ] &&
install_binary mount blkid
for util_linux_binary in mount blkid; do
install_binary "$util_linux_binary"
done
# install mandatory binaries
install_binary busybox modprobe
for main_binary in busybox modprobe; do
install_binary "$main_binary"
done
}
create_structure() {
@ -136,11 +142,13 @@ create_symlinks() {
}
install_devmgr() {
msg info "installing device manager"
case "$devmgr" in
udev)
msg info "installing udev"
install_binary udevd udevadm dmsetup
for udev_binary in udevd udevadm dmsetup; do
install_binary "$udev_binary"
done
find /usr/lib/udev \
! -path "*rc_keymaps*" \
@ -151,8 +159,6 @@ install_devmgr() {
msg panic "failed to install udev"
;;
mdev)
msg info "installing mdev"
install -m644 "${filesdir}/mdev.conf" \
"${workdir}/etc/mdev.conf"
@ -160,9 +166,9 @@ install_devmgr() {
"${workdir}/lib/mdev/storage-device"
;;
mdevd)
msg info "installing mdevd"
install_binary mdevd mdevd-coldplug
for mdevd_binary in mdevd mdevd-coldplug; do
install_binary "$mdevd_binary"
done
install -m644 "${filesdir}/mdev.conf" \
"${workdir}/etc/mdev.conf"
@ -181,9 +187,10 @@ install_lvm() {
install_binary lvm
lvm_drivers="dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror"
[ "$hostonly" = 1 ] &&
install_driver "$lvm_drivers"
for lvm_driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
install_driver "$lvm_driver"
done
# install lvm config
if [ "$lvm_conf" = 1 ]; then
@ -211,20 +218,18 @@ install_luks() {
install_binary cryptsetup
luks_drivers="aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent"
[ "$hostonly" = 1 ] &&
install_driver "$luks_drivers"
for luks_driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
install_driver "$luks_driver"
done
# avoid "locking directory missing" warning
# message and libgcc_s.so.1 missing error
# see https://bugs.archlinux.org/task/56771
mkdir -p "${workdir}/run/cryptsetup"
[ -e /usr/lib/libgcc_s.so.1 ] && {
install -s -m755 /usr/lib/libgcc_s.so.1 \
"${workdir}/usr/lib/libgcc_s.so.1" ||
msg panic "failed to install LUKS libraries"
}
[ -e /usr/lib/libgcc_s.so.1 ] &&
install_library /usr/lib/libgcc_s.so.1
# copy luks header
[ -f "$luks_header" ] && {
@ -249,11 +254,7 @@ install_driver() {
# check monolithic kernel(builtin drivers)
[ -d "${moddir}/${kernel}" ] || return
# we need splitting
# shellcheck disable=SC2068
for driver in $@; do
# strip path and extension if any
driver="$1"
driver="${driver##*/}"
driver="${driver%%.*}"
@ -262,10 +263,13 @@ install_driver() {
grep -v "builtin\|net" |
cut -d " " -f 2 |
while read -r driver_dep; do
install -Dm644 "$driver_dep" \
"${workdir}${driver_dep}"
done
while read -r full_driver; do
# check if driver already installed
[ -e "${workdir}${full_driver}" ] &&
continue
install -Dm644 "$full_driver" \
"${workdir}${full_driver}"
done
}
@ -276,7 +280,11 @@ install_hostonly_drivers() {
msg panic "hostonly mode required root_type option to be configured"
# perform autodetection of drivers via /sys
install_driver "$(find /sys -name modalias -exec sort -u "{}" "+")"
find /sys -name modalias -exec sort -u {} + |
while read -r alias_driver; do
install_driver "$alias_driver"
done
# TODO autodetect root fs driver
# TODO separate root type option
@ -285,7 +293,9 @@ install_hostonly_drivers() {
# install user specified drivers
[ "$drivers" ] &&
install_driver "$drivers"
for custom_driver in $drivers; do
install_driver "$custom_driver"
done
}
install_all_drivers() {
@ -293,8 +303,7 @@ install_all_drivers() {
modker="${moddir}/${kernel}/kernel"
install_driver \
"$(find \
find \
"${modker}/arch" \
"${modker}/crypto" \
"${modker}/fs" \
@ -306,7 +315,11 @@ install_all_drivers() {
"${modker}/drivers/usb/storage" \
"${modker}/drivers/usb/host" \
"${modker}/drivers/virtio" \
-type f 2> /dev/null)"
-type f 2> /dev/null |
while read -r path_driver; do
install_driver "$path_driver"
done
}
generate_depmod() {
@ -324,47 +337,45 @@ generate_depmod() {
install_binary() {
# TODO make strip optional
workdirbin="${workdir}/usr/bin/"
# we need splitting
# shellcheck disable=SC2068
for binary in $@; do
msg info "installing binary $binary"
binary="$1"
fullbin=$(command -v "$binary")
workdirbin="${workdir}/usr/bin/"
# check if binary exists
[ "$fullbin" ] ||
msg panic "$binary doesn't exists"
# check if binary already installed
[ -e "${workdirbin}${fullbin##*/}" ] &&
return
# install and strip binary
install -s -m755 "$fullbin" \
"${workdirbin}${fullbin##*/}"
# check static
ldd "$fullbin" > /dev/null 2>&1 ||
continue
return
# install libraries
install_library "$binary"
# exract paths to libraries
ldd $(command -v "$binary") |
sed -nr \
-e 's,.* (/.*lib.*/.*.so.*) .*,\1,p' \
-e 's,.*(/lib.*/ld.*.so.*) .*,\1,p' |
while read -r library; do
install_library "$library"
done
}
install_library() {
# TODO make strip optional
workdirlib="${workdir}/usr/lib/"
# extract paths to libraries from ldd output
ldd $(command -v "$1") |
sed -nr \
-e 's,.* (/.*lib.*/.*.so.*) .*,\1,p' \
-e 's,.*(/lib.*/ld.*.so.*) .*,\1,p' |
while read -r library; do
library="$1"
namelib="${library##*/}"
reallib=$(readlink "$library")
fulllib=$(readlink -f "$library")
workdirlib="${workdir}/usr/lib/"
# check symlink
if [ -h "$library" ]; then
@ -391,7 +402,6 @@ install_library() {
install -s -m755 "$library" \
"${workdirlib}${namelib}"
fi
done
}
install_files() {