-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-vsftpd.sh
78 lines (64 loc) · 2.46 KB
/
run-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
#!/bin/bash
# If no env var for FTP_USER has been specified, use 'admin':
if [ "$FTP_USER" = "**String**" ]; then
export FTP_USER='admin'
fi
# If no env var has been specified, generate a random password for FTP_USER:
if [ "$FTP_PASS" = "**Random**" ]; then
export FTP_PASS=`cat /dev/urandom | tr -dc A-Z-a-z-0-9 | head -c${1:-16}`
fi
# Do not log to STDOUT by default:
if [ "$LOG_STDOUT" = "**Boolean**" ]; then
export LOG_STDOUT=''
else
export LOG_STDOUT='Yes.'
fi
# Create home dir and update vsftpd user db:
mkdir -p "/home/vsftpd/${FTP_USER}"
chown -R ftp:ftp /home/vsftpd/
echo -e "${FTP_USER}\n${FTP_PASS}" > /etc/vsftpd/virtual_users.txt
/usr/bin/db_load -T -t hash -f /etc/vsftpd/virtual_users.txt /etc/vsftpd/virtual_users.db
# Set passive mode parameters:
if [ "$PASV_ADDRESS" = "**IPv4**" ]; then
export PASV_ADDRESS=$(/sbin/ip route|awk '/default/ { print $3 }')
fi
echo "pasv_address=${PASV_ADDRESS}" >> /etc/vsftpd/vsftpd.conf
echo "pasv_max_port=${PASV_MAX_PORT}" >> /etc/vsftpd/vsftpd.conf
echo "pasv_min_port=${PASV_MIN_PORT}" >> /etc/vsftpd/vsftpd.conf
# If env var has been specified, set local_umask:
if [ ! "$LOCAL_UMASK" = "**String**" ]; then
echo "local_umask=${LOCAL_UMASK}" >> /etc/vsftpd/vsftpd.conf
fi
# If env var has been specified, set file_open_mode:
if [ ! "$FILE_OPEN_MODE" = "**String**" ]; then
echo "file_open_mode=${FILE_OPEN_MODE}" >> /etc/vsftpd/vsftpd.conf
fi
# If env var has been specified, set pasv_addr_resolve:
if [ ! "$PASV_ADDR_RESOLVE" = "**Boolean**" ]; then
echo "pasv_addr_resolve=${PASV_ADDR_RESOLVE}" >> /etc/vsftpd/vsftpd.conf
fi
# Get log file path
export LOG_FILE=`grep xferlog_file /etc/vsftpd/vsftpd.conf|cut -d= -f2`
# stdout server info:
if [ ! $LOG_STDOUT ]; then
cat << EOB
*************************************************
* *
* Docker image: mayi/vsftd *
* https://github.com/mayi/docker-vsftpd *
* *
*************************************************
SERVER SETTINGS
---------------
· FTP User: $FTP_USER
· FTP Password: $FTP_PASS
· Log file: $LOG_FILE
· Redirect vsftpd log to STDOUT: No.
. The value that the umask for file creation is set to for local users: $LOCAL_UMASK
. The permissions with which uploaded files are created: $FILE_OPEN_MODE
EOB
else
/usr/bin/ln -sf /dev/stdout $LOG_FILE
fi
# Run vsftpd:
&>/dev/null /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf