forked from stilliard/docker-pure-ftpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
81 lines (66 loc) · 2.29 KB
/
run.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
#!/bin/bash
# build up flags passed to this file on run + env flag for additional flags
# e.g. -e "ADDED_FLAGS=--tls=2"
PURE_FTPD_FLAGS="$@ $ADDED_FLAGS "
# start rsyslog
if [[ "$PURE_FTPD_FLAGS" == *" -d "* ]] || [[ "$PURE_FTPD_FLAGS" == *"--verboselog"* ]]
then
echo "Log enabled, see /var/log/messages"
rsyslogd
fi
PASSWD_FILE="/etc/pure-ftpd/passwd/pureftpd.passwd"
# Load in any existing db from volume store
if [ -e /etc/pure-ftpd/passwd/pureftpd.passwd ]
then
pure-pw mkdb /etc/pure-ftpd/pureftpd.pdb -f "$PASSWD_FILE"
fi
# detect if using TLS (from volumed in file) but no flag set, set one
if [ -e /etc/ssl/private/pure-ftpd.pem ] && [[ "$PURE_FTPD_FLAGS" != *"--tls"* ]]
then
echo "TLS Enabled"
PURE_FTPD_FLAGS="$PURE_FTPD_FLAGS --tls=1 "
fi
# Add user
if [ ! -z "$FTP_USER_NAME" ] && [ ! -z "$FTP_USER_PASS" ] && [ ! -z "$FTP_USER_HOME" ]
then
echo "Creating user..."
# Generate the file that will be used to inject in the password prompt stdin
PWD_FILE="$(mktemp)"
echo "$FTP_USER_PASS
$FTP_USER_PASS" > "$PWD_FILE"
# Set uid/gid
PURE_PW_ADD_FLAGS=""
if [ ! -z "$FTP_USER_UID" ]
then
PURE_PW_ADD_FLAGS="$PURE_PW_ADD_FLAGS -u $FTP_USER_UID"
else
PURE_PW_ADD_FLAGS="$PURE_PW_ADD_FLAGS -u ftpuser"
fi
if [ ! -z "$FTP_USER_GID" ]
then
PURE_PW_ADD_FLAGS="$PURE_PW_ADD_FLAGS -g $FTP_USER_GID"
fi
pure-pw useradd "$FTP_USER_NAME" -f "$PASSWD_FILE" -m -d "$FTP_USER_HOME" $PURE_PW_ADD_FLAGS < "$PWD_FILE"
if [ ! -z "$FTP_USER_HOME_PERMISSION" ]
then
chmod "$FTP_USER_HOME_PERMISSION" "$FTP_USER_HOME"
echo " root user give $FTP_USER_NAME ftp user at $FTP_USER_HOME directory has $FTP_USER_HOME_PERMISSION permission"
fi
rm "$PWD_FILE"
fi
# Set a default value to the env var FTP_PASSIVE_PORTS
if [ -z "$FTP_PASSIVE_PORTS" ]
then
FTP_PASSIVE_PORTS=30000:30009
fi
# Set passive port range in pure-ftpd options if not already existent
if [[ $PURE_FTPD_FLAGS != *" -p "* ]]
then
echo "Setting default port range"
PURE_FTPD_FLAGS="$PURE_FTPD_FLAGS -p $FTP_PASSIVE_PORTS"
fi
# let users know what flags we've ended with (useful for debug)
echo "Starting Pure-FTPd:"
echo " pure-ftpd $PURE_FTPD_FLAGS"
# start pureftpd with requested flags
exec /usr/sbin/pure-ftpd $PURE_FTPD_FLAGS