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:
parent
61b0a863e0
commit
6213664492
2 changed files with 9 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
userConfPath="/etc/sftp-users.conf"
|
userConfPath="/etc/sftp-users.conf"
|
||||||
userConfFinalPath="/var/run/sftp-users.conf"
|
userConfFinalPath="/var/run/sftp-users.conf"
|
||||||
|
@ -43,7 +44,7 @@ function createUser() {
|
||||||
if [ -n "$gid" ]; then
|
if [ -n "$gid" ]; then
|
||||||
useraddOptions="$useraddOptions --gid $gid"
|
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
|
groupadd --gid $gid $gid
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -85,9 +86,11 @@ for user in "$@"; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Append users from STDIN to final config
|
# Append users from STDIN to final config
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||||
echo "$user" >> "$userConfFinalPath"
|
echo "$user" >> "$userConfFinalPath"
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f "$userConfFinalPath" ]; then
|
if [ ! -f "$userConfFinalPath" ]; then
|
||||||
echo "ERROR: Missing users!"
|
echo "ERROR: Missing users!"
|
||||||
|
@ -97,7 +100,7 @@ fi
|
||||||
|
|
||||||
# Import users from final conf file
|
# Import users from final conf file
|
||||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||||
createUser "$user";
|
createUser "$user"
|
||||||
done < "$userConfFinalPath"
|
done < "$userConfFinalPath"
|
||||||
|
|
||||||
exec /usr/sbin/sshd -D
|
exec /usr/sbin/sshd -D
|
||||||
|
|
|
@ -14,7 +14,7 @@ sftpContainerName="atmoz_sftp_test"
|
||||||
if [ "$output" == "quiet" ]; then
|
if [ "$output" == "quiet" ]; then
|
||||||
redirect="/dev/null"
|
redirect="/dev/null"
|
||||||
else
|
else
|
||||||
redirect=$'&1'
|
redirect="/dev/stdout"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
Loading…
Reference in a new issue