Skip to content

Commit

Permalink
Fixed user creation when group with the same id already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
delfer committed Mar 31, 2022
1 parent 669039a commit 9fd6e07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker run -d \
## Configuration

Environment variables:
- `USERS` - space and `|` separated list (optional, default: `ftp|alpineftp`)
- `USERS` - space and `|` separated list (optional, default: `alpineftp|alpineftp`)
- format `name1|password1|[folder1][|uid1] name2|password2|[folder2][|uid2]`
- `ADDRESS` - external address witch clients can connect passive ports (optional, should resolve to ftp server ip address)
- `MIN_PORT` - minimum port number to be used for passive connections (optional, default `21000`)
Expand Down
20 changes: 13 additions & 7 deletions start_vsftpd.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#Remove all ftp users
grep '/ftp/' /etc/passwd | cut -d':' -f1 | xargs -n1 deluser
grep '/ftp/' /etc/passwd | cut -d':' -f1 | xargs -r -n1 deluser

#Create users
#USERS='name1|password1|[folder1][|uid1] name2|password2|[folder2][|uid2]'
Expand All @@ -15,26 +15,32 @@ grep '/ftp/' /etc/passwd | cut -d':' -f1 | xargs -n1 deluser
#Default user 'ftp' with password 'alpineftp'

if [ -z "$USERS" ]; then
USERS="ftp|alpineftp"
USERS="alpineftp|alpineftp"
fi

for i in $USERS ; do
NAME=$(echo $i | cut -d'|' -f1)
PASS=$(echo $i | cut -d'|' -f2)
NAME=$(echo $i | cut -d'|' -f1)
GROUP=$NAME
PASS=$(echo $i | cut -d'|' -f2)
FOLDER=$(echo $i | cut -d'|' -f3)
UID=$(echo $i | cut -d'|' -f4)
UID=$(echo $i | cut -d'|' -f4)

if [ -z "$FOLDER" ]; then
FOLDER="/ftp/$NAME"
fi

if [ ! -z "$UID" ]; then
UID_OPT="-u $UID"
#Check if the group with the same ID already exists
GROUP=$(getent group $UID | cut -d: -f1)
if [ ! -z "$GROUP" ]; then
GROUP_OPT="-G $GROUP"
fi
fi

echo -e "$PASS\n$PASS" | adduser -h $FOLDER -s /sbin/nologin $UID_OPT $NAME
echo -e "$PASS\n$PASS" | adduser -h $FOLDER -s /sbin/nologin $UID_OPT $GROUP_OPT $NAME
mkdir -p $FOLDER
chown $NAME:$NAME $FOLDER
chown $NAME:$GROUP $FOLDER
unset NAME PASS FOLDER UID
done

Expand Down

0 comments on commit 9fd6e07

Please sign in to comment.