-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_ftp.sh
More file actions
executable file
·118 lines (97 loc) · 3.31 KB
/
install_ftp.sh
File metadata and controls
executable file
·118 lines (97 loc) · 3.31 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# ============================================================================
# This script installs and configure an ftp server via vsftpd
# ============================================================================
# Uncomment the following line to debug
# set -o xtrace
#=================================================
# GLOBAL FUNCTIONS
#=================================================
if [[ ! -f common_packages ]]; then
curl -OL https://github.com/dlux/InstallScripts/raw/master/common_packages
curl -OL https://github.com/dlux/InstallScripts/raw/master/common_functions
fi
[[ ! -f common_packages ]] && echo 'Error. Unable to download common_packages.'
source common_packages
EnsureRoot
_PASSWORD='secure123'
_USER='dlux4ftp'
# ======================= Processes installation options =====================
while [[ $1 ]]; do
case "$1" in
--help|-h)
read -d '' extras <<- EOM
\ --password | -pw Password for ftp user.
--user | -u User for ftp servr. Default to dlux4ftp.
EOM
PrintHelp "Install & configure FTP server" $(basename "$0") "$extras"
;;
--password|-pw)
[[ -z $2 ]] && PrintError "Password must be provided"
_PASSWORD=$2
shift
;;
--user|-u)
[[ -z $2 ]] && PrintError "User must be provided"
_USER=$2
shift
;;
*)
HandleOptions "$@"
shift
esac
shift
done
# ========================= Configuration Section ============================
SetLocale /root
[[ -n $http_proxy ]] && SetProxy $http_proxy
[[ ! -z "$_PROXY" ]] && source .PROXY
UpdatePackageManager
function OpenPorts {
ufw allow 20/tcp
ufw allow 21/tcp
ufw allow 990/tcp
ufw allow 40000:50000/tcp
}
# ========================= Instalation ======================================
echo "FTP server installation begins"
AddUser $_USER $_PASSWORD False
mkdir /home/$_USER/ftp
chown nobody:nogroup /home/$_USER/ftp
mod a-w /home/$_USER/ftp
mkdir /home/$_USER/ftp/files
chown $_USER:$_USER /home/$_USER/ftp/files
echo "vsftpd test file" | sudo tee /home/$_USER/ftp/files/test.txt
InstallFirewallUFW
SetFirewallUFW
[[ -n $(ufw status | grep -i status..active) ]] && OpenPorts
$_INSTALLER_CMD vsftpd
[[ -f /etc/vsftpd.conf ]] && fpath='/etc' || fpath='/etc/vsftpd'
file_name=$fpath/vsftpd.conf
fulist=$fpath/vsftpd.userlist
cp $file_name "${file_name}.orig"
sed -i "s/anonymous_enable/#anonymous_enable/g" $file_name
sed -i "/Allow anonymous FTP/a anonymous_enable=NO" $file_name
sed -i "s/local_enable/#local_enable/g" $file_name
sed -i "/allow local users/a local_enable=YES" $file_name
sed -i "s/#write_enable=YES/write_enable=YES/g" $file_name
sed -i "s/#chroot_local_user=YES/chroot_local_user=YES/g" $file_name
read -d '' extraConf <<- EOC
user_sub_token=\$USER
local_root=/home/\$USER/ftp
pasv_min_port=40000
pasv_max_port=50000
listen_port=45000
userlist_enable=YES
userlist_file=$fulist
userlist_deny=NO
EOC
echo $extraConf >> $file_name
echo $_USER | tee -a $fulist
systemctl restart vsftpd
echo "Testing access - List files"
file_lst=$(curl -slu $_USER:$_PASSWORD ftp://localhost/files/)
[[ -z $(echo $file_lst | grep test.txt) ]] && PrintError "Something went wrong"
echo "FTP server is setup properly"
# Cleanup _proxy from apt if added - first coincedence
[[ -n $_ORIGINAL_PROXY ]] && UnsetProxy $_ORIGINAL_PROXY