browsertrix-crawler/docker-entrypoint.sh
Ed Summers cd17764b77
Check if group/user exists (#176)
Ensure that group and user do not already exist before creating them.

Fixes #174
2022-11-03 17:28:13 -07:00

28 lines
635 B
Bash
Executable file

#!/bin/sh
# Get UID/GID from volume dir
VOLUME_UID=$(stat -c '%u' /crawls)
VOLUME_GID=$(stat -c '%g' /crawls)
# Get the UID/GID we are running as
MY_UID=$(id -u)
MY_GID=$(id -g)
# If we aren't running as the owner of the /crawls/ dir then add a new user
# btrix with the same UID/GID of the /crawls dir and run as that user instead.
if [ "$MY_GID" != "$VOLUME_GID" ] || [ "$MY_UID" != "$VOLUME_UID" ]; then
groupadd btrix
groupmod -o --gid $VOLUME_GID btrix
useradd -ms /bin/bash -g $VOLUME_GID btrix
usermod -o -u $VOLUME_UID btrix > /dev/null
cmd="cd $PWD; $@"
su btrix -c "$cmd"
else
exec $@
fi