mirror of
https://github.com/atmoz/sftp.git
synced 2024-11-17 12:51:33 -05:00
Do not create users on container restart
This commit is contained in:
parent
55d879419f
commit
c388a4ec68
1 changed files with 31 additions and 21 deletions
52
entrypoint
52
entrypoint
|
@ -35,6 +35,11 @@ function createUser() {
|
|||
gid="${param[3]}"
|
||||
fi
|
||||
|
||||
if $(cat /etc/passwd | cut -d: -f3 | grep -q "$uid"); then
|
||||
echo "User with UID \"$uid\" already exists, skipping."
|
||||
return 0
|
||||
fi
|
||||
|
||||
useraddOptions="--no-user-group"
|
||||
|
||||
if [ -n "$uid" ]; then
|
||||
|
@ -75,32 +80,37 @@ if [ "$1" == "--readme" ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# Append mounted config to final config
|
||||
if [ -f "$userConfPath" ]; then
|
||||
cat "$userConfPath" >> "$userConfFinalPath"
|
||||
fi
|
||||
# Create final config
|
||||
if [ ! -f "$userConfFinalPath" ]; then
|
||||
|
||||
# Append users from arguments to final config
|
||||
for user in "$@"; do
|
||||
echo "$user" >> "$userConfFinalPath"
|
||||
done
|
||||
# Append mounted config to final config
|
||||
if [ -f "$userConfPath" ]; then
|
||||
cat "$userConfPath" >> "$userConfFinalPath"
|
||||
fi
|
||||
|
||||
# Append users from STDIN to final config
|
||||
if [ ! -t 0 ]; then
|
||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||
# Append users from arguments to final config
|
||||
for user in "$@"; do
|
||||
echo "$user" >> "$userConfFinalPath"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ ! -f "$userConfFinalPath" ]; then
|
||||
echo "ERROR: Missing users!"
|
||||
printHelp
|
||||
exit 1
|
||||
fi
|
||||
# Append users from STDIN to final config
|
||||
if [ ! -t 0 ]; then
|
||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||
echo "$user" >> "$userConfFinalPath"
|
||||
done
|
||||
fi
|
||||
|
||||
# Import users from final conf file
|
||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||
createUser "$user"
|
||||
done < "$userConfFinalPath"
|
||||
if [ ! -f "$userConfFinalPath" ]; then
|
||||
echo "ERROR: Missing users!"
|
||||
printHelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Import users from final conf file
|
||||
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||
createUser "$user"
|
||||
done < "$userConfFinalPath"
|
||||
|
||||
fi
|
||||
|
||||
exec /usr/sbin/sshd -D
|
||||
|
|
Loading…
Reference in a new issue