diff --git a/.dockerignore b/.dockerignore index 8f2be31..e9dcab0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ .git tests -README.md diff --git a/Dockerfile b/Dockerfile index aa06bc8..0517abc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ -FROM debian:wheezy +FROM debian:jessie MAINTAINER Adrian Dvergsdal [atmoz.net] -# Install OpenSSH RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server && \ rm -rf /var/lib/apt/lists/* @@ -9,9 +8,9 @@ RUN apt-get update && \ # sshd needs this directory to run RUN mkdir -p /var/run/sshd -# Copy configuration and entrypoint script COPY sshd_config /etc/ssh/sshd_config COPY entrypoint / +COPY README.md / EXPOSE 22 diff --git a/entrypoint b/entrypoint index 0151e43..6c02243 100755 --- a/entrypoint +++ b/entrypoint @@ -1,17 +1,32 @@ #!/bin/bash -for users in "$@"; do - IFS=':' read -a data <<< "$users" - user="${data[0]}" - pass="${data[1]}" +function printHelp() { + echo "Syntax: user:pass[:e][:[uid][:gid]]..." + echo "Use --readme for information and examples." +} - if [ "${data[2]}" == "e" ]; then +function printReadme() { + cat /README.md +} + +function createUser() { + IFS=':' read -a param <<< $@ + user="${param[0]}" + pass="${param[1]}" + + if [ -z "$user" -o -z "$pass" ]; then + echo "You must at least provide a username and a password." + printHelp + exit 1 + fi + + if [ "${param[2]}" == "e" ]; then chpasswdOptions="-e" - uid="${data[3]}" - gid="${data[4]}" + uid="${param[3]}" + gid="${param[4]}" else - uid="${data[2]}" - gid="${data[3]}" + uid="${param[2]}" + gid="${param[3]}" fi useraddOptions="--create-home --no-user-group" @@ -39,6 +54,20 @@ for users in "$@"; do cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys chown $user /home/$user/.ssh/authorized_keys chmod 600 /home/$user/.ssh/authorized_keys +} + +if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then + printHelp + exit 0 +fi + +if [ "$1" == "--readme" ]; then + printReadme + exit 0 +fi + +for user in "$@"; do + createUser $user done exec /usr/sbin/sshd -D