Files
buryan-infra/ops/integration/nginx-remap.sh
T
architect c985c0617b
lint / hygiene (push) Failing after 30s
lint / hygiene (pull_request) Failing after 21s
standard / check (push) Successful in 9s
standard / check (pull_request) Successful in 14s
[INFRA] migrate active old VPS 193.233.210.184 to 45.133.209.253
2026-12-02 18:00:21 +03:00

66 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# ============================================================
# nginx-home-services.sh — files -> Nextcloud, home -> HA
# ============================================================
set -uo pipefail
VPS=45.133.209.253
HCONF=/etc/nginx/conf.d/buryans-all.conf
VCONF=/etc/nginx/conf.d/buryans-all.conf
cat > /tmp/remap.py <<'PY'
import re, sys
path = sys.argv[1]
t = open(path, encoding="utf-8").read()
targets = {
"files.buryans.ru": "http://192.168.1.109:8080", # Nextcloud
"home.buryans.ru": "http://192.168.1.106:9111", # HA через прокси входа
}
changed = []
for dom, new in targets.items():
m = re.search(r"server_name\s+" + re.escape(dom) + r"\s*;", t)
if not m:
print(" не найден блок: " + dom); continue
loc = t.find("location / {", m.end())
if loc == -1:
print(" нет location: " + dom); continue
pm = re.search(r"proxy_pass\s+([^;]+);", t[loc:loc + 1200])
if not pm:
print(" нет proxy_pass: " + dom); continue
old = pm.group(1)
if old == new:
print(" %s: уже так" % dom); continue
seg = t[loc:loc + 1200].replace("proxy_pass " + old + ";", "proxy_pass " + new + ";", 1)
t = t[:loc] + seg + t[loc + 1200:]
changed.append("%s: %s -> %s" % (dom, old, new))
open(path, "w", encoding="utf-8").write(t)
for c in changed:
print(" " + c)
print(" изменено: %d" % len(changed))
PY
echo "=== 1. ДОМАШНИЙ NGINX ==="
cp -p $HCONF $HCONF.before-nc-ha
python3 /tmp/remap.py $HCONF 2>&1 | sed 's/^/ /'
nginx -t 2>&1 | tail -1 | sed 's/^/ /'
systemctl reload nginx && echo " перезагружен"
echo
echo "=== 2. NGINX НА VPS ==="
scp -q /tmp/remap.py root@$VPS:/tmp/remap.py
ssh -o BatchMode=yes -o ConnectTimeout=25 root@$VPS "cp -p $VCONF $VCONF.before-nc-ha; python3 /tmp/remap.py $VCONF; nginx -t 2>&1 | tail -1; systemctl reload nginx && echo ' перезагружен'" 2>&1 | sed 's/^/ /'
echo
echo "=== 3. HOME ASSISTANT: ДОВЕРИЕ ПРОКСИ ==="
pct exec 106 -- bash -c 'ls /opt/smart-lxc/ 2>/dev/null | head -5' | sed 's/^/ /'
pct exec 106 -- bash -c 'grep -nE "^http:|trusted_proxies|use_x_forwarded_for|ip_ban" /opt/smart-lxc/config/configuration.yaml 2>/dev/null | head -10' | sed 's/^/ /'
echo
echo "=== 4. ПРОВЕРКА ==="
sleep 3
for d in files home docs; do
h=$(curl -s -o /dev/null -D - --max-time 12 -k "https://$d.buryans.ru/" 2>/dev/null)
code=$(echo "$h" | head -1 | awk '{print $2}')
loc=$(echo "$h" | grep -i '^location:' | head -1 | tr -d '\r' | cut -c1-70)
printf ' %-8s %s %s\n' "$d" "$code" "$loc"
done