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

Minor refactoring of checks

This commit is contained in:
Adrian Dvergsdal 2015-12-21 01:37:42 +01:00
parent 02b5d4d09e
commit 27939df2ff
2 changed files with 17 additions and 16 deletions

View file

@ -20,12 +20,6 @@ function createUser() {
user="${param[0]}" user="${param[0]}"
pass="${param[1]}" pass="${param[1]}"
if [ -z "$user" ]; then
echo "You must at least provide a username."
printHelp
exit 1
fi
if [ "${param[2]}" == "e" ]; then if [ "${param[2]}" == "e" ]; then
chpasswdOptions="-e" chpasswdOptions="-e"
uid="${param[3]}" uid="${param[3]}"
@ -35,9 +29,14 @@ function createUser() {
gid="${param[3]}" gid="${param[3]}"
fi fi
if $(cat /etc/passwd | cut -d: -f3 | grep -q "$uid"); then if [ -z "$user" ]; then
echo "User with UID \"$uid\" already exists, skipping." echo "FATAL: You must at least provide a username."
return 0 exit 1
fi
if $(cat /etc/passwd | cut -d: -f1 | grep -q "$user"); then
echo "FATAL: User \"$user\" already exists."
exit 2
fi fi
useraddOptions="--no-user-group" useraddOptions="--no-user-group"
@ -47,11 +46,11 @@ function createUser() {
fi fi
if [ -n "$gid" ]; then 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 groupadd --gid $gid $gid
fi fi
useraddOptions="$useraddOptions --gid $gid"
fi fi
useradd $useraddOptions $user useradd $useraddOptions $user
@ -84,12 +83,12 @@ if [ "$1" == "--readme" ]; then
exit 0 exit 0
fi fi
# Create final config # Create users only on first run
if [ ! -f "$userConfFinalPath" ]; then if [ ! -f "$userConfFinalPath" ]; then
# Append mounted config to final config # Append mounted config to final config
if [ -f "$userConfPath" ]; then if [ -f "$userConfPath" ]; then
cat "$userConfPath" >> "$userConfFinalPath" cat "$userConfPath" > "$userConfFinalPath"
fi fi
# Append users from arguments to final config # Append users from arguments to final config
@ -104,10 +103,11 @@ if [ ! -f "$userConfFinalPath" ]; then
done done
fi fi
if [ ! -f "$userConfFinalPath" ]; then # Check that we have users in config
echo "ERROR: Missing users!" if [ "$(cat "$userConfFinalPath" | wc -l)" == 0 ]; then
echo "FATAL: No users provided!"
printHelp printHelp
exit 1 exit 3
fi fi
# Import users from final conf file # Import users from final conf file

View file

@ -46,6 +46,7 @@ function beforeTest() {
function afterTest() { function afterTest() {
if [ "$output" != "quiet" ]; then if [ "$output" != "quiet" ]; then
echo "Docker logs:"
docker logs "$sftpContainerName" docker logs "$sftpContainerName"
fi fi