forked from OERV-BSP/image-builder
138 lines
3.2 KiB
Bash
Executable File
138 lines
3.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_ARCHIVE=""
|
|
PACKAGE_MANAGER=""
|
|
OUTPUT_PREFIX=""
|
|
|
|
ROOTFS_DIR=""
|
|
|
|
. ./receipe_helper.sh
|
|
. ./fs_helper/vfat.sh
|
|
. ./fs_helper/ext4.sh
|
|
. ./partition_table_helper/guid.sh
|
|
. ./image_layout_helper.sh
|
|
. ./image_creation_helper.sh
|
|
|
|
parse_image_layout() {
|
|
logi "Parsing image layout"
|
|
|
|
# Introduce subshell for isolated env vars
|
|
image_layout_info="$(parse_image_layout_impl)"
|
|
logdraw "${image_layout_info}"
|
|
}
|
|
|
|
create_image() {
|
|
logi "Creating image"
|
|
(eval "${image_layout_info}" && create_image_impl)
|
|
}
|
|
|
|
generate_bsp() {
|
|
# Pre-process image layout for subsequent post-install scripts
|
|
parse_image_layout
|
|
|
|
# Prepare pre-built rootfs
|
|
ROOTFS_DIR="$(mktemp -d)"
|
|
logi "Extracting pre-built rootfs to ${ROOTFS_DIR}"
|
|
logcmd tar -xvf "${ROOTFS_ARCHIVE}" -C "${ROOTFS_DIR}"
|
|
|
|
setup_repo
|
|
|
|
SCRIPT_ENV_SETUP_CMD="
|
|
export ROOTFS_DIR=${ROOTFS_DIR} &&
|
|
$(echo "${image_layout_info}" | sed -E 's/^(.+)$/export \1 \&\& /')
|
|
export get_fs_uuid_by_mountpoint='${get_fs_uuid_by_mountpoint}' &&
|
|
"
|
|
install_packages "${SCRIPT_ENV_SETUP_CMD}"
|
|
post_scripts "${SCRIPT_ENV_SETUP_CMD}"
|
|
create_image
|
|
|
|
# Clean up
|
|
rm -rf "${ROOTFS_DIR}"
|
|
}
|
|
|
|
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.
|
|
-s rootfs Path to pre-built rootfs archive
|
|
-i receipe Path to BSP receipe directory
|
|
-p package_manager
|
|
Specify which package manager should be
|
|
used.
|
|
-o output Prefix for generated files
|
|
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:s:h" o; do
|
|
case "${o}" in
|
|
h)
|
|
print_usage
|
|
exit 0
|
|
;;
|
|
i)
|
|
RECEIPE_DIR=${OPTARG}
|
|
;;
|
|
s)
|
|
ROOTFS_ARCHIVE=${OPTARG}
|
|
;;
|
|
p)
|
|
PACKAGE_MANAGER=${OPTARG}
|
|
;;
|
|
o)
|
|
OUTPUT_PREFIX=${OPTARG}
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
logi "BSP Builder"
|
|
|
|
# Validate inputs
|
|
if [ -z "${RECEIPE_DIR}" ]; then
|
|
loge "No receipe is specified!"
|
|
exit 1
|
|
fi
|
|
if [ -z "${ROOTFS_ARCHIVE}" ]; then
|
|
loge "No output dir is specified!"
|
|
exit 1
|
|
fi
|
|
if [ -z "${OUTPUT_PREFIX}" ]; 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_ARCHIVE: ${ROOTFS_ARCHIVE}"
|
|
logi "- PACKAGE_MANAGER: ${PACKAGE_MANAGER}"
|
|
logi "- OUTPUT_PREFIX: ${OUTPUT_PREFIX}"
|
|
|
|
generate_bsp
|
|
|
|
exit 0
|
|
}
|
|
|
|
main "$@"
|