From 621366449274c0c9f82fd60931b681080698d51f Mon Sep 17 00:00:00 2001 From: Adrian Dvergsdal Date: Wed, 16 Dec 2015 11:54:57 +0100 Subject: [PATCH] Check if STDIN is coming from a pipe or a file See: http://www.linuxjournal.com/content/working-stdin-and-stdout --- entrypoint | 13 ++++++++----- tests/run | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/entrypoint b/entrypoint index 53438b7..9edf409 100755 --- a/entrypoint +++ b/entrypoint @@ -1,4 +1,5 @@ #!/bin/bash +set -e userConfPath="/etc/sftp-users.conf" userConfFinalPath="/var/run/sftp-users.conf" @@ -43,7 +44,7 @@ function createUser() { if [ -n "$gid" ]; then useraddOptions="$useraddOptions --gid $gid" - if [ "$(cat /etc/group | cut -d : -f3 | grep -q "$gid")" ]; then + if [ $(cat /etc/group | cut -d: -f3 | grep -q "$gid") ]; then groupadd --gid $gid $gid fi fi @@ -85,9 +86,11 @@ for user in "$@"; do done # Append users from STDIN to final config -while IFS= read -r user || [[ -n "$user" ]]; do - echo "$user" >> "$userConfFinalPath" -done +if [ ! -t 0 ]; then + while IFS= read -r user || [[ -n "$user" ]]; do + echo "$user" >> "$userConfFinalPath" + done +fi if [ ! -f "$userConfFinalPath" ]; then echo "ERROR: Missing users!" @@ -97,7 +100,7 @@ fi # Import users from final conf file while IFS= read -r user || [[ -n "$user" ]]; do - createUser "$user"; + createUser "$user" done < "$userConfFinalPath" exec /usr/sbin/sshd -D diff --git a/tests/run b/tests/run index 1679b11..2d506be 100755 --- a/tests/run +++ b/tests/run @@ -14,7 +14,7 @@ sftpContainerName="atmoz_sftp_test" if [ "$output" == "quiet" ]; then redirect="/dev/null" else - redirect=$'&1' + redirect="/dev/stdout" fi ##############################################################################