Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 411caa2

Browse files
authored
fix: Refactor preinstall script to use useradd if adduser is not available (coder#2858)
Fixes coder#2800 preventing installation on Alpine.
1 parent 52fa1f2 commit 411caa2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

preinstall.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ set -eu
33

44
USER="coder"
55

6-
# Add a Coder user to run as in systemd.
7-
if ! id -u $USER >/dev/null 2>&1; then
6+
if id -u $USER >/dev/null 2>&1; then
7+
# If the coder user already exists, we don't need to add it.
8+
exit 0
9+
fi
10+
11+
if command -V useradd >/dev/null 2>&1; then
812
useradd \
913
--create-home \
1014
--system \
1115
--user-group \
1216
--shell /bin/false \
1317
$USER
1418

15-
# Add the Coder user to the Docker group.
16-
# Coder is frequently used with Docker, so
17-
# this prevents failures when building.
18-
#
19-
# It's fine if this fails!
2019
usermod \
2120
--append \
2221
--groups docker \
23-
$USER 2>/dev/null || true
22+
$USER >/dev/null 2>&1 || true
23+
elif command -V adduser >/dev/null 2>&1; then
24+
# On alpine distributions useradd does not exist.
25+
# This is a backup!
26+
addgroup -S $USER
27+
adduser -G coder -S coder
28+
adduser coder docker >/dev/null 2>&1 || true
2429
fi

0 commit comments

Comments
 (0)