Last active
August 9, 2019 09:12
-
-
Save fincham/d7d45619990779131135c3eac0f0e33b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# update the apache ACLs for cloudfront IPs | |
new=$(while read -r i; do printf "Require ip %s\\n" "$i"; done < <(curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="CLOUDFRONT") | .ip_prefix')) | |
if [ "$(sha256sum - <<< "$new" | sed -e 's/ .*//')" != "$(sha256sum /etc/apache2/require-cloudfront-ip.conf | sed -e 's/ .*//')" ]; then | |
> /etc/apache2/require-cloudfront-ip.conf | |
while read -r line; do | |
if [[ "$line" =~ ^Require\ ip\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}$ ]]; then | |
printf "%s\\n" "$line" >> /etc/apache2/require-cloudfront-ip.conf | |
fi | |
done <<< "$new" | |
service apache2 restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment