1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#!/bin/sh
#
# 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.
enable_qemu_binfmts()
{
if ! [ -f /proc/sys/fs/binfmt_misc/status ]; then
sudo mount -t binfmt_misc null /proc/sys/fs/binfmt_misc
fi
for CONF in /usr/lib/binfmt.d/qemu-*.conf; do
if ! [ -f /proc/sys/fs/binfmt_misc/"$(basename "${CONF%%.conf}")" ]; then
sudo sh -c "cat '$CONF' > /proc/sys/fs/binfmt_misc/register"
fi
done
}
# kas-isar: enable_qemu_binfmts
chown_managed_dirs()
{
for DIR in /build /work /sstate /downloads /repo-ref; do
if [ -d "$DIR" ]; then
chown "$1":"$2" "$DIR"
fi
done
# SSH Directory Permissions
if [ -d "/builder/.ssh" ]; then
chown -R "$1":"$2" "/builder/.ssh"
fi
}
restore_managed_dirs_owner()
{
chown_managed_dirs 0 0
}
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
configuration to use a different driver (overlay, overlay2, devicemapper). You
may also need to update the host distribution (e.g. Debian Jessie -> Stretch).
EOF
fi
# if the container is started from a not supported terminal, fallback to xterm
if [ -n "$TERM" ]; then
infocmp "$TERM" > /dev/null 2>&1 || TERM=xterm
fi
if [ -z "$USER_ID" ] && [ -n "$CI_PROJECT_DIR" ]; then
# Work around for gitlab-runner not aligning checked out repo ownership
# with our builder user. We handle that internally in kas, but we
# need the exception here as well for git calls outside of kas.
sudo git config --system safe.directory "$CI_PROJECT_DIR"
# Account for externally specified git clone path
if [ -n "$GIT_CLONE_PATH" ]; then
sudo git config --system --add safe.directory "$GIT_CLONE_PATH"
fi
fi
if [ -z "$USER_ID" ] || [ "$USER_ID" = 0 ]; then
# Not a kas-container call, or we shall run everything as root
GOSU=""
else
GROUP_ID=${GROUP_ID:-$(id -g)}
groupmod -o --gid "$GROUP_ID" builder
usermod -o --uid "$USER_ID" --gid "$GROUP_ID" builder >/dev/null
chown -R "$USER_ID":"$GROUP_ID" /builder
# copy host SSH config into home of builder
if [ -d /var/kas/userdata/.ssh ]; then
cp -a /var/kas/userdata/.ssh /builder/
fi
# adjust timezone to host
if [ -n "${KAS_HOST_TZ}" ] && [ -f "/usr/share/zoneinfo/${KAS_HOST_TZ}" ]; then
echo "${KAS_HOST_TZ}" > /etc/timezone
ln -sf "/usr/share/zoneinfo/${KAS_HOST_TZ}" /etc/localtime
fi
GOSU="gosu builder"
fi
# kas-container on rootless docker workaround
if [ -n "$USER_ID" ] && [ "$USER_ID" -ne 0 ] && \
[ "$KAS_DOCKER_ROOTLESS" = "1" ] && [ "$(stat -c %u /repo)" -eq 0 ]; then
# Docker rootless does not support keeping the user namespace
# (podman option --userns=keep-id). By that, the bind mounts
# are owned by root.
git config --system safe.directory /repo
chown_managed_dirs "$USER_ID" "$GROUP_ID"
# Copy userdata to a writable location so we can chown it.
if [ -d "/var/kas/userdata" ]; then
mv /var/kas/userdata /var/kas/userdata.orig
cp -r /var/kas/userdata.orig /var/kas/userdata
chown -R "$USER_ID":"$GROUP_ID" /var/kas/userdata
fi
fi
if [ "$PWD" = / ]; then
cd /builder || exit 1
fi
if [ -n "$1" ]; then
case "$1" in
build|checkout|clean*|diff|dump|for-all-repos|lock|menu|purge|shell|-*)
# We must restore the dir owner after every kas invocation.
# This is cheap as only the top-level dirs are changed (non recursive).
if [ "$KAS_DOCKER_ROOTLESS" = "1" ]; then
trap restore_managed_dirs_owner EXIT INT TERM
$GOSU kas "$@"
else
# SC2086: Double quote to prevent globbing and word splitting.
# shellcheck disable=2086
exec $GOSU kas "$@"
fi
;;
*)
if [ -n "$USER_ID" ]; then
echo "kas-container: this container does not support \"kas $1\"" >&2
exit 1
fi
# SC2086: Double quote to prevent globbing and word splitting.
# shellcheck disable=2086
exec $GOSU "$@"
;;
esac
else
# SC2086: Double quote to prevent globbing and word splitting.
# shellcheck disable=2086
exec $GOSU bash
fi
|