From 9f31e8d6c1666660bba94c1d235ab101c6392d77 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sat, 18 Apr 2020 17:41:46 +0400 Subject: [PATCH] Add ability to create users from environment variables --- Dockerfile | 8 ++++++-- entrypoint.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index b36fae6..cbef0e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ FROM alpine MAINTAINER Vladimir Hodakov -RUN apk add --no-cache samba-common-tools samba-server +RUN apk add --no-cache tini bash samba-common-tools samba-server + +COPY entrypoint.sh /usr/local/bin/entrypoint + +RUN ["chmod", "+x", "/usr/local/bin/entrypoint"] VOLUME /etc/samba \ /var/lib/samba \ @@ -12,4 +16,4 @@ EXPOSE 137/udp \ 139/tcp \ 445/tcp -CMD nmbd -D && smbd -FS --no-process-group +CMD ["/sbin/tini", "--", "/usr/local/bin/entrypoint"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2bf662e --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +while IFS='=' read -r name value ; do + if [[ $name == 'USER'* ]]; then + IFS=';' + read -ra userParams <<< "${!name}" + echo "Adding user ${userParams[0]}" + adduser --no-create-home --uid "${userParams[2]}" --ingroup "${userParams[1]}" \ + --disabled-password "${userParams[0]}" + fi +done < <(env) + +nmbd -D +smbd -FS --no-process-group