Dernière activité 1747064984

Script to update home IP in nginx conf

Révision 1a696688dce39a4139269621c546a2382826c119

update-home-ip.sh Brut
1#!/usr/bin/env bash
2
3# in /etc/nginx/sites-available/search.lema.org
4# satisfy any;
5# include /etc/nginx/home_allow.conf;
6# auth_basic "Restricted";
7# auth_basic_user_file /etc/nginx/.htpasswd;
8
9
10
11CNAME="casinha.lema.org"
12INCLUDE_FILE="/etc/nginx/home_allow.conf"
13CURRENT_IP=$(dig +short "$CNAME" | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n 1)
14
15if [[ -z "$CURRENT_IP" ]]; then
16 echo "Could not resolve $CNAME"
17 exit 1
18fi
19
20NEW_CONTENT="allow $CURRENT_IP;\ndeny all;"
21
22# Only reload if IP changed
23if ! grep -q "allow $CURRENT_IP;" "$INCLUDE_FILE"; then
24 echo -e "$NEW_CONTENT" > "$INCLUDE_FILE"
25 nginx -t && nginx -s reload
26 echo "Updated Nginx allow list with IP $CURRENT_IP"
27else
28 echo "IP unchanged, nothing to do."
29fi
30