From 1e506399b91d2a594a64f6879da36f9efbd4b61b Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Sat, 25 Jul 2015 13:55:33 +0200 Subject: [PATCH 1/4] Checking parameters and showing help --- .dockerignore | 1 - Dockerfile | 3 +-- entrypoint | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5f19104..6b8710a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ .git -.README.md diff --git a/Dockerfile b/Dockerfile index aa06bc8..7f1629a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM debian:wheezy 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..1ca64ca 100755 --- a/entrypoint +++ b/entrypoint @@ -1,10 +1,26 @@ #!/bin/bash +if [ $1 == "--readme" ]; then + cat /README.md + exit 0 +fi + +if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then + echo "Syntax: user:pass[:e][:[uid][:gid]]..." + echo "Use --readme for information and examples." + exit 0 +fi + for users in "$@"; do IFS=':' read -a data <<< "$users" user="${data[0]}" pass="${data[1]}" + if [ -z "$user" -o -z "$pass" ]; then + echo "You must at least provide a username and a password." + exit 1 + fi + if [ "${data[2]}" == "e" ]; then chpasswdOptions="-e" uid="${data[3]}" From 1822dc9a398b18b5845c741e7625ca66ce996df0 Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Sat, 25 Jul 2015 13:56:39 +0200 Subject: [PATCH 2/4] Upgrade to jessie --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7f1629a..0517abc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:wheezy +FROM debian:jessie MAINTAINER Adrian Dvergsdal [atmoz.net] RUN apt-get update && \ From 9ba2bfbe6ddfbbdbfaa417d0600289d0766120fb Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Sat, 25 Jul 2015 13:57:30 +0200 Subject: [PATCH 3/4] Use Docker Hub name and add imagelayers.io shield --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1fff1f..0366284 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -sftp [![Docker Build Status](http://hubstatus.container42.com/atmoz/sftp)](https://registry.hub.docker.com/u/atmoz/sftp) +atmoz/sftp [![Docker Build Status](http://hubstatus.container42.com/atmoz/sftp)](https://registry.hub.docker.com/u/atmoz/sftp) [![](https://badge.imagelayers.io/atmoz/sftp:latest.svg)](https://imagelayers.io/?images=atmoz/sftp:latest 'Get your own badge on imagelayers.io') ==== Easy to use SFTP ([SSH File Transfer Protocol](https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol)) server with [OpenSSH](https://en.wikipedia.org/wiki/OpenSSH). From 3c756a9b330f7a14400233036da94d70dc8f3848 Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Sat, 25 Jul 2015 14:00:24 +0200 Subject: [PATCH 4/4] Simple help output --- entrypoint | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/entrypoint b/entrypoint index 1ca64ca..6c02243 100755 --- a/entrypoint +++ b/entrypoint @@ -1,33 +1,32 @@ #!/bin/bash -if [ $1 == "--readme" ]; then - cat /README.md - exit 0 -fi - -if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then +function printHelp() { echo "Syntax: user:pass[:e][:[uid][:gid]]..." echo "Use --readme for information and examples." - exit 0 -fi +} -for users in "$@"; do - IFS=':' read -a data <<< "$users" - user="${data[0]}" - pass="${data[1]}" +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 [ "${data[2]}" == "e" ]; then + 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" @@ -55,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