Last active
January 21, 2024 22:28
-
-
Save TehPeGaSuS/fc53be6e310a8ab7fdb7588224b0aeb2 to your computer and use it in GitHub Desktop.
Automated renewal of WeeChat relay certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use?
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
/etc/letsencrypt/scripts
folder and save it under the nameweechat_renew.sh
wget https://gist.githubusercontent.com/TehPeGaSuS/fc53be6e310a8ab7fdb7588224b0aeb2/raw/4b6fa8962e0dc9a6430cd41484af3b1438c3882b/weechat_renew.sh -O /etc/letsencrypt/scripts/weechat_renew.sh
chmod +x /etc/letsencrypt/scripts/weechat_renew.sh
certbot -d weechat.domain.tld --deploy-hook /etc/letsencrypt/scripts/weechat_renew.sh
(you may need to run the command twice)