2017-06-14 13:36:37 +02:00
|
|
|
#!/bin/bash
|
2023-02-05 21:06:50 +01:00
|
|
|
#
|
|
|
|
# kas - setup tool for bitbake based projects
|
|
|
|
#
|
|
|
|
# Copyright (c) Siemens AG, 2017-2023
|
|
|
|
#
|
|
|
|
# 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.
|
2017-06-14 13:36:37 +02:00
|
|
|
|
2023-02-05 21:02:07 +01:00
|
|
|
# kas-isar: sudo update-binfmts --enable && [ -f /proc/sys/fs/binfmt_misc/status ]
|
2023-02-05 20:56:06 +01:00
|
|
|
|
2017-07-05 14:03:26 +02:00
|
|
|
if mount | grep -q "on / type aufs"; then
|
|
|
|
cat <<EOF >&2
|
|
|
|
WARNING: Generation of wic images will fail!
|
|
|
|
|
|
|
|
Your docker host setup uses broken aufs as storage driver. Adjust the docker
|
2018-07-17 21:56:11 +02:00
|
|
|
configuration to use a different driver (overlay, overlay2, devicemapper). You
|
|
|
|
may also need to update the host distribution (e.g. Debian Jessie -> Stretch).
|
2017-07-05 14:03:26 +02:00
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2023-02-06 17:57:53 +01:00
|
|
|
if [ -z "$USER_ID" ]; then
|
|
|
|
# Not a kas-container call
|
|
|
|
GOSU=""
|
|
|
|
|
|
|
|
# Work around gitlab-runner not aligning checked out repo ownership
|
|
|
|
# with our builder user
|
|
|
|
sudo git config --system safe.directory "*"
|
|
|
|
elif [ "$USER_ID" == 0 ]; then
|
|
|
|
# We shall run everything as root
|
2018-07-17 21:56:12 +02:00
|
|
|
GOSU=""
|
2017-07-19 08:51:22 +02:00
|
|
|
else
|
2023-02-05 21:02:07 +01:00
|
|
|
GROUP_ID=${GROUP_ID:-$(id -g)}
|
2017-07-20 18:13:14 +02:00
|
|
|
|
2023-02-05 21:02:07 +01:00
|
|
|
groupmod -o --gid "$GROUP_ID" builder
|
|
|
|
usermod -o --uid "$USER_ID" --gid "$GROUP_ID" builder >/dev/null
|
|
|
|
chown -R "$USER_ID":"$GROUP_ID" /builder
|
2023-02-27 13:21:30 +01:00
|
|
|
# copy host SSH config into home of builder
|
2023-02-27 13:21:31 +01:00
|
|
|
if [ -d /var/kas/userdata/.ssh ]; then
|
|
|
|
cp -a /var/kas/userdata/.ssh /builder/
|
2023-02-27 13:21:30 +01:00
|
|
|
fi
|
2023-02-05 20:56:06 +01:00
|
|
|
|
2023-02-05 21:02:07 +01:00
|
|
|
GOSU="gosu builder"
|
2018-07-17 21:56:12 +02:00
|
|
|
fi
|
|
|
|
|
2018-07-17 21:56:14 +02:00
|
|
|
if [ "$PWD" = / ]; then
|
2022-01-10 12:39:14 +01:00
|
|
|
cd /builder || exit 1
|
2018-07-17 21:56:14 +02:00
|
|
|
fi
|
|
|
|
|
2018-07-17 21:56:12 +02:00
|
|
|
if [ -n "$1" ]; then
|
2018-07-17 21:56:13 +02:00
|
|
|
case "$1" in
|
2022-12-11 08:30:29 +01:00
|
|
|
build|checkout|dump|for-all-repos|menu|shell|-*)
|
2022-01-10 12:39:14 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2018-07-17 21:56:13 +02:00
|
|
|
exec $GOSU kas "$@"
|
|
|
|
;;
|
|
|
|
*)
|
2022-01-10 12:39:14 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2018-07-17 21:56:13 +02:00
|
|
|
exec $GOSU "$@"
|
|
|
|
;;
|
|
|
|
esac
|
2018-07-17 21:56:12 +02:00
|
|
|
else
|
2022-01-10 12:39:14 +01:00
|
|
|
# SC2086: Double quote to prevent globbing and word splitting.
|
|
|
|
# shellcheck disable=2086
|
2018-07-17 21:56:12 +02:00
|
|
|
exec $GOSU bash
|
2017-07-19 08:51:22 +02:00
|
|
|
fi
|