-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.bash
executable file
·48 lines (37 loc) · 1.03 KB
/
entrypoint.bash
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
#!/bin/bash -eu
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
tuser=tsvc
name=telemetry-server
_localstatedir=/var
_tsvcdir=${_localstatedir}/lib/${tuser}
_certdir=${_tsvcdir}/certs
[ -d ${_certdir} ] && cp -a ${_certdir}/* /etc/pki/trust/anchors
update-ca-certificates
if [[ ! -d ${_tsvcdir} ]]; then
echo "Error: no ${_tsvcdir} directory found; did you bind mount the service account dir to ${_tsvcdir}?"
exit 1
fi
uid_gid=(
$(stat -c '%u %g' ${_tsvcdir})
)
# ensure that the required group exists or add it with matching gid
# if needed
getent group ${tuser} >/dev/null || groupadd \
-r \
-g ${uid_gid[1]} \
${tuser}
# ensure that the required user exists or add it with matching uid
# if needed
getent passwd ${tuser} >/dev/null || useradd \
-r \
-g ${tuser} \
-u ${uid_gid[0]} \
-d ${_tsvcdir} \
-s /sbin/nologin \
-c "user for ${name}" ${tuser}
chown -R ${uid_gid[0]}:${uid_gid[1]} ${_tsvcdir}
cmd_args=(
/usr/bin/${name}
"${@}"
)
su - ${tuser} --shell /bin/bash -c "${cmd_args[*]}"