Skip to content

Instantly share code, notes, and snippets.

@diegoweb
diegoweb / update_mod_remoteip_cloudflare.sh
Last active March 2, 2023 04:23
Auto update remoteip.conf from mod_remoteip with new CloudFlare ips
#!/bin/bash
# Defining trusted proxy addresses for mod_remoteip to Restore original visitor IPs
# https://support.cloudflare.com/hc/en-us/articles/200170786-Restoring-original-visitor-IPs
# IP's from CloudFlare https://www.cloudflare.com/en-gb/ips/
# Define variables
ipv4_url="https://www.cloudflare.com/ips-v4"
ipv6_url="https://www.cloudflare.com/ips-v6"
filename="remoteip.conf"
destination="/etc/httpd/conf.modules.d"
  • Use curl to get the JSON response for the latest release
  • Use grep to find the line containing file URL
  • Use cut and tr to extract the URL
  • Use wget to download it
curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \" \