vsftpd.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env sh
  2. #Here is a script to deploy cert to vsftpd server.
  3. #returns 0 means success, otherwise error.
  4. #DEPLOY_VSFTPD_CONF="/etc/vsftpd.conf"
  5. #DEPLOY_VSFTPD_RELOAD="service vsftpd restart"
  6. ######## Public functions #####################
  7. #domain keyfile certfile cafile fullchain
  8. vsftpd_deploy() {
  9. _cdomain="$1"
  10. _ckey="$2"
  11. _ccert="$3"
  12. _cca="$4"
  13. _cfullchain="$5"
  14. _debug _cdomain "$_cdomain"
  15. _debug _ckey "$_ckey"
  16. _debug _ccert "$_ccert"
  17. _debug _cca "$_cca"
  18. _debug _cfullchain "$_cfullchain"
  19. _ssl_path="/etc/acme.sh/vsftpd"
  20. if ! mkdir -p "$_ssl_path"; then
  21. _err "Can not create folder:$_ssl_path"
  22. return 1
  23. fi
  24. _info "Copying key and cert"
  25. _real_key="$_ssl_path/vsftpd.key"
  26. if ! cat "$_ckey" >"$_real_key"; then
  27. _err "Error: write key file to: $_real_key"
  28. return 1
  29. fi
  30. _real_fullchain="$_ssl_path/vsftpd.chain.pem"
  31. if ! cat "$_cfullchain" >"$_real_fullchain"; then
  32. _err "Error: write key file to: $_real_fullchain"
  33. return 1
  34. fi
  35. DEFAULT_VSFTPD_RELOAD="service vsftpd restart"
  36. _reload="${DEPLOY_VSFTPD_RELOAD:-$DEFAULT_VSFTPD_RELOAD}"
  37. if [ -z "$IS_RENEW" ]; then
  38. DEFAULT_VSFTPD_CONF="/etc/vsftpd.conf"
  39. _vsftpd_conf="${DEPLOY_VSFTPD_CONF:-$DEFAULT_VSFTPD_CONF}"
  40. if [ ! -f "$_vsftpd_conf" ]; then
  41. if [ -z "$DEPLOY_VSFTPD_CONF" ]; then
  42. _err "vsftpd conf is not found, please define DEPLOY_VSFTPD_CONF"
  43. return 1
  44. else
  45. _err "It seems that the specified vsftpd conf is not valid, please check."
  46. return 1
  47. fi
  48. fi
  49. if [ ! -w "$_vsftpd_conf" ]; then
  50. _err "The file $_vsftpd_conf is not writable, please change the permission."
  51. return 1
  52. fi
  53. _backup_conf="$DOMAIN_BACKUP_PATH/vsftpd.conf.bak"
  54. _info "Backup $_vsftpd_conf to $_backup_conf"
  55. cp "$_vsftpd_conf" "$_backup_conf"
  56. _info "Modify vsftpd conf: $_vsftpd_conf"
  57. if _setopt "$_vsftpd_conf" "rsa_cert_file" "=" "$_real_fullchain" \
  58. && _setopt "$_vsftpd_conf" "rsa_private_key_file" "=" "$_real_key" \
  59. && _setopt "$_vsftpd_conf" "ssl_enable" "=" "YES"; then
  60. _info "Set config success!"
  61. else
  62. _err "Config vsftpd server error, please report bug to us."
  63. _info "Restoring vsftpd conf"
  64. if cat "$_backup_conf" >"$_vsftpd_conf"; then
  65. _info "Restore conf success"
  66. eval "$_reload"
  67. else
  68. _err "Oops, error restore vsftpd conf, please report bug to us."
  69. fi
  70. return 1
  71. fi
  72. fi
  73. _info "Run reload: $_reload"
  74. if eval "$_reload"; then
  75. _info "Reload success!"
  76. if [ "$DEPLOY_VSFTPD_CONF" ]; then
  77. _savedomainconf DEPLOY_VSFTPD_CONF "$DEPLOY_VSFTPD_CONF"
  78. else
  79. _cleardomainconf DEPLOY_VSFTPD_CONF
  80. fi
  81. if [ "$DEPLOY_VSFTPD_RELOAD" ]; then
  82. _savedomainconf DEPLOY_VSFTPD_RELOAD "$DEPLOY_VSFTPD_RELOAD"
  83. else
  84. _cleardomainconf DEPLOY_VSFTPD_RELOAD
  85. fi
  86. return 0
  87. else
  88. _err "Reload error, restoring"
  89. if cat "$_backup_conf" >"$_vsftpd_conf"; then
  90. _info "Restore conf success"
  91. eval "$_reload"
  92. else
  93. _err "Oops, error restore vsftpd conf, please report bug to us."
  94. fi
  95. return 1
  96. fi
  97. return 0
  98. }