All checks were successful
Aimee OS/aimee-os/pipeline/head This commit looks good
This is needed in case we need to poll for the block device containing the root filesystem.
115 lines
2.9 KiB
Bash
Executable File
115 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ $(id -u) != 0 ]; then
|
|
exec "${HOST_DIR}"/bin/fakeroot "$0" "$@"
|
|
fi
|
|
|
|
export PATH="${HOST_DIR}:${PATH}"
|
|
|
|
TARGET_DIR=$1
|
|
WORKDIR=$(mktemp -d)
|
|
OUTDIR="${WORKDIR}"/initramfs
|
|
LIB_CACHE="${WORKDIR}"/libs.cache
|
|
PKGDIR="${0%/*}"
|
|
|
|
trap 'rm -rf "${WORKDIR}"' INT QUIT TERM EXIT
|
|
|
|
cache_libs() {
|
|
find \
|
|
"${TARGET_DIR}"/usr/lib \
|
|
"${TARGET_DIR}"/usr/lib64 \
|
|
\( -type f -o -type l \) \
|
|
-name '*.so*' \
|
|
| sed "s@${TARGET_DIR}@@" \
|
|
> "${LIB_CACHE}"
|
|
}
|
|
|
|
bin_install() {
|
|
for arg; do
|
|
arg=${arg#/}
|
|
[ -e "${OUTDIR}/${arg}" ] && continue
|
|
mkdir -p "${OUTDIR}/${arg%/*}"
|
|
cp -a "${TARGET_DIR}/${arg}" "${OUTDIR}/${arg}"
|
|
if [ -h "${TARGET_DIR}/${arg}" ]; then
|
|
bin_install "$(realpath --relative-to "${TARGET_DIR}" "${TARGET_DIR}/${arg}")"
|
|
elif [ -f "${TARGET_DIR}/${arg}" ]; then
|
|
readelf --dynamic "${TARGET_DIR}/${arg}" \
|
|
| awk '$2=="(NEEDED)"{gsub(/\[|\]/,"",$5); print $5}' \
|
|
| while IFS= read -r lib; do
|
|
path="$(grep "${lib}"'$' "${LIB_CACHE}")"
|
|
if [ -z "${path}" ]; then
|
|
printf 'ERROR could not resolve shared library %s\n' "${lib}" >&2
|
|
return 1
|
|
fi
|
|
bin_install "${path}"
|
|
done
|
|
elif [ ! -e "${TARGET_DIR}/${arg}" ]; then
|
|
printf 'ERROR could not find /%s to copy\n' "${arg}" >&2
|
|
return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
mk_skel() {
|
|
mkdir -p "${OUTDIR}"/dev
|
|
mknod -m 0622 "${OUTDIR}"/dev/console c 5 1
|
|
|
|
mkdir -p \
|
|
"${OUTDIR}"/usr \
|
|
"${OUTDIR}"/usr/bin \
|
|
"${OUTDIR}"/usr/sbin \
|
|
"${OUTDIR}"/usr/lib
|
|
ln -s usr/bin "${OUTDIR}"/bin
|
|
ln -s usr/sbin "${OUTDIR}"/sbin
|
|
ln -s usr/lib "${OUTDIR}"/lib
|
|
if [ -h "${TARGET_DIR}"/usr/lib64 ]; then
|
|
cp -P "${TARGET_DIR}"/usr/lib64 "${OUTDIR}"/usr
|
|
fi
|
|
if [ -h "${TARGET_DIR}"/lib64 ]; then
|
|
cp -P "${TARGET_DIR}"/lib64 "${OUTDIR}"
|
|
fi
|
|
}
|
|
|
|
rm -rf "${OUTDIR}"
|
|
|
|
mk_skel || exit
|
|
cache_libs || exit
|
|
|
|
bin_install \
|
|
/bin/cat \
|
|
/bin/cp \
|
|
/bin/ls \
|
|
/bin/mkdir \
|
|
/bin/mount \
|
|
/bin/rm \
|
|
/bin/sh \
|
|
/bin/sleep \
|
|
/bin/sort \
|
|
/bin/tail \
|
|
/bin/umount \
|
|
/usr/bin/btrfs \
|
|
/usr/bin/mkfs.btrfs \
|
|
/usr/bin/mountpoint \
|
|
/usr/bin/readlink \
|
|
/usr/sbin/blkid \
|
|
/usr/sbin/findfs \
|
|
/usr/sbin/partx \
|
|
/usr/sbin/sfdisk \
|
|
/usr/sbin/switch_root \
|
|
|| exit
|
|
|
|
if [ -e "${TARGET_DIR}"/usr/bin/setfiles ]; then
|
|
bin_install /usr/bin/setfiles || exit
|
|
fi
|
|
|
|
install "${PKGDIR}"/initramfs/initramfs-init.sh "${OUTDIR}"/init || exit
|
|
install "${PKGDIR}"/initramfs/init-storage.sh "${OUTDIR}"/usr/bin/init-storage || exit
|
|
|
|
mkdir -p "${TARGET_DIR}"/boot
|
|
|
|
(cd "${OUTDIR}" && find . -mindepth 1 \
|
|
| LC_ALL=C sort \
|
|
| cpio --reproducible --quiet -o -H newc \
|
|
| zstd \
|
|
) > "${TARGET_DIR}"/boot/initramfs.img.zst
|