3 #Here is a script to deploy cert to vsftpd server.
5 #returns 0 means success, otherwise error.
7 #DEPLOY_VSFTPD_CONF="/etc/vsftpd.conf"
8 #DEPLOY_VSFTPD_RELOAD="service vsftpd restart"
10 ######## Public functions #####################
12 #domain keyfile certfile cafile fullchain
20 _debug _cdomain
"$_cdomain"
22 _debug _ccert
"$_ccert"
24 _debug _cfullchain
"$_cfullchain"
26 _ssl_path
="/etc/acme.sh/vsftpd"
27 if ! mkdir
-p "$_ssl_path"; then
28 _err
"Can not create folder:$_ssl_path"
32 _info
"Copying key and cert"
33 _real_key
="$_ssl_path/vsftpd.key"
34 if ! cat "$_ckey" >"$_real_key"; then
35 _err
"Error: write key file to: $_real_key"
38 _real_fullchain
="$_ssl_path/vsftpd.chain.pem"
39 if ! cat "$_cfullchain" >"$_real_fullchain"; then
40 _err
"Error: write key file to: $_real_fullchain"
44 DEFAULT_VSFTPD_RELOAD
="service vsftpd restart"
45 _reload
="${DEPLOY_VSFTPD_RELOAD:-$DEFAULT_VSFTPD_RELOAD}"
47 if [ -z "$IS_RENEW" ]; then
48 DEFAULT_VSFTPD_CONF
="/etc/vsftpd.conf"
49 _vsftpd_conf
="${DEPLOY_VSFTPD_CONF:-$DEFAULT_VSFTPD_CONF}"
50 if [ ! -f "$_vsftpd_conf" ]; then
51 if [ -z "$DEPLOY_VSFTPD_CONF" ]; then
52 _err
"vsftpd conf is not found, please define DEPLOY_VSFTPD_CONF"
55 _err
"It seems that the specified vsftpd conf is not valid, please check."
59 if [ ! -w "$_vsftpd_conf" ]; then
60 _err
"The file $_vsftpd_conf is not writable, please change the permission."
63 _backup_conf
="$DOMAIN_BACKUP_PATH/vsftpd.conf.bak"
64 _info
"Backup $_vsftpd_conf to $_backup_conf"
65 cp "$_vsftpd_conf" "$_backup_conf"
67 _info
"Modify vsftpd conf: $_vsftpd_conf"
68 if _setopt
"$_vsftpd_conf" "rsa_cert_file" "=" "$_real_fullchain" &&
69 _setopt
"$_vsftpd_conf" "rsa_private_key_file" "=" "$_real_key" &&
70 _setopt
"$_vsftpd_conf" "ssl_enable" "=" "YES"; then
71 _info
"Set config success!"
73 _err
"Config vsftpd server error, please report bug to us."
74 _info
"Restoring vsftpd conf"
75 if cat "$_backup_conf" >"$_vsftpd_conf"; then
76 _info
"Restore conf success"
79 _err
"Oops, error restore vsftpd conf, please report bug to us."
85 _info
"Run reload: $_reload"
86 if eval "$_reload"; then
87 _info
"Reload success!"
88 if [ "$DEPLOY_VSFTPD_CONF" ]; then
89 _savedomainconf DEPLOY_VSFTPD_CONF
"$DEPLOY_VSFTPD_CONF"
91 _cleardomainconf DEPLOY_VSFTPD_CONF
93 if [ "$DEPLOY_VSFTPD_RELOAD" ]; then
94 _savedomainconf DEPLOY_VSFTPD_RELOAD
"$DEPLOY_VSFTPD_RELOAD"
96 _cleardomainconf DEPLOY_VSFTPD_RELOAD
100 _err
"Reload error, restoring"
101 if cat "$_backup_conf" >"$_vsftpd_conf"; then
102 _info
"Restore conf success"
105 _err
"Oops, error restore vsftpd conf, please report bug to us."