0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2025-03-09 15:16:00 -04:00

ADD: re-evaluate user-list on container restart

This commit is contained in:
Alexander Kuemmel 2019-01-01 02:00:01 +01:00
parent bd437a09cb
commit 2a378f5a16

View file

@ -11,6 +11,8 @@ reArgSkip='^([[:blank:]]*#.*|[[:blank:]]*)$' # comment or empty line
userConfPath="/etc/sftp/users.conf" userConfPath="/etc/sftp/users.conf"
userConfPathLegacy="/etc/sftp-users.conf" userConfPathLegacy="/etc/sftp-users.conf"
userConfFinalPath="/var/run/sftp/users.conf" userConfFinalPath="/var/run/sftp/users.conf"
userProvisionedFinalPath="/var/run/sftp/users.provisioned"
userProvisionedTmpPath="/var/run/sftp/users.diff"
function log() { function log() {
echo "[$0] $*" >&2 echo "[$0] $*" >&2
@ -29,8 +31,21 @@ if [ ! -f "$userConfPath" ] && [ -f "$userConfPathLegacy" ]; then
ln -s "$userConfPathLegacy" "$userConfPath" ln -s "$userConfPathLegacy" "$userConfPath"
fi fi
# Create users only on first run # Check for differences between defined and provisioned users
if [ ! -f "$userConfFinalPath" ]; then if [ -f "$userProvisionedFinalPath" ]; then
set +e
diff "$userProvisionedFinalPath" "$userConfPath" \
| tail -n+3 \
| grep -E '^\+.*$' \
| cut -c2- \
| grep -v -E '^\s*#' > "$userProvisionedTmpPath"
set -e
SFTP_USERS="$(cat $userProvisionedTmpPath)"
rm -f "$userProvisionedTmpPath"
fi
# Create users on first run and if new entries are present
if [ ! -f "$userConfFinalPath" ] || [ -n "$SFTP_USERS" ]; then
mkdir -p "$(dirname $userConfFinalPath)" mkdir -p "$(dirname $userConfFinalPath)"
if [ -f "$userConfPath" ]; then if [ -f "$userConfPath" ]; then