2020-09-28 09:02:11 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# kas - setup tool for bitbake based projects
|
|
|
|
#
|
2022-01-27 12:03:03 +01:00
|
|
|
# Copyright (c) Siemens AG, 2018-2022
|
2020-09-28 09:02:11 +02:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Jan Kiszka <jan.kiszka@siemens.com>
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
2022-12-11 08:30:29 +01:00
|
|
|
printf "%b" "Usage: $0 [OPTIONS] { build | shell } [KASOPTIONS] [KASFILE]\n"
|
|
|
|
printf "%b" " $0 [OPTIONS] { checkout | dump } [KASOPTIONS] [KASFILE]\n"
|
2021-07-12 08:47:34 +02:00
|
|
|
printf "%b" " $0 [OPTIONS] for-all-repos [KASOPTIONS] [KASFILE] COMMAND\n"
|
2022-01-08 08:51:33 +01:00
|
|
|
printf "%b" " $0 [OPTIONS] { clean | cleansstate | cleanall}\n"
|
2021-07-18 16:39:06 +02:00
|
|
|
printf "%b" " $0 [OPTIONS] menu [KCONFIG]\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "\nPositional arguments:\n"
|
|
|
|
printf "%b" "build\t\t\tCheck out repositories and build target.\n"
|
2021-06-29 13:45:40 +02:00
|
|
|
printf "%b" "checkout\t\tCheck out repositories but do not build.\n"
|
2022-12-11 08:30:29 +01:00
|
|
|
printf "%b" "dump\t\t\tCheck out repositories and write flat version\n"
|
|
|
|
printf "%b" " \t\t\tof config to stdout.\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "shell\t\t\tRun a shell in the build environment.\n"
|
2021-06-29 13:45:40 +02:00
|
|
|
printf "%b" "for-all-repos\t\tRun specified command in each repository.\n"
|
2022-01-08 08:51:33 +01:00
|
|
|
printf "%b" "clean\t\t\tClean build artifacts, keep sstate cache and " \
|
|
|
|
"downloads.\n"
|
2022-03-30 10:02:40 +02:00
|
|
|
printf "%b" "cleansstate\t\tClean build artifacts and sstate cache, " \
|
2022-01-08 08:51:33 +01:00
|
|
|
"keep downloads.\n"
|
|
|
|
printf "%b" "cleanall\t\tClean build artifacts, sstate cache and " \
|
|
|
|
"downloads.\n"
|
2021-07-18 16:39:06 +02:00
|
|
|
printf "%b" "menu\t\t\tProvide configuration menu and trigger " \
|
|
|
|
"configured build.\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "\nOptional arguments:\n"
|
|
|
|
printf "%b" "--isar\t\t\tUse kas-isar container to build Isar image.\n"
|
|
|
|
printf "%b" "--with-loop-dev Pass a loop device to the " \
|
|
|
|
"container. Only required if\n"
|
|
|
|
printf "%b" "\t\t\tloop-mounting is used by recipes.\n"
|
2020-09-28 09:02:13 +02:00
|
|
|
printf "%b" "--runtime-args\t\tAdditional arguments to pass to the " \
|
2020-10-02 08:10:44 +02:00
|
|
|
"container runtime\n"
|
|
|
|
printf "%b" "\t\t\tfor running the build.\n"
|
2023-05-03 16:53:38 +02:00
|
|
|
printf "%b" "-d\t\t\tPrint debug output (deprecated, use -l debug).\n"
|
|
|
|
printf "%b" "-l, --log-level\t\tSet log level (default=info).\n"
|
2020-10-22 08:35:08 +02:00
|
|
|
printf "%b" "-v\t\t\tSame as -d (deprecated).\n"
|
2021-02-25 20:42:27 +01:00
|
|
|
printf "%b" "--version\t\tprint program version.\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "--ssh-dir\t\tDirectory containing SSH configurations.\n"
|
|
|
|
printf "%b" "\t\t\tAvoid \$HOME/.ssh unless you fully trust the " \
|
|
|
|
"container.\n"
|
2022-03-25 10:40:18 +01:00
|
|
|
printf "%b" "--ssh-agent\t\tForward ssh-agent socket to the container.\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "--aws-dir\t\tDirectory containing AWScli configuration.\n"
|
2021-05-06 11:31:13 +02:00
|
|
|
printf "%b" "--git-credential-store\tFile path to the git credential " \
|
|
|
|
"store\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "--no-proxy-from-env\tDo not inherit proxy settings from " \
|
|
|
|
"environment.\n"
|
2021-04-15 12:57:26 +02:00
|
|
|
printf "%b" "--repo-ro\t\tMount current repository read-only\n" \
|
|
|
|
"\t\t\t(default for build command)\n"
|
|
|
|
printf "%b" "--repo-rw\t\tMount current repository writeable\n" \
|
|
|
|
"\t\t\t(default for shell command)\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
printf "%b" "\n"
|
|
|
|
printf "%b" "You can force the use of podman over docker using " \
|
2020-09-28 09:02:13 +02:00
|
|
|
"KAS_CONTAINER_ENGINE=podman.\n"
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trace()
|
|
|
|
{
|
2022-11-22 04:49:02 +01:00
|
|
|
[ -n "${KAS_VERBOSE}" ] && echo "+ $*" >&2
|
2020-09-28 09:02:11 +02:00
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
2020-11-15 09:57:51 +01:00
|
|
|
enable_isar_mode() {
|
2022-01-27 12:03:03 +01:00
|
|
|
if [ -n "${ISAR_MODE}" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
ISAR_MODE=1
|
|
|
|
|
2020-11-15 09:57:51 +01:00
|
|
|
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas-isar"
|
|
|
|
KAS_ISAR_ARGS="--privileged"
|
|
|
|
|
2021-02-16 10:36:14 +01:00
|
|
|
if [ "${KAS_CONTAINER_ENGINE}" = "podman" ]; then
|
2020-11-15 09:57:51 +01:00
|
|
|
# sudo is needed for a privileged podman container
|
2022-02-02 21:10:29 +01:00
|
|
|
KAS_CONTAINER_COMMAND="sudo --preserve-env ${KAS_CONTAINER_COMMAND}"
|
2023-02-12 13:42:42 +01:00
|
|
|
# preserved user PATH may lack sbin needed by privileged podman
|
|
|
|
export PATH="${PATH}:/usr/sbin"
|
2021-02-16 10:36:14 +01:00
|
|
|
fi
|
2020-11-15 09:57:51 +01:00
|
|
|
}
|
|
|
|
|
2022-06-08 14:44:17 +02:00
|
|
|
enable_oe_mode() {
|
|
|
|
if [ "${KAS_CONTAINER_ENGINE}" = "podman" ]; then
|
|
|
|
# The container entry point expects that the current userid
|
|
|
|
# calling "podman run" has a 1:1 mapping
|
|
|
|
KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} --userns=keep-id"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-08 08:55:31 +01:00
|
|
|
run_clean() {
|
|
|
|
if [ -n "${KAS_ISAR_ARGS}" ]; then
|
|
|
|
set_container_image_var
|
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
|
|
|
trace ${KAS_CONTAINER_COMMAND} run -v "${KAS_BUILD_DIR}":/build:rw \
|
|
|
|
--workdir=/build --rm ${KAS_ISAR_ARGS} \
|
|
|
|
${KAS_CONTAINER_IMAGE} \
|
|
|
|
sudo rm -rf tmp
|
|
|
|
else
|
2023-06-18 21:39:45 +02:00
|
|
|
trace rm -rf "${KAS_BUILD_DIR}"/tmp*
|
2022-01-08 08:55:31 +01:00
|
|
|
fi
|
2022-01-08 08:51:33 +01:00
|
|
|
|
|
|
|
if [ "$1" != "clean" ]; then
|
|
|
|
SSTATE_DIR=${SSTATE_DIR:-${KAS_BUILD_DIR}/sstate-cache}
|
|
|
|
trace rm -rf "${SSTATE_DIR}"
|
|
|
|
|
|
|
|
if [ "$1" = "cleanall" ]; then
|
|
|
|
DL_DIR=${DL_DIR:-${KAS_BUILD_DIR}/downloads}
|
|
|
|
trace rm -rf "${DL_DIR}"
|
|
|
|
fi
|
|
|
|
fi
|
2022-01-08 08:55:31 +01:00
|
|
|
}
|
|
|
|
|
2023-06-20 21:26:48 +02:00
|
|
|
KAS_IMAGE_VERSION_DEFAULT="3.3"
|
2020-09-28 09:02:15 +02:00
|
|
|
KAS_CONTAINER_IMAGE_PATH_DEFAULT="ghcr.io/siemens/kas"
|
|
|
|
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas"
|
2020-09-28 09:02:11 +02:00
|
|
|
|
2020-09-28 09:02:15 +02:00
|
|
|
set_container_image_var() {
|
|
|
|
KAS_IMAGE_VERSION="${KAS_IMAGE_VERSION:-${KAS_IMAGE_VERSION_DEFAULT}}"
|
|
|
|
KAS_CONTAINER_IMAGE_NAME="${KAS_CONTAINER_IMAGE_NAME:-${KAS_CONTAINER_IMAGE_NAME_DEFAULT}}"
|
|
|
|
KAS_CONTAINER_IMAGE_PATH="${KAS_CONTAINER_IMAGE_PATH:-${KAS_CONTAINER_IMAGE_PATH_DEFAULT}}"
|
2021-04-16 14:09:02 +02:00
|
|
|
KAS_CONTAINER_IMAGE_DEFAULT="${KAS_CONTAINER_IMAGE_PATH}/${KAS_CONTAINER_IMAGE_NAME}:${KAS_IMAGE_VERSION}"
|
|
|
|
KAS_CONTAINER_IMAGE="${KAS_CONTAINER_IMAGE:-${KAS_CONTAINER_IMAGE_DEFAULT}}"
|
2020-09-28 09:02:15 +02:00
|
|
|
}
|
2020-09-28 09:02:11 +02:00
|
|
|
|
2023-03-09 22:35:14 +01:00
|
|
|
KAS_WORK_DIR=$(readlink -fv "${KAS_WORK_DIR:-$(pwd)}")
|
2021-11-05 16:09:23 +01:00
|
|
|
# KAS_WORK_DIR needs to exist for the subsequent code
|
|
|
|
trace mkdir -p "${KAS_WORK_DIR}"
|
2023-03-09 22:35:14 +01:00
|
|
|
KAS_BUILD_DIR=$(readlink -fv "${KAS_BUILD_DIR:-${KAS_WORK_DIR}/build}")
|
2021-11-05 16:09:23 +01:00
|
|
|
trace mkdir -p "${KAS_BUILD_DIR}"
|
2021-03-09 21:40:50 +01:00
|
|
|
|
2020-09-28 09:02:13 +02:00
|
|
|
KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
|
|
|
|
if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
|
|
|
|
# Try to auto-detect a container engine
|
2020-09-28 09:02:11 +02:00
|
|
|
if command -v docker >/dev/null; then
|
2023-01-09 12:57:40 +01:00
|
|
|
case $(docker -v 2>/dev/null) in
|
|
|
|
podman*)
|
|
|
|
# The docker command is an alias for podman
|
|
|
|
KAS_CONTAINER_ENGINE=podman
|
|
|
|
;;
|
|
|
|
Docker*)
|
|
|
|
# The docker command is the real docker
|
|
|
|
KAS_CONTAINER_ENGINE=docker
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# The docker command is an unknown engine
|
|
|
|
echo "$0: docker command found, but unknown engine detected" >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
2020-09-28 09:02:11 +02:00
|
|
|
elif command -v podman >/dev/null; then
|
2020-09-28 09:02:13 +02:00
|
|
|
KAS_CONTAINER_ENGINE=podman
|
2020-09-28 09:02:11 +02:00
|
|
|
else
|
2020-09-28 09:02:13 +02:00
|
|
|
echo "$0: no container engine found, need docker or podman" >&2
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-02-05 21:02:07 +01:00
|
|
|
KAS_RUNTIME_ARGS="--log-driver=none --user=root"
|
2022-09-19 15:53:17 +02:00
|
|
|
|
2020-09-28 09:02:13 +02:00
|
|
|
case "${KAS_CONTAINER_ENGINE}" in
|
2020-09-28 09:02:11 +02:00
|
|
|
docker)
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_CONTAINER_COMMAND="docker"
|
2020-09-28 09:02:11 +02:00
|
|
|
;;
|
|
|
|
podman)
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_CONTAINER_COMMAND="podman"
|
2022-09-19 15:53:17 +02:00
|
|
|
KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} --security-opt label=disable"
|
2020-09-28 09:02:11 +02:00
|
|
|
;;
|
|
|
|
*)
|
2020-09-28 09:02:13 +02:00
|
|
|
echo "$0: unknown container engine '${KAS_CONTAINER_ENGINE}'" >&2
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-09-28 09:02:13 +02:00
|
|
|
# parse kas-container options
|
2020-09-28 09:02:11 +02:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--isar)
|
2020-11-15 09:57:51 +01:00
|
|
|
enable_isar_mode
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
--with-loop-dev)
|
2020-09-28 09:02:14 +02:00
|
|
|
if ! KAS_LOOP_DEV=$(/sbin/losetup -f 2>/dev/null); then
|
2020-09-28 09:02:11 +02:00
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
echo "Error: loop device not available!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sudo_command="/sbin/losetup -f"
|
|
|
|
sudo_message="[sudo] enter password to setup loop"
|
|
|
|
sudo_message="$sudo_message devices by calling"
|
2020-09-29 08:36:07 +02:00
|
|
|
sudo_message="$sudo_message '$sudo_command': "
|
2021-01-29 14:19:02 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2020-09-28 09:02:14 +02:00
|
|
|
if ! KAS_LOOP_DEV=$(sudo -p "$sudo_message" $sudo_command \
|
2020-09-28 09:02:11 +02:00
|
|
|
2>/dev/null); then
|
|
|
|
echo "Error: loop device setup unsuccessful!"
|
|
|
|
echo "try calling '$sudo_command' with root" \
|
|
|
|
"permissions manually."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_WITH_LOOP_DEV="--device ${KAS_LOOP_DEV}"
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
2020-09-28 09:02:13 +02:00
|
|
|
--runtime-args|--docker-args)
|
2020-09-28 09:02:11 +02:00
|
|
|
[ $# -gt 0 ] || usage
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} $2"
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--ssh-dir)
|
|
|
|
[ $# -gt 2 ] || usage
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_SSH_DIR="$2"
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
2022-03-25 10:40:18 +01:00
|
|
|
--ssh-agent)
|
2023-03-09 22:35:14 +01:00
|
|
|
KAS_SSH_AUTH_SOCK=$(readlink -fv "$SSH_AUTH_SOCK")
|
2022-03-25 10:40:18 +01:00
|
|
|
shift 1
|
|
|
|
;;
|
2020-09-28 09:02:11 +02:00
|
|
|
--aws-dir)
|
|
|
|
[ $# -gt 2 ] || usage
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_AWS_DIR="$2"
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
2021-05-06 11:31:13 +02:00
|
|
|
--git-credential-store)
|
|
|
|
[ $# -gt 2 ] || usage
|
|
|
|
KAS_GIT_CREDENTIAL_STORE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2020-09-28 09:02:11 +02:00
|
|
|
--no-proxy-from-env)
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_NO_PROXY_FROM_ENV=1
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
2021-07-18 15:10:18 +02:00
|
|
|
--repo-ro)
|
|
|
|
KAS_REPO_MOUNT_OPT="ro"
|
2021-04-15 12:57:26 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
2021-07-18 15:10:18 +02:00
|
|
|
--repo-rw)
|
|
|
|
KAS_REPO_MOUNT_OPT="rw"
|
2021-04-15 12:57:26 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
2020-10-22 08:35:08 +02:00
|
|
|
-v | -d)
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_VERBOSE=1
|
2020-10-22 08:35:09 +02:00
|
|
|
KAS_OPTIONS_DIRECT="${KAS_OPTIONS_DIRECT} -d"
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 1
|
|
|
|
;;
|
2023-05-03 16:53:38 +02:00
|
|
|
-l | --log-level)
|
|
|
|
if [ "$2" = "debug" ]; then
|
|
|
|
KAS_VERBOSE=1
|
|
|
|
fi
|
|
|
|
KAS_OPTIONS_DIRECT="${KAS_OPTIONS_DIRECT} -l $2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-02-25 20:42:27 +01:00
|
|
|
--version)
|
|
|
|
echo "$(basename "$0") $KAS_IMAGE_VERSION_DEFAULT"
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-09-28 09:02:11 +02:00
|
|
|
--*)
|
|
|
|
usage
|
|
|
|
;;
|
2022-01-08 08:51:33 +01:00
|
|
|
clean|cleansstate|cleanall)
|
2020-09-28 09:02:11 +02:00
|
|
|
[ $# -eq 1 ] || usage
|
2022-01-08 08:55:31 +01:00
|
|
|
run_clean "$1"
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
2021-04-15 12:57:26 +02:00
|
|
|
shell)
|
|
|
|
KAS_REPO_MOUNT_OPT_DEFAULT="rw"
|
|
|
|
KAS_CMD=$1
|
|
|
|
shift 1
|
|
|
|
break
|
|
|
|
;;
|
2023-05-03 06:05:56 +02:00
|
|
|
build|checkout|for-all-repos|menu)
|
2021-04-15 12:57:26 +02:00
|
|
|
KAS_REPO_MOUNT_OPT_DEFAULT="ro"
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_CMD=$1
|
2020-09-28 09:02:11 +02:00
|
|
|
shift 1
|
|
|
|
break
|
|
|
|
;;
|
2023-05-03 06:05:56 +02:00
|
|
|
dump)
|
|
|
|
if printf '%s\0' "$@" | grep -xqz -- '--inplace\|-i'; then
|
|
|
|
KAS_REPO_MOUNT_OPT_DEFAULT="rw"
|
|
|
|
else
|
|
|
|
KAS_REPO_MOUNT_OPT_DEFAULT="ro"
|
|
|
|
fi
|
|
|
|
KAS_CMD=$1
|
|
|
|
shift 1
|
|
|
|
break
|
|
|
|
;;
|
2020-09-28 09:02:11 +02:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-09-28 09:02:14 +02:00
|
|
|
[ -n "${KAS_CMD}" ] || usage
|
2020-09-28 09:02:11 +02:00
|
|
|
|
|
|
|
KAS_EXTRA_BITBAKE_ARGS=0
|
|
|
|
|
2021-07-18 16:39:06 +02:00
|
|
|
# parse kas sub-command options
|
2020-09-28 09:02:11 +02:00
|
|
|
while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do
|
|
|
|
case "$1" in
|
2021-01-29 12:12:17 +01:00
|
|
|
--skip|--target|--task)
|
2020-09-28 09:02:11 +02:00
|
|
|
KAS_OPTIONS="${KAS_OPTIONS} $1 $2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-01-29 12:12:17 +01:00
|
|
|
-c|--cmd|--command)
|
|
|
|
KAS_BITBAKE_C_OPTION_ARGS="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2022-02-23 02:02:01 +01:00
|
|
|
-E|--preserve-env)
|
|
|
|
echo "$1 is not supported with kas-container"
|
|
|
|
exit 1
|
|
|
|
;;
|
2020-09-28 09:02:11 +02:00
|
|
|
--)
|
|
|
|
KAS_EXTRA_BITBAKE_ARGS=$#
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
KAS_OPTIONS="${KAS_OPTIONS} $1"
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
KAS_FILES=
|
2021-01-29 14:19:02 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2020-09-28 09:02:11 +02:00
|
|
|
for FILE in $(IFS=':'; echo $1); do
|
2020-09-28 09:02:14 +02:00
|
|
|
if ! KAS_REAL_FILE="$(realpath -qe "$FILE")"; then
|
2020-09-28 09:02:11 +02:00
|
|
|
echo "Error: configuration file '${FILE}' not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "${KAS_FILES}" ]; then
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_FIRST_FILE="${KAS_REAL_FILE}"
|
|
|
|
KAS_FILES="${KAS_REAL_FILE}"
|
2020-09-28 09:02:11 +02:00
|
|
|
else
|
2020-09-28 09:02:14 +02:00
|
|
|
KAS_FILES="${KAS_FILES}:${KAS_REAL_FILE}"
|
2020-09-28 09:02:11 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
shift 1
|
2021-05-20 15:57:22 +02:00
|
|
|
if [ "$KAS_CMD" = "for-all-repos" ]; then
|
|
|
|
KAS_REPO_CMD="$1"
|
|
|
|
shift 1
|
|
|
|
fi
|
2020-09-28 09:02:11 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-07-12 08:47:34 +02:00
|
|
|
if [ -n "${KAS_FIRST_FILE}" ]; then
|
|
|
|
KAS_FILE_DIR="$(dirname "${KAS_FIRST_FILE}")"
|
|
|
|
KAS_REPO_DIR=$(git -C "${KAS_FILE_DIR}" rev-parse --show-toplevel 2>/dev/null) \
|
|
|
|
|| KAS_REPO_DIR=$(hg --cwd "${KAS_FILE_DIR}" root 2>/dev/null) \
|
|
|
|
|| KAS_REPO_DIR=${KAS_FILE_DIR}
|
|
|
|
else
|
|
|
|
KAS_REPO_DIR=$(pwd)
|
|
|
|
fi
|
2020-09-28 09:02:11 +02:00
|
|
|
|
2023-05-26 06:39:43 +02:00
|
|
|
SOURCE_DIR_HOST=$(
|
|
|
|
grep -e "^_source_dir_host: " "${KAS_WORK_DIR}/.config.yaml" 2>/dev/null | \
|
|
|
|
sed 's/_source_dir_host:[ ]\+//')
|
|
|
|
if [ -n "${SOURCE_DIR_HOST}" ]; then
|
|
|
|
KAS_REPO_DIR="${SOURCE_DIR_HOST}"
|
|
|
|
fi
|
|
|
|
|
2021-07-18 16:39:06 +02:00
|
|
|
if [ "${KAS_CMD}" = "menu" ]; then
|
|
|
|
if [ -z "${KAS_FIRST_FILE}" ]; then
|
|
|
|
KAS_FIRST_FILE="Kconfig"
|
|
|
|
fi
|
|
|
|
|
2023-05-26 06:39:43 +02:00
|
|
|
# When using the menu plugin, we need to track the KAS_REPO_DIR outside
|
|
|
|
# of the container to later allow a simple `kas-container build`. For
|
|
|
|
# that, we tell the kas menu plugin via an env-var about the location
|
|
|
|
# on the host. This data is then added to the .config.yaml where it can
|
|
|
|
# be evaluated by the next invocation of kas-container.
|
|
|
|
|
|
|
|
if ! [ "$(realpath -qe "${KAS_REPO_DIR}")" = "$(realpath -qe "${KAS_WORK_DIR}")" ]; then
|
|
|
|
set -- "$@" -e _KAS_REPO_DIR_HOST="$(readlink -fv "${KAS_REPO_DIR}")"
|
|
|
|
fi
|
|
|
|
|
2021-07-18 16:39:06 +02:00
|
|
|
BUILD_SYSTEM=$(tr '\n' '\f' 2>/dev/null < ${KAS_FIRST_FILE} | \
|
|
|
|
sed -e 's/\(.*\fconfig KAS_BUILD_SYSTEM\f\(.*\)\|.*\)/\2/' \
|
|
|
|
-e 's/\f\([[:alpha:]].*\|$\)//' \
|
|
|
|
-e 's/.*default \"\(.*\)\".*/\1/')
|
|
|
|
else
|
|
|
|
if [ -z "${KAS_FIRST_FILE}" ]; then
|
|
|
|
KAS_FIRST_FILE="${KAS_WORK_DIR}/.config.yaml"
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_SYSTEM=$(grep -e "^build_system: " "${KAS_FIRST_FILE}" 2>/dev/null | \
|
|
|
|
sed 's/build_system:[ ]\+//')
|
|
|
|
fi
|
|
|
|
|
2020-11-15 09:57:51 +01:00
|
|
|
if [ "${BUILD_SYSTEM}" = "isar" ]; then
|
|
|
|
enable_isar_mode
|
2023-03-07 09:07:08 +01:00
|
|
|
elif [ -z "${ISAR_MODE}" ]; then
|
2022-06-08 14:44:17 +02:00
|
|
|
enable_oe_mode
|
2020-11-15 09:57:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
set_container_image_var
|
|
|
|
|
2021-04-15 12:57:26 +02:00
|
|
|
KAS_REPO_MOUNT_OPT="${KAS_REPO_MOUNT_OPT:-${KAS_REPO_MOUNT_OPT_DEFAULT}}"
|
|
|
|
|
2021-08-18 15:27:31 +02:00
|
|
|
KAS_FILES="$(echo "${KAS_FILES}" | sed 's|'"${KAS_REPO_DIR}"'/|/repo/|g')"
|
2020-09-28 09:02:11 +02:00
|
|
|
|
|
|
|
if [ "$(id -u)" -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
|
|
|
|
echo "Error: Running as root - may break certain recipes."
|
|
|
|
echo "Better give a regular user docker access. Set" \
|
|
|
|
"KAS_ALLOW_ROOT=yes to override."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-15 12:57:26 +02:00
|
|
|
set -- "$@" -v "${KAS_REPO_DIR}":/repo:${KAS_REPO_MOUNT_OPT} \
|
2021-08-18 15:31:23 +02:00
|
|
|
-v "${KAS_WORK_DIR}":/work:rw -e KAS_WORK_DIR=/work \
|
2021-03-09 21:40:50 +01:00
|
|
|
-v "${KAS_BUILD_DIR}":/build:rw \
|
2021-08-18 15:31:23 +02:00
|
|
|
--workdir=/repo \
|
2021-03-09 21:40:50 +01:00
|
|
|
-e KAS_BUILD_DIR=/build \
|
2022-01-04 21:05:38 +01:00
|
|
|
-e USER_ID="$(id -u)" -e GROUP_ID="$(id -g)" --rm --init
|
2020-09-28 09:02:11 +02:00
|
|
|
|
2020-09-28 09:02:14 +02:00
|
|
|
if [ -n "${KAS_SSH_DIR}" ] ; then
|
|
|
|
if [ ! -d "${KAS_SSH_DIR}" ]; then
|
|
|
|
echo "Passed KAS_SSH_DIR '${KAS_SSH_DIR}' is not a directory"
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-03-09 22:35:14 +01:00
|
|
|
set -- "$@" -v "$(readlink -fv "${KAS_SSH_DIR}")":/var/kas/userdata/.ssh:ro
|
2020-09-28 09:02:11 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-25 10:40:18 +01:00
|
|
|
if [ -n "${KAS_SSH_AUTH_SOCK}" ]; then
|
|
|
|
if [ ! -S "${KAS_SSH_AUTH_SOCK}" ]; then
|
|
|
|
echo "Passed SSH_AUTH_SOCK '${KAS_SSH_AUTH_SOCK}' is not a socket"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
set -- "$@" -v "${KAS_SSH_AUTH_SOCK}":/ssh-agent/ssh-auth-sock \
|
|
|
|
-e SSH_AUTH_SOCK=/ssh-agent/ssh-auth-sock
|
|
|
|
fi
|
|
|
|
|
2020-09-28 09:02:14 +02:00
|
|
|
if [ -n "${KAS_AWS_DIR}" ] ; then
|
|
|
|
if [ ! -d "${KAS_AWS_DIR}" ]; then
|
|
|
|
echo "Passed KAS_AWS_DIR '${KAS_AWS_DIR}' is not a directory"
|
2020-09-28 09:02:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-03-09 22:35:14 +01:00
|
|
|
set -- "$@" -v "$(readlink -fv "${KAS_AWS_DIR}")":/var/kas/userdata/.aws:ro \
|
2023-02-27 13:21:31 +01:00
|
|
|
-e AWS_CONFIG_FILE="${AWS_CONFIG_FILE:-/var/kas/userdata/.aws/config}" \
|
|
|
|
-e AWS_SHARED_CREDENTIALS_FILE="${AWS_SHARED_CREDENTIALS_FILE:-/var/kas/userdata/.aws/credentials}"
|
2020-09-28 09:02:11 +02:00
|
|
|
fi
|
|
|
|
|
2021-05-06 11:31:13 +02:00
|
|
|
KAS_GIT_CREDENTIAL_HELPER_DEFAULT=""
|
|
|
|
|
|
|
|
if [ -n "${KAS_GIT_CREDENTIAL_STORE}" ] ; then
|
|
|
|
if [ ! -f "${KAS_GIT_CREDENTIAL_STORE}" ]; then
|
2022-09-30 13:49:27 +02:00
|
|
|
echo "Passed KAS_GIT_CREDENTIAL_STORE '${KAS_GIT_CREDENTIAL_STORE}' is not a file"
|
2021-05-06 11:31:13 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-02-27 13:21:31 +01:00
|
|
|
KAS_GIT_CREDENTIAL_HELPER_DEFAULT="store --file=/var/kas/userdata/.git-credentials"
|
2023-03-09 22:35:14 +01:00
|
|
|
set -- "$@" -v "$(readlink -fv "${KAS_GIT_CREDENTIAL_STORE}")":/var/kas/userdata/.git-credentials:ro
|
2021-05-06 11:31:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
GIT_CREDENTIAL_HELPER="${GIT_CREDENTIAL_HELPER:-${KAS_GIT_CREDENTIAL_HELPER_DEFAULT}}"
|
|
|
|
|
|
|
|
if [ -n "${GIT_CREDENTIAL_HELPER}" ] ; then
|
|
|
|
set -- "$@" -e GIT_CREDENTIAL_HELPER="${GIT_CREDENTIAL_HELPER}"
|
|
|
|
fi
|
|
|
|
|
2022-06-23 14:51:22 +02:00
|
|
|
if [ -f "${NETRC_FILE}" ]; then
|
2023-03-09 22:35:14 +01:00
|
|
|
set -- "$@" -v "$(readlink -fv "${NETRC_FILE}")":/var/kas/userdata/.netrc:ro \
|
2023-02-27 13:21:31 +01:00
|
|
|
-e NETRC_FILE="/var/kas/userdata/.netrc"
|
2022-06-23 14:51:22 +02:00
|
|
|
fi
|
|
|
|
|
2020-09-28 09:02:11 +02:00
|
|
|
if [ -t 1 ]; then
|
|
|
|
set -- "$@" -t -i
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${DL_DIR}" ]; then
|
|
|
|
trace mkdir -p "${DL_DIR}"
|
|
|
|
set -- "$@" \
|
2023-03-09 22:35:14 +01:00
|
|
|
-v "$(readlink -fv "${DL_DIR}")":/downloads:rw \
|
2020-09-28 09:02:11 +02:00
|
|
|
-e DL_DIR=/downloads
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${SSTATE_DIR}" ]; then
|
|
|
|
trace mkdir -p "${SSTATE_DIR}"
|
|
|
|
set -- "$@" \
|
2023-03-09 22:35:14 +01:00
|
|
|
-v "$(readlink -fv "${SSTATE_DIR}")":/sstate:rw \
|
2020-09-28 09:02:11 +02:00
|
|
|
-e SSTATE_DIR=/sstate
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${KAS_REPO_REF_DIR}" ]; then
|
2021-11-05 16:09:24 +01:00
|
|
|
if [ ! -d "${KAS_REPO_REF_DIR}" ]; then
|
|
|
|
echo "Passed KAS_REPO_REF_DIR '${KAS_REPO_REF_DIR}' is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-09-28 09:02:11 +02:00
|
|
|
set -- "$@" \
|
2023-03-09 22:35:14 +01:00
|
|
|
-v "$(readlink -fv "${KAS_REPO_REF_DIR}")":/repo-ref:rw \
|
2021-05-09 15:47:40 +02:00
|
|
|
-e KAS_REPO_REF_DIR=/repo-ref
|
2020-09-28 09:02:11 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK \
|
2023-03-02 08:25:51 +01:00
|
|
|
KAS_PREMIRRORS DISTRO_APT_PREMIRRORS BB_NUMBER_THREADS PARALLEL_MAKE \
|
|
|
|
GIT_CREDENTIAL_USEHTTPPATH; do
|
2020-09-28 09:02:11 +02:00
|
|
|
if [ -n "$(eval echo \$${var})" ]; then
|
|
|
|
set -- "$@" -e "${var}=$(eval echo \"\$${var}\")"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# propagate only supported SHELL settings
|
|
|
|
case "$SHELL" in
|
|
|
|
/bin/sh|/bin/bash|/bin/dash)
|
|
|
|
set -- "$@" -e "SHELL=$SHELL"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
set -- "$@" -e "SHELL=/bin/bash"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-09-28 09:02:14 +02:00
|
|
|
if [ -z "${KAS_NO_PROXY_FROM_ENV+x}" ]; then
|
2020-09-28 09:02:11 +02:00
|
|
|
for var in http_proxy https_proxy ftp_proxy no_proxy NO_PROXY; do
|
|
|
|
if [ -n "$(eval echo \$${var})" ]; then
|
|
|
|
set -- "$@" -e "${var}=$(eval echo \$${var})"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2021-01-29 14:19:02 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2020-09-28 09:02:14 +02:00
|
|
|
set -- "$@" ${KAS_ISAR_ARGS} ${KAS_WITH_LOOP_DEV} ${KAS_RUNTIME_ARGS} \
|
2021-01-29 12:12:17 +01:00
|
|
|
${KAS_CONTAINER_IMAGE} ${KAS_OPTIONS_DIRECT} ${KAS_CMD} ${KAS_OPTIONS}
|
|
|
|
if [ -n "${KAS_BITBAKE_C_OPTION_ARGS}" ]; then
|
|
|
|
set -- "$@" -c "${KAS_BITBAKE_C_OPTION_ARGS}"
|
|
|
|
fi
|
2021-01-29 14:19:02 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2021-01-29 12:12:17 +01:00
|
|
|
set -- "$@" ${KAS_FILES}
|
2021-05-20 15:57:22 +02:00
|
|
|
if [ "$KAS_CMD" = "for-all-repos" ]; then
|
|
|
|
set -- "$@" "${KAS_REPO_CMD}"
|
|
|
|
fi
|
2020-09-28 09:02:11 +02:00
|
|
|
|
|
|
|
# rotate any extra bitbake args from the front to the end of the argument list
|
|
|
|
while [ $KAS_EXTRA_BITBAKE_ARGS -gt 0 ]; do
|
|
|
|
arg="$1"
|
|
|
|
shift 1
|
|
|
|
set -- "$@" "$arg"
|
|
|
|
KAS_EXTRA_BITBAKE_ARGS=$((KAS_EXTRA_BITBAKE_ARGS - 1))
|
|
|
|
done
|
|
|
|
|
2020-09-28 09:02:14 +02:00
|
|
|
trace ${KAS_CONTAINER_COMMAND} run "$@"
|