2019-02-26 14:24:14 +00:00
|
|
|
#!/bin/sh
|
2018-06-16 14:50:45 +00:00
|
|
|
#Remove all ftp users
|
2022-03-31 16:19:20 +00:00
|
|
|
grep '/ftp/' /etc/passwd | cut -d':' -f1 | xargs -r -n1 deluser
|
2018-06-16 14:50:45 +00:00
|
|
|
|
|
|
|
#Create users
|
|
|
|
#USERS='name1|password1|[folder1][|uid1] name2|password2|[folder2][|uid2]'
|
|
|
|
#may be:
|
|
|
|
# user|password foo|bar|/home/foo
|
|
|
|
#OR
|
|
|
|
# user|password|/home/user/dir|10000
|
|
|
|
#OR
|
|
|
|
# user|password||10000
|
|
|
|
|
|
|
|
#Default user 'ftp' with password 'alpineftp'
|
|
|
|
|
|
|
|
if [ -z "$USERS" ]; then
|
2022-03-31 16:19:20 +00:00
|
|
|
USERS="alpineftp|alpineftp"
|
2018-06-16 14:50:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
for i in $USERS ; do
|
2022-03-31 16:19:20 +00:00
|
|
|
NAME=$(echo $i | cut -d'|' -f1)
|
|
|
|
GROUP=$NAME
|
|
|
|
PASS=$(echo $i | cut -d'|' -f2)
|
2018-06-16 14:50:45 +00:00
|
|
|
FOLDER=$(echo $i | cut -d'|' -f3)
|
2022-03-31 16:19:20 +00:00
|
|
|
UID=$(echo $i | cut -d'|' -f4)
|
2018-06-16 14:50:45 +00:00
|
|
|
|
|
|
|
if [ -z "$FOLDER" ]; then
|
|
|
|
FOLDER="/ftp/$NAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$UID" ]; then
|
|
|
|
UID_OPT="-u $UID"
|
2022-03-31 16:19:20 +00:00
|
|
|
#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
|
2018-06-16 14:50:45 +00:00
|
|
|
fi
|
|
|
|
|
2022-03-31 16:19:20 +00:00
|
|
|
echo -e "$PASS\n$PASS" | adduser -h $FOLDER -s /sbin/nologin $UID_OPT $GROUP_OPT $NAME
|
2018-06-16 14:50:45 +00:00
|
|
|
mkdir -p $FOLDER
|
2022-03-31 16:19:20 +00:00
|
|
|
chown $NAME:$GROUP $FOLDER
|
2018-06-16 14:50:45 +00:00
|
|
|
unset NAME PASS FOLDER UID
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$MIN_PORT" ]; then
|
|
|
|
MIN_PORT=21000
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$MAX_PORT" ]; then
|
|
|
|
MAX_PORT=21010
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$ADDRESS" ]; then
|
|
|
|
ADDR_OPT="-opasv_address=$ADDRESS"
|
|
|
|
fi
|
|
|
|
|
2019-11-28 19:03:06 +00:00
|
|
|
# Used to run custom commands inside container
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
exec "$@"
|
|
|
|
else
|
2020-02-05 21:16:40 +00:00
|
|
|
exec /usr/sbin/vsftpd -opasv_min_port=$MIN_PORT -opasv_max_port=$MAX_PORT $ADDR_OPT /etc/vsftpd/vsftpd.conf & sleep infinity
|
2019-11-28 19:03:06 +00:00
|
|
|
fi
|