dolibarr/dev/setup/nginx/setup_nginx.py
vickytechkey cb9cc21a71
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 1m14s
FIX: #0 Move Nginx helper Python script out of workflow YAML to avoid syntax error
2026-08-19 10:10:27 +05:30

31 lines
1 KiB
Python

import os
filepath = '/etc/nginx/sites-available/default'
if os.path.exists(filepath):
content = open(filepath).read()
if 'location ^~ /dolibarrbeta' not in content:
idx = content.find('location / {')
if idx != -1:
block = """location ^~ /dolibarrbeta {
alias /home/ubuntu/dolibarrbeta/htdocs;
index index.php;
try_files $uri $uri/ /dolibarrbeta/index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
}
"""
content = content[:idx] + block + content[idx:]
open('/tmp/default', 'w').write(content)
print("Nginx config generated at /tmp/default")
else:
print("Error: Could not find 'location / {' in Nginx config")
else:
print("Dolibarrbeta location block already configured in Nginx")
else:
print(f"Error: {filepath} not found")