121 lines
3.7 KiB
Bash
121 lines
3.7 KiB
Bash
#!/usr/bin/env false
|
|
|
|
is_function() {
|
|
type "$1" 2>/dev/null | head -n 1 | grep 'function' > /dev/null
|
|
}
|
|
|
|
setup_repo_yum() {
|
|
mkdir -p "${ROOTFS_DIR}/etc/yum.repos.d"
|
|
cp "${RECEIPE_DIR}"/repos.d/* "${ROOTFS_DIR}/etc/yum.repos.d" 2>/dev/null || true
|
|
}
|
|
|
|
setup_repo() {
|
|
logi "Preconfiguring package repo..."
|
|
setup_repo_func="setup_repo_${PACKAGE_MANAGER}"
|
|
if ! is_function "${setup_repo_func}" ; then
|
|
loge "Package manager ${PACKAGE_MANAGER} not supported yet."
|
|
exit 1
|
|
fi
|
|
"setup_repo_${PACKAGE_MANAGER}"
|
|
}
|
|
|
|
execute_script_dir() {
|
|
script_dir="$1"
|
|
|
|
find "${script_dir}" -maxdepth 1 -mindepth 1 -type d,l | sort | \
|
|
while IFS= read -r line; do
|
|
logi "Executing scripts: ${line}"
|
|
bash -c "
|
|
cd ${line} &&
|
|
${2}
|
|
${line}/entry.sh"
|
|
done
|
|
}
|
|
|
|
install_package_cleanup_yum() {
|
|
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" clean all
|
|
}
|
|
|
|
install_package_cleanup() {
|
|
logi "Cleanup package installation"
|
|
install_package_cleanup_func="install_package_cleanup_${PACKAGE_MANAGER}"
|
|
if ! is_function "${install_package_cleanup_func}" ; then
|
|
loge "Package manager ${PACKAGE_MANAGER} not supported yet."
|
|
exit 1
|
|
fi
|
|
"install_package_cleanup_${PACKAGE_MANAGER}"
|
|
}
|
|
|
|
install_package_list_yum() {
|
|
# shellcheck shell=dash disable=SC2086
|
|
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y install $1
|
|
}
|
|
|
|
install_package_list() {
|
|
logi "Installing package list: $1"
|
|
install_package_list_func="install_package_list_${PACKAGE_MANAGER}"
|
|
if ! is_function "${install_package_list_func}" ; then
|
|
loge "Package manager ${PACKAGE_MANAGER} not supported yet."
|
|
exit 1
|
|
fi
|
|
"install_package_list_${PACKAGE_MANAGER}" "$(tr '\n' ' ' < "$1")"
|
|
}
|
|
|
|
install_package_group_yum() {
|
|
# shellcheck shell=dash disable=SC2086
|
|
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y groupinstall $1
|
|
}
|
|
|
|
install_package_group() {
|
|
logi "Installing package group: $1"
|
|
install_package_group_func="install_package_group_${PACKAGE_MANAGER}"
|
|
if ! is_function "${install_package_group_func}" ; then
|
|
loge "Package manager ${PACKAGE_MANAGER} not supported yet."
|
|
exit 1
|
|
fi
|
|
"install_package_group_${PACKAGE_MANAGER}" "$(tr '\n' ' ' < "$1")"
|
|
}
|
|
|
|
install_packages() {
|
|
if [ -d "${RECEIPE_DIR}/packages.d/" ]; then
|
|
logi "Install packages..."
|
|
else
|
|
logw "packages.d missing"
|
|
return
|
|
fi
|
|
|
|
find "${RECEIPE_DIR}"/packages.d/ -maxdepth 1 -mindepth 1 -type f,d,l | sort | \
|
|
while IFS= read -r line; do
|
|
actualpath="$(readlink -f "${line}")"
|
|
if [ -d "${actualpath}" ]; then
|
|
if [ -f "${line}/packages.list" ]; then
|
|
install_package_list "${line}/packages.list"
|
|
elif [ -f "${line}/packages.group" ]; then
|
|
install_package_group "${line}/packages.group"
|
|
else
|
|
logw "No package list, ignoring ${line}"
|
|
continue
|
|
fi
|
|
if [ -d "${line}/post.d" ]; then
|
|
execute_script_dir "${line}/post.d" "${1}"
|
|
fi
|
|
elif [ -f "${actualpath}" ]; then
|
|
if echo "${line}" | grep ".*.list" > /dev/null; then
|
|
install_package_list "${line}"
|
|
elif echo "${line}" | grep ".*.group" > /dev/null; then
|
|
install_package_group "${line}"
|
|
else
|
|
logw "Unsupported package list, ignoring ${line}"
|
|
fi
|
|
fi
|
|
done
|
|
install_package_cleanup
|
|
}
|
|
|
|
post_scripts() {
|
|
if [ -d "$(readlink -f "${RECEIPE_DIR}/post.d")" ]; then
|
|
logi "Post configuring..."
|
|
execute_script_dir "${RECEIPE_DIR}/post.d" "${1}"
|
|
fi
|
|
}
|