To use this script, you need to have a PGP key to sign the keys with.
The script expects the gpg2 binary to exist in /usr/bin/ and the UFW binary to exist in /usr/sbin, if not, change the code to fit your case.
SSH to the server which is intended to automatically update the UFW ruleset.
Import the PGP key and make it trusted:
export PGP_KEY="xxx--your-pgp-fingerprint--xxx"
gpg2 --receive-keys --keyserver ha.pool.sks-keyservers.net ${PGP_KEY}
gpg2 --edit-key ${PGP_KEY}
Download the script and place it in your path (or move it to a dir which is in path already):
wget https://gist.githubusercontent.com/Johannestegner/130ea6c6cd71bd3be26730aa836c5f5a/raw/ufw-cron.sh -O /usr/local/bin/ufw-cron
chmod +x /usr/local/bin/ufw-cron
Change the GIST_URI variable in the script to point to your gist with rules.
Set up a cronjob which runs as often as you wish it to poll:
crontab -e
*/5 * * * * /usr/local/bin/ufw-cron TYPE > /var/log/ufw-cron.log 2>&1
The script takes one argument, and that is the type of ruleset to use (file name in your gist).
Create a new file for your ruleset. Each line should be a UFW rule (exclude the ufw command):
web.txt
allow ssh
allow http
allow https
Add it to your gist.
Fetch the file from the gist (to be sure it have the correct encoding and line-endings etc that the server will have) and create a signature:
wget https://gist.github.com/me/gist-id/raw/web.txt
gpg2 --detach-sign -a web.txt
clip < web.txt.asc
Add the new asc file to the gist.