mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 14:33:17 +00:00
Check if group/user exists (#176)
Ensure that group and user do not already exist before creating them. Fixes #174
This commit is contained in:
parent
ffa3174578
commit
cd17764b77
1 changed files with 12 additions and 11 deletions
|
@ -1,26 +1,27 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Get UID/GID from volume dir
|
# Get UID/GID from volume dir
|
||||||
|
|
||||||
VOLUME_UID=$(stat -c '%u' /crawls)
|
VOLUME_UID=$(stat -c '%u' /crawls)
|
||||||
VOLUME_GID=$(stat -c '%g' /crawls)
|
VOLUME_GID=$(stat -c '%g' /crawls)
|
||||||
|
|
||||||
|
# Get the UID/GID we are running as
|
||||||
|
|
||||||
MY_UID=$(id -u)
|
MY_UID=$(id -u)
|
||||||
MY_GID=$(id -g)
|
MY_GID=$(id -g)
|
||||||
|
|
||||||
# Run as custom user
|
# 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
|
if [ "$MY_GID" != "$VOLUME_GID" ] || [ "$MY_UID" != "$VOLUME_UID" ]; then
|
||||||
# create or modify user and group to match expected uid/gid
|
groupadd btrix
|
||||||
groupadd --gid $VOLUME_GID archivist || groupmod -o --gid $VOLUME_GID archivist
|
groupmod -o --gid $VOLUME_GID btrix
|
||||||
useradd -ms /bin/bash -u $VOLUME_UID -g $VOLUME_GID archivist || usermod -o -u $VOLUME_UID archivist
|
|
||||||
|
useradd -ms /bin/bash -g $VOLUME_GID btrix
|
||||||
|
usermod -o -u $VOLUME_UID btrix > /dev/null
|
||||||
|
|
||||||
cmd="cd $PWD; $@"
|
cmd="cd $PWD; $@"
|
||||||
|
su btrix -c "$cmd"
|
||||||
# run process as new archivist user
|
|
||||||
su archivist -c "$cmd"
|
|
||||||
|
|
||||||
# run as current user (root)
|
|
||||||
else
|
else
|
||||||
exec $@
|
exec $@
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue