89 lines
2.0 KiB
Bash
89 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
echo_blue() {
|
|
echo -e "\033[34m$1\033[0m"
|
|
}
|
|
|
|
echo_yellow() {
|
|
echo -e "\033[0;33m$1\033[0m"
|
|
}
|
|
|
|
echo_red() {
|
|
echo -e "\033[0;31m$1\033[0m"
|
|
}
|
|
|
|
# Installs a library. Expects absolute path.
|
|
install_dep() {
|
|
local lib="$1"
|
|
[[ -f "$lib" ]] || {
|
|
echo "Did not find library at path: $lib"
|
|
exit 1
|
|
}
|
|
|
|
[[ -f "${ROOT}${lib}" ]] || {
|
|
mkdir -p $(dirname "${ROOT}${lib}")
|
|
echo_blue "Adding dependency to root: $lib"
|
|
cp "$lib" "${ROOT}${lib}"
|
|
}
|
|
}
|
|
|
|
# Expects to receive the absolute path as the full argument.
|
|
# Use `which binary_name` if it's in your path.
|
|
# Installs to /usr/bin
|
|
install_binary() {
|
|
local binary="$1" lib=''
|
|
[[ -f "$binary" ]] || {
|
|
echo_red "Did not find binary at path: $binary"
|
|
exit 1
|
|
}
|
|
|
|
echo_blue "Adding binary to root: $binary"
|
|
cp "$binary" "${ROOT}/usr/bin/"
|
|
|
|
ldd_deps="$(ldd "$binary")"
|
|
if [[ $ldd_deps == *"not a dynamic executable"* ]]; then
|
|
return 0
|
|
fi
|
|
|
|
while read -r lib; do
|
|
install_dep "$lib"
|
|
done <<< "$( echo "$ldd_deps" | grep -F ' => ' | awk '{ print $3 }' )"
|
|
}
|
|
|
|
install_busybox() {
|
|
echo_blue "Installing busybox..."
|
|
[[ -f "$BUSYBOX_PATH" ]] || {
|
|
echo_red "Did not find busybox at $BUSYBOX_PATH"
|
|
echo_red "Please compile or download busybox. You can also change the path."
|
|
exit 1
|
|
}
|
|
install_binary "$BUSYBOX_PATH" || return 1
|
|
for applet in $(/usr/lib/initcpio/busybox --list); do
|
|
ln -s busybox "${ROOT}/usr/bin/$applet"
|
|
done
|
|
}
|
|
|
|
install_init_script() {
|
|
cp ../init.sh ${ROOT}/init
|
|
cp ../init_functions.sh ${ROOT}/
|
|
}
|
|
|
|
create_archive() {
|
|
echo_blue "Creating archive..."
|
|
find . | cpio -o -H newc | gzip > detee-$(hostnamectl hostname)-${KERNEL}.cpio.gz
|
|
}
|
|
|
|
install_module() {
|
|
local module="$1" depends='' dep='' filename=''
|
|
|
|
filename="$( modinfo -k $KERNEL $module | grep '^filename:' | awk '{ print $2 }' )"
|
|
install_dep "$filename"
|
|
|
|
depends="$(modinfo -k $KERNEL $module |
|
|
grep '^depends:' | awk '{ print $2 }' | sed 's/,/\n/g')"
|
|
while read -r dep; do
|
|
[[ -z $dep ]] && continue
|
|
install_module "$dep"
|
|
done <<< "$( echo "$depends" )"
|
|
}
|