Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Created January 20, 2020 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbuckley/9a33ac88606ac34897eb79b10ebb6f07 to your computer and use it in GitHub Desktop.
Save cmbuckley/9a33ac88606ac34897eb79b10ebb6f07 to your computer and use it in GitHub Desktop.
Update UFW with IPs from GitHub
#!/bin/bash
github=$(curl -s https://api.github.com/meta | jq -r '.web | .[]' | sed 's~/32~~' | sort)
ufw=$(ufw status | grep '# GitHub' | awk '{print $1}' | sort)
comm -13 <(echo "$ufw") <(echo "$github") | while read addition; do
echo "Adding $addition"
ufw allow out to $addition port 22 comment GitHub
done
comm -23 <(echo "$ufw") <(echo "$github") | while read deletion; do
echo "Deleting $deletion"
ufw delete allow out to $deletion port 22
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment