Skip to content

Instantly share code, notes, and snippets.

@TehPeGaSuS
Last active January 21, 2024 22:28
Show Gist options
  • Save TehPeGaSuS/fc53be6e310a8ab7fdb7588224b0aeb2 to your computer and use it in GitHub Desktop.
Save TehPeGaSuS/fc53be6e310a8ab7fdb7588224b0aeb2 to your computer and use it in GitHub Desktop.
Automated renewal of WeeChat relay certificate
#!/usr/bin/env sh
#----------------------------------------------------------------------------------#
# Shell script to manage WeeChat relay certificates with Let's Encrypt and Certbot #
# #----------------------------------#
# NOTE: This script was tested on Ubuntu 20.04+ #
# #-----------------------------------#
# For other distros check Certbot documentation and edit paths/commands accordingly #
#-----------------------------------------------------------------------------------#
#-------------------------------------------#
# Domain/subdomain of your WeeChat instance #
#-------------------------------------------#
weechatDomain=weechat.domain.tld
#------------------------#
# User that runs WeeChat #
#------------------------#
weechatUser=weechater
#------------------------------------------------#
# WeeChat user group (usually the same as above) #
#------------------------------------------------#
weechatGroup=weechater
#-----------------------------------------------------------------#
# WeeChat TLS folder (usually /home/username/.config/weechat/tls) #
#-----------------------------------------------------------------#
weechatTLS="/home/ubuntu/.config/weechat/tls"
#-------------------#
# WeeChat FIFO path #
#-------------------#
weechatFIFO="/run/user/1000/weechat/weechat_fifo"
#----------------------------------------------------------------------#
# Don't edit anything below unless you know exactly what you're doing. #---------------------------------------#
# If you touch the code below and then complain the script "suddenly stopped working" I'll touch you at night. #
#--------------------------------------------------------------------------------------------------------------#
case $RENEWED_LINEAGE in
*/"$weechatDomain")
# Concatenate fullchain.pem and privkey.pem into relay.pem
cat "$RENEWED_LINEAGE"/fullchain.pem "$RENEWED_LINEAGE"/privkey.pem > "$weechatTLS"/relay.pem &&
# Set user that runs weechat as the file owner
chown -- "$weechatUser":"$weechatGroup" "$weechatTLS"/relay.pem &&
# Reload weechat tlscertkey
echo "core.weechat */relay tlscertkey" > "$weechatFIFO" &&
# Success!
printf "WeeChat relay certificate updated successfully!\n\n"
esac
@TehPeGaSuS
Copy link
Author

TehPeGaSuS commented Jan 21, 2024

How to use?

  • Create a folder, named scripts under /etc/letsencrypt, where we will put all the files for automation with Let's Encrypt using the following command: mkdir -p /etc/letsencrypt/scripts
  • Copy the file above to the /etc/letsencrypt/scripts folder and save it under the name weechat_renew.sh
  • Alternatively you can use the following wget command: wget https://gist.githubusercontent.com/TehPeGaSuS/fc53be6e310a8ab7fdb7588224b0aeb2/raw/4b6fa8962e0dc9a6430cd41484af3b1438c3882b/weechat_renew.sh -O /etc/letsencrypt/scripts/weechat_renew.sh
  • Edit the file to fit your needs
  • Make it executable with the command chmod +x /etc/letsencrypt/scripts/weechat_renew.sh
  • Request/renew your certificate with certbot -d weechat.domain.tld --deploy-hook /etc/letsencrypt/scripts/weechat_renew.sh (you may need to run the command twice)
  • Now, every time that Certbot auto renew your certificate, it will be automatically updated on your weechat instance
  • ENJOY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment