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")