-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbx
executable file
·85 lines (75 loc) · 2.58 KB
/
tbx
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
#!/bin/bash
set -euo pipefail
if [ -e /.waketimed-toolbox ]; then
echo "ERROR: You're already within a waketimed toolbox container."
echo "Calls to toolbox shouldn't be nested."
exit 1
fi
CONTAINER_MGR=${CONTAINER_MGR:-podman}
DIR=$(dirname $(realpath $0))
PROJECT_DIR=$(realpath "$DIR")
PROJECT_TOOLBOX_IMAGE="${PROJECT_TOOLBOX_IMAGE:-localhost/waketimed_toolbox_builder}"
if [ -t 1 ]; then
TOOLBOX_TTY="${TOOLBOX_TTY:--ti}"
else
TOOLBOX_TTY="${TOOLBOX_TTY:-}"
fi
if ! $CONTAINER_MGR images | grep "^$PROJECT_TOOLBOX_IMAGE \\+latest " &> /dev/null; then
pushd "$PROJECT_DIR"
make toolbox-build
popd
fi
IDX=0
while $CONTAINER_MGR inspect waketimed_$IDX &> /dev/null; do
((IDX++))
done || true
mkdir -p $PROJECT_DIR/tmp/cargo
PASS_THROUGH_VARS=$(compgen -A variable | grep '^WAKETIMED_' | awk '{ print "-e " $0; }' | tr '\n' ' ' || true)
if [ -z "${DESKTOP_PASS_THROUGH+x}" ]; then
# This allows the container to run the app inside and have it
# connect with the user's desktop. It also allows running GDB on
# it.
DESKTOP_PASS_THROUGH="\
-v $XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR \
-e WAYLAND_DISPLAY \
-e DBUS_SESSION_BUS_ADDRESS \
-e DESKTOP_SESSION \
-e DISPLAY \
-e XDG_CURRENT_DESKTOP \
-e XDG_DATA_DIRS \
-e XDG_MENU_PREFIX \
-e XDG_RUNTIME_DIR \
-e XDG_SEAT \
-e XDG_SESSION_DESKTOP \
-e XDG_SESSION_ID \
-e XDG_SESSION_TYPE \
-e XDG_VTNR \
"
fi
# TODO: make use of --passwd-entry after it is released. Currently
# Podman uses the value from -w as the home dir in /etc/passwd for the
# main user in container (preserved via --userns=keep-id). This seems
# wrong. We explicitly pass -e HOME=$HOME to get around this, but
# there may be something that reads /etc/passwd rather than the env
# var perhaps...
# https://github.com/containers/podman/issues/13185
$CONTAINER_MGR run \
--name waketimed_$IDX \
--detach-keys='ctrl-^' \
$TOOLBOX_TTY \
--userns=keep-id \
-w "$PROJECT_DIR" \
--rm \
--privileged \
--tmpfs "$HOME" \
-v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket \
-v "$PROJECT_DIR/tmp/cargo:$HOME/.cargo:z" \
-v "$PROJECT_DIR:$PROJECT_DIR:z" \
-e "CARGO_HOME=$PROJECT_DIR/tmp/cargo" \
-e "HOME=$HOME" \
-e "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" \
${DESKTOP_PASS_THROUGH} \
${PASS_THROUGH_VARS} \
${PROJECT_TOOLBOX_ARGS:-} \
"$PROJECT_TOOLBOX_IMAGE" \
"$@"