diff --git a/npm_install.py b/npm_install.py index 72a43cd..ad00dbd 100644 --- a/npm_install.py +++ b/npm_install.py @@ -170,6 +170,28 @@ def write_resolvers_conf(ipv6_enabled: bool): content = f"resolver {' '.join(ips)} valid=10s{ipv6_flag};\n" write_file(Path("/etc/angie/conf.d/include/resolvers.conf"), content, 0o644) + +def comment_x_served_by_step(path="/etc/angie/conf.d/include/proxy.conf"): + p = Path(path) + if not p.exists(): + raise FileNotFoundError(path) + src = p.read_text() + pattern = re.compile(r'^(?P\s*)(?!#)\s*add_header\s+X-Served-By\s+\$host\s*;\s*$', re.MULTILINE) + count = len(pattern.findall(src)) + if count == 0: + return 0 + backup = p.with_suffix(p.suffix + ".bak") + shutil.copy2(p, backup) + out = pattern.sub(lambda m: f"{m.group('ws')}# add_header X-Served-By $host;", src) + fd, tmp = tempfile.mkstemp(dir=str(p.parent)) + os.close(fd) + Path(tmp).write_text(out) + shutil.copymode(p, tmp) + os.replace(tmp, p) + print(f"✔ Commented {count} line(s) | backup: {backup}") + return count + + def download_extract_tar_gz(url: str, dest_dir: Path) -> Path: dest_dir.mkdir(parents=True, exist_ok=True) with step("Downloading and untaring"): @@ -1332,6 +1354,8 @@ def main(): install_logrotate_for_data_logs() fix_logrotate_permissions_and_wrapper() sync_backup_nginx_conf() + comment_x_served_by_step() + with step("Restarting services after installation"): run(["systemctl","restart","angie.service"], check=False) run(["systemctl","restart","npm.service"], check=False)