Fixed user creation when group with the same id already exists

(cherry picked from commit 9fd6e070ff6d49b3a0fb4c4009a3072e2f007291)
This commit is contained in:
Delfer 2022-03-31 19:19:20 +03:00 committed by Amin Vakil
parent b58c0a3b20
commit 274cd6349c
No known key found for this signature in database
GPG key ID: 1EFC1864E9D9E56B
2 changed files with 14 additions and 8 deletions

View file

@ -14,7 +14,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`)

View file

@ -1,6 +1,6 @@
#!/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]'
@ -14,11 +14,12 @@
#Default user 'ftp' with password 'alpineftp'
if [ -z "$USERS" ]; then
USERS="amin|alpineftp"
USERS="alpineftp|alpineftp"
fi
for i in $USERS ; do
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)
@ -29,11 +30,16 @@ for i in $USERS ; do
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