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.

61 lines
2.0 KiB

  1. #!/usr/bin/env bash
  2. # Simple script to deploy certificates for Weechat relay servers
  3. #
  4. # Configuration:
  5. # export WEECHAT_PEM (or set in access.conf) to the PEM file you have your weechat client
  6. # set to load.
  7. # Optionally configure WEECHAT_HOME if you would like to attempt to reload the certificate
  8. # on a successful deploy.
  9. # This deploy script attempts to guess sane defaults in the absence of either
  10. # If you would like this script to automatically reload this certificate, you must ensure
  11. # weechat is configured with plugins.var.fifo.fifo = on
  12. # Usage Example: acme.sh --renew --deploy --deploy-hook weechat -d weechat.example.com --force
  13. #returns 0 means success, otherwise error.
  14. ######## Public functions #####################
  15. #domain keyfile certfile cafile fullchain
  16. weechat_deploy() {
  17. _cdomain="$1"
  18. _ckey="$2"
  19. _ccert="$3"
  20. _cca="$4"
  21. _cfullchain="$5"
  22. _debug _cdomain "$_cdomain"
  23. _debug _ckey "$_ckey"
  24. _debug _ccert "$_ccert"
  25. _debug _cca "$_cca"
  26. _debug _cfullchain "$_cfullchain"
  27. _info "Deploying $_cdomain to weechat"
  28. if [ -z "$WEECHAT_HOME" ]; then
  29. _info "WEECHAT_HOME not set, defaulting to ${HOME}/.weechat"
  30. WEECHAT_HOME="${HOME}/.weechat"
  31. fi
  32. if [ -z "$WEECHAT_PEM" ]; then
  33. _info "WEECHAT_PEM not set, defaulting to ${HOME}/.weechat/ssl/relay.pem"
  34. WEECHAT_PEM="${HOME}/.weechat/ssl/relay.pem"
  35. fi
  36. if [ -w $WEECHAT_PEM ]; then
  37. _info "$WEECHAT_PEM exists and is writable, backing up and overwriting"
  38. cp $WEECHAT_PEM $WEECHAT_PEM.bak
  39. cat $_ckey $_cfullchain > $WEECHAT_PEM
  40. _info "Deployed $_cdomain to weechat"
  41. _debug "Attempting to issue /relay sslcertky to weechat via fifo"
  42. for fifo in $WEECHAT_HOME/weechat_fifo_*
  43. do
  44. _info "Issuing reload to weechat via $fifo"
  45. printf '%b' '*/relay sslcertkey\n' > "$fifo"
  46. done
  47. exit 0
  48. else
  49. _err "$WEECHAT_PEM does not exist or is not writable. If this is a first run \
  50. please issue \'touch $WEECHAT_PEM\' and retry."
  51. exit 1
  52. fi
  53. }