-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathstart_vsftpd.sh
executable file
·83 lines (69 loc) · 2.08 KB
/
start_vsftpd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
#Remove all ftp users
grep '/ftp/' /etc/passwd | cut -d':' -f1 | xargs -r -n1 deluser
#Create users
#USERS='name1|password1|[folder1][|uid1][|gid1] name2|password2|[folder2][|uid2][|gid2]'
#may be:
# user|password foo|bar|/home/foo
#OR
# user|password|/home/user/dir|10000
#OR
# user|password|/home/user/dir|10000|10000
#OR
# user|password||10000|82
#Default user 'ftp' with password 'alpineftp'
if [ -z "$USERS" ]; then
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)
# Add group handling
GID=$(echo $i | cut -d'|' -f5)
if [ -z "$FOLDER" ]; then
FOLDER="/ftp/$NAME"
fi
if [ ! -z "$UID" ]; then
UID_OPT="-u $UID"
if [ -z "$GID" ]; then
GID=$UID
fi
#Check if the group with the same ID already exists
GROUP=$(getent group $GID | cut -d: -f1)
if [ ! -z "$GROUP" ]; then
GROUP_OPT="-G $GROUP"
elif [ ! -z "$GID" ]; then
# Group don't exist but GID supplied
addgroup -g $GID $NAME
GROUP_OPT="-G $NAME"
fi
fi
echo -e "$PASS\n$PASS" | adduser -h $FOLDER -s /sbin/nologin $UID_OPT $GROUP_OPT $NAME
mkdir -p $FOLDER
chown $NAME:$GROUP $FOLDER
unset NAME PASS FOLDER UID GID
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
if [ ! -z "$TLS_CERT" ] || [ ! -z "$TLS_KEY" ]; then
TLS_OPT="-orsa_cert_file=$TLS_CERT -orsa_private_key_file=$TLS_KEY -ossl_enable=YES -oallow_anon_ssl=NO -oforce_local_data_ssl=YES -oforce_local_logins_ssl=YES -ossl_tlsv1=NO -ossl_sslv2=NO -ossl_sslv3=NO -ossl_ciphers=HIGH"
fi
# Used to run custom commands inside container
if [ ! -z "$1" ]; then
exec "$@"
else
vsftpd -opasv_min_port=$MIN_PORT -opasv_max_port=$MAX_PORT $ADDR_OPT $TLS_OPT /etc/vsftpd/vsftpd.conf
[ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd
pgrep vsftpd | tail -n 1 > /var/run/vsftpd/vsftpd.pid
exec pidproxy /var/run/vsftpd/vsftpd.pid true
fi