Repository navigation
Expand file tree
/
Copy pathinit
More file actions
executable file
·101 lines (81 loc) · 2.89 KB
/
Copy pathinit
File metadata and controls
executable file
·101 lines (81 loc) · 2.89 KB
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
#!/usr/bin/env bash
# # (c) 2019 containerenv authors
#
# init wrapper
output() {
echo "[$(date '+%m/%d/%Y %H:%M:%S')] $*"
}
# Clean services
output "cleaning up extra systemd unit files that don't apply in a container"
cd /lib/systemd/system/sysinit.target.wants/; ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1 \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
if ! grep wheel < /etc/group >/dev/null 2>&1; then
output "creating wheel group"
groupadd --gid 998 wheel
fi
if ! grep 1000 < /etc/passwd >/dev/null 2>&1; then
output "creating user / group"
groupadd --gid 1000 "$USERNAME_CONFIG" || true
useradd --gid 1000 --uid 1000 -G wheel -m "$USERNAME_CONFIG" || true
if [[ -n "$DOCKER_GID" ]]; then
output "enabling access to host docker"
groupdel docker || true
groupadd --gid "$DOCKER_GID" docker
usermod -aG docker "$USERNAME_CONFIG"
chgrp docker /var/run/docker.sock
fi
cat << EOF > "/home/$USERNAME_CONFIG/.bashrc"
#!/usr/bin/env bash
# First init!
echo "Welcome! Please delete this .bashrc and replace it with something better."
echo ""
if [[ ! -e "$HOME/.xinitrc" ]] && [[ "\$X11_CONFIG" == "CONTAINER" ]]; then
echo "Warning: No ~/.xinitrc exists. Running startx will fail."
echo ""
fi
EOF
echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
fi
if [[ "$PULSEAUDIO_CONFIG" == "HOST" ]]; then
output "configuring pulseaudio to use the host's"
cat << EOF > /etc/pulse/client.conf
# Connect to the host's server using the mounted UNIX socket
default-server = unix:/run/user/1000/pulse/native
# Prevent a server running in the container
autospawn = no
daemon-binary = /bin/true
# Prevent the use of shared memory
enable-shm = false
EOF
fi
if [[ "$X11_CONFIG" == "CONTAINER" ]]; then
output "configuring container to run X11"
cat << EOF > /etc/X11/Xwrapper.config
allowed_users=anybody
needs_root_rights=yes
EOF
output " ... starting udevd"
/usr/lib/systemd/systemd-udevd &
udevadm trigger &
fi
# download containerenv if we can
if [[ -n "$CONTAINERENV_VERSION" ]]; then
output "fetching containerenv ..."
wget "https://github.com/containerenv/containerenv/releases/download/$CONTAINERENV_VERSION/containerenv-linux-amd64.tar.xz" -O /tmp/containerenv.tar.xz
pushd "/tmp" >/dev/null 2>&1
tar xvf /tmp/containerenv.tar.xz
cp /tmp/containerenv /usr/bin/containerenv
chmod +x /tmp/containerenv
popd >/dev/null 2>&1
output "using containerenv version $CONTAINERENV_VERSION"
fi
# setup the default user target
systemctl set-default multi-user.target
output "launching systemd"
exec /lib/systemd/systemd --no-pager --log-level info