Files
2025-09-05 15:40:18 +08:00

97 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env sh
# shellcheck shell=dash disable=SC2317
# Unreachable Detection is disabled as the script relies on indirect call.
set -o errexit
set -o nounset
. ./logging.sh
RECEIPE_DIR=""
ROOTFS_DIR=""
PACKAGE_MANAGER=""
. ./receipe_helper.sh
generate_rootfs() {
SCRIPT_ENV_SETUP_CMD="
export ROOTFS_DIR=${ROOTFS_DIR} &&
"
setup_repo
install_packages "${SCRIPT_ENV_SETUP_CMD}"
post_scripts "${SCRIPT_ENV_SETUP_CMD}"
}
print_usage() {
# Keep help message within 80 cols for special consoles.
cat << EOF
Usage: $0 [-hp] [-i input [-i input [...]]] output
-h Print this help message.
-i receipe Path to directory containing the receipe
to make the rootfs.
-o rootfs Path to directory that the rootfs will
be bootstrapped into.
-p package_manager
Specify which package manager should be
used.
Environment Variables:
LOG_LEVEL Controls the log level of this script.
One of: DEBUG, INFO, WARN, ERROR
Defaults to: INFO
EOF
}
main() {
# Handling args
while getopts "i:o:p:h" o; do
case "${o}" in
h)
print_usage
exit 0
;;
i)
RECEIPE_DIR=${OPTARG}
;;
o)
ROOTFS_DIR=${OPTARG}
;;
p)
PACKAGE_MANAGER=${OPTARG}
;;
*)
exit 1
;;
esac
done
shift $((OPTIND-1))
logi "RootFS Builder"
# Validate inputs
if [ -z "${RECEIPE_DIR}" ]; then
loge "No receipe is specified!"
exit 1
fi
if [ -z "${ROOTFS_DIR}" ]; then
loge "No output dir is specified!"
exit 1
fi
if [ -z "${PACKAGE_MANAGER}" ]; then
loge "No package manager is specified!"
exit 1
fi
logi "Using receipe: ${RECEIPE_DIR}"
logi "- ROOTFS_DIR: ${ROOTFS_DIR}"
logi "- PACKAGE_MANAGER: ${PACKAGE_MANAGER}"
generate_rootfs
logi "RootFS generated at: ${ROOTFS_DIR}"
exit 0
}
main "$@"