diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 1740458..1c88145 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -87,6 +87,35 @@ jobs: exit 1 fi + HOSTNAME_SHORT=\"$(hostname)\" + if ! getent hosts \"$HOSTNAME_SHORT\" >/dev/null 2>&1; then + sudo -n /usr/bin/python3 - <<'PY' + import os + from pathlib import Path + + hostname = os.popen("hostname").read().strip() + hosts_path = Path("/etc/hosts") + + text = hosts_path.read_text(encoding="utf-8") if hosts_path.exists() else "" + lines = text.splitlines() + + def has_hostname() -> bool: + for line in lines: + s = line.strip() + if not s or s.startswith("#"): + continue + if hostname in s.split(): + return True + return False + + if not has_hostname(): + if text and not text.endswith("\n"): + text += "\n" + text += f"127.0.1.1 {hostname}\n" + hosts_path.write_text(text, encoding="utf-8") + PY + fi + sudo -n mkdir -p /opt/infra-controller /etc/infra-controller /var/lib/infra-controller /var/log/infra-controller if [ ! -d /opt/infra-controller/.git ]; then