0
0
Fork 0
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:
Adrian Dvergsdal 2015-12-16 19:41:49 +01:00
parent 55d879419f
commit c388a4ec68

View file

@ -35,6 +35,11 @@ function createUser() {
gid="${param[3]}" gid="${param[3]}"
fi 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" useraddOptions="--no-user-group"
if [ -n "$uid" ]; then if [ -n "$uid" ]; then
@ -75,32 +80,37 @@ if [ "$1" == "--readme" ]; then
exit 0 exit 0
fi fi
# Append mounted config to final config # Create final config
if [ -f "$userConfPath" ]; then if [ ! -f "$userConfFinalPath" ]; then
cat "$userConfPath" >> "$userConfFinalPath"
fi
# Append users from arguments to final config # Append mounted config to final config
for user in "$@"; do if [ -f "$userConfPath" ]; then
echo "$user" >> "$userConfFinalPath" cat "$userConfPath" >> "$userConfFinalPath"
done fi
# Append users from STDIN to final config # Append users from arguments to final config
if [ ! -t 0 ]; then for user in "$@"; do
while IFS= read -r user || [[ -n "$user" ]]; do
echo "$user" >> "$userConfFinalPath" echo "$user" >> "$userConfFinalPath"
done done
fi
if [ ! -f "$userConfFinalPath" ]; then # Append users from STDIN to final config
echo "ERROR: Missing users!" if [ ! -t 0 ]; then
printHelp while IFS= read -r user || [[ -n "$user" ]]; do
exit 1 echo "$user" >> "$userConfFinalPath"
fi done
fi
# Import users from final conf file if [ ! -f "$userConfFinalPath" ]; then
while IFS= read -r user || [[ -n "$user" ]]; do echo "ERROR: Missing users!"
createUser "$user" printHelp
done < "$userConfFinalPath" 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 exec /usr/sbin/sshd -D