You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.7 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  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. DEFAULT_VSFTPD_CONF="/etc/vsftpd.conf"
  25. _vsftpd_conf="${DEPLOY_VSFTPD_CONF:-$DEFAULT_VSFTPD_CONF}"
  26. if [ ! -f "$_vsftpd_conf" ]; then
  27. if [ -z "$DEPLOY_VSFTPD_CONF" ]; then
  28. _err "vsftpd conf is not found, please define DEPLOY_VSFTPD_CONF"
  29. return 1
  30. else
  31. _err "It seems that the specified vsftpd conf is not valid, please check."
  32. return 1
  33. fi
  34. fi
  35. if [ ! -w "$_vsftpd_conf" ]; then
  36. _err "The file $_vsftpd_conf is not writable, please change the permission."
  37. return 1
  38. fi
  39. _backup_conf="$DOMAIN_BACKUP_PATH/vsftpd.conf.bak"
  40. _info "Backup $_vsftpd_conf to $_backup_conf"
  41. cp "$_vsftpd_conf" "$_backup_conf"
  42. _info "Copying key and cert"
  43. _real_key="$_ssl_path/vsftpd.key"
  44. if ! cat "$_ckey" >"$_real_key"; then
  45. _err "Error: write key file to: $_real_key"
  46. return 1
  47. fi
  48. _real_fullchain="$_ssl_path/vsftpd.chain.pem"
  49. if ! cat "$_cfullchain" >"$_real_fullchain"; then
  50. _err "Error: write key file to: $_real_fullchain"
  51. return 1
  52. fi
  53. _info "Modify vsftpd conf: $_vsftpd_conf"
  54. DEFAULT_VSFTPD_RELOAD="service vsftpd restart"
  55. _reload="${DEPLOY_VSFTPD_RELOAD:-$DEFAULT_VSFTPD_RELOAD}"
  56. if _setopt "$_vsftpd_conf" "rsa_cert_file" "=" "$_real_fullchain" \
  57. && _setopt "$_vsftpd_conf" "rsa_private_key_file" "=" "$_real_key" \
  58. && _setopt "$_vsftpd_conf" "ssl_enable" "=" "YES" \
  59. && eval "$_reload"; then
  60. _info "Deploy success!"
  61. if [ "$DEPLOY_VSFTPD_CONF" ]; then
  62. _savedomainconf DEPLOY_VSFTPD_CONF "$DEPLOY_VSFTPD_CONF"
  63. else
  64. _cleardomainconf DEPLOY_VSFTPD_CONF
  65. fi
  66. if [ "$DEPLOY_VSFTPD_RELOAD" ]; then
  67. _savedomainconf DEPLOY_VSFTPD_RELOAD "$DEPLOY_VSFTPD_RELOAD"
  68. else
  69. _cleardomainconf DEPLOY_VSFTPD_RELOAD
  70. fi
  71. return 0
  72. else
  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"
  77. eval "$_reload"
  78. else
  79. _err "Opps, error restore vsftpd conf, please report bug to us."
  80. fi
  81. return 1
  82. fi
  83. return 1
  84. }