mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
get-ip.sh internet: returns the first IP address found that has internet access. get-ip.sh local (or no argument): returns the list of non-loopback IPs minus the one that has internet access. This means that update-dns.sh now sends the first IP address that does *not* have internet access.
41 lines
1.1 KiB
Bash
Executable File
41 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Path to Nginx configuration file
|
|
NGINX_CONFIG="/etc/nginx/vhosts.d/dougal.conf"
|
|
|
|
# Extract the first hostname matching 'lan.dougal' from the config
|
|
# Assumes server_name lines like: server_name hostname1 hostname2;
|
|
HOSTNAME=$(grep -oE '[a-zA-Z0-9.-]*lan\.dougal[a-zA-Z0-9.-]*' "$NGINX_CONFIG" | head -n 1)
|
|
|
|
if [ -z "$HOSTNAME" ]; then
|
|
echo "Error: No matching hostname found in $NGINX_CONFIG"
|
|
exit 1
|
|
fi
|
|
|
|
# Path to IP retrieval script
|
|
IP_SCRIPT="$HOME/software/sbin/get-ip.sh"
|
|
|
|
# Get the current IPv4 address
|
|
IP_ADDRESS=$("$IP_SCRIPT" |head -n1)
|
|
|
|
if [ -z "$IP_ADDRESS" ]; then
|
|
echo "Error: Failed to retrieve IP address from $IP_SCRIPT"
|
|
exit 1
|
|
fi
|
|
|
|
# Check for DYNDNS_PASSWD environment variable
|
|
if [ -z "$DYNDNS_PASSWD" ]; then
|
|
echo "Error: DYNDNS_PASSWD environment variable is not set"
|
|
exit 1
|
|
fi
|
|
|
|
# Hurricane Electric DynDNS update URL
|
|
UPDATE_URL="https://dyn.dns.he.net/nic/update?hostname=$HOSTNAME&password=$DYNDNS_PASSWD&myip=$IP_ADDRESS"
|
|
|
|
# Send the update request and capture the response
|
|
RESPONSE=$(curl -s "$UPDATE_URL")
|
|
|
|
# Output the response for logging/debugging
|
|
echo "Update response for $HOSTNAME ($IP_ADDRESS): $RESPONSE"
|
|
|