2017-06-14 13:36:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
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
|
|
|
|
|
2017-06-19 09:28:34 +02:00
|
|
|
USER_ID=${USER_ID:-30000}
|
2018-11-23 18:16:59 +01:00
|
|
|
GROUP_ID=${GROUP_ID:-30000}
|
2017-06-14 13:36:37 +02:00
|
|
|
|
2017-07-20 18:13:14 +02:00
|
|
|
if [ $USER_ID == 0 ]; then
|
|
|
|
# We shall run everything as root
|
2017-11-21 18:21:40 +01:00
|
|
|
mkdir -p /builder
|
2017-06-14 13:36:37 +02:00
|
|
|
|
2021-01-20 00:05:06 +01:00
|
|
|
GOSU=""
|
|
|
|
elif [ $USER_ID == $UID ]; then
|
2018-07-17 21:56:12 +02:00
|
|
|
GOSU=""
|
2017-07-19 08:51:22 +02:00
|
|
|
else
|
2018-11-23 18:16:59 +01:00
|
|
|
if ! grep -q "^builder:" /etc/group; then
|
|
|
|
groupadd -o --gid $GROUP_ID builder
|
|
|
|
fi
|
|
|
|
if ! id builder >/dev/null 2>&1; then
|
2017-11-21 18:21:40 +01:00
|
|
|
# Create a non-root user that will perform the actual build
|
2018-11-23 18:16:59 +01:00
|
|
|
useradd -o --uid $USER_ID --gid $GROUP_ID --create-home \
|
|
|
|
--home-dir /builder builder
|
2017-11-21 18:21:40 +01:00
|
|
|
fi
|
2017-07-20 18:13:14 +02:00
|
|
|
|
2018-07-17 21:56:12 +02:00
|
|
|
GOSU="gosu builder"
|
|
|
|
fi
|
|
|
|
|
2018-07-17 21:56:14 +02:00
|
|
|
if [ "$PWD" = / ]; then
|
|
|
|
cd /builder
|
|
|
|
fi
|
|
|
|
|
2018-07-17 21:56:12 +02:00
|
|
|
if [ -n "$1" ]; then
|
2018-07-17 21:56:13 +02:00
|
|
|
case "$1" in
|
|
|
|
build|shell|-*)
|
|
|
|
exec $GOSU kas "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exec $GOSU "$@"
|
|
|
|
;;
|
|
|
|
esac
|
2018-07-17 21:56:12 +02:00
|
|
|
else
|
|
|
|
exec $GOSU bash
|
2017-07-19 08:51:22 +02:00
|
|
|
fi
|