0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2024-11-17 12:51:33 -05:00

Check if STDIN is coming from a pipe or a file

See: http://www.linuxjournal.com/content/working-stdin-and-stdout
This commit is contained in:
Adrian Dvergsdal 2015-12-16 11:54:57 +01:00
parent 61b0a863e0
commit 6213664492
2 changed files with 9 additions and 6 deletions

View file

@ -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
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

View file

@ -14,7 +14,7 @@ sftpContainerName="atmoz_sftp_test"
if [ "$output" == "quiet" ]; then
redirect="/dev/null"
else
redirect=$'&1'
redirect="/dev/stdout"
fi
##############################################################################