Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions preinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ set -eu

USER="coder"

# Add a Coder user to run as in systemd.
if ! id -u $USER >/dev/null 2>&1; then
if id -u $USER >/dev/null 2>&1; then
# If the coder user already exists, we don't need to add it.
exit 0
fi

if command -V useradd >/dev/null 2>&1; then
useradd \
--create-home \
--system \
--user-group \
--shell /bin/false \
$USER

# Add the Coder user to the Docker group.
# Coder is frequently used with Docker, so
# this prevents failures when building.
#
# It's fine if this fails!
usermod \
--append \
--groups docker \
$USER 2>/dev/null || true
$USER >/dev/null 2>&1 || true
elif command -V adduser >/dev/null 2>&1; then
# On alpine distributions useradd does not exist.
# This is a backup!
addgroup -S $USER
adduser -G coder -S coder
adduser coder docker >/dev/null 2>&1 || true
fi