This commit is contained in:
Alexey Berezhok
2026-07-18 11:34:35 +03:00
parent 204484c9fc
commit ec27eef6b3
2 changed files with 81 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ mkdir -p %{buildroot}/usr/local/ispmanager-mod_rewrite/patches
cp payload/* %{buildroot}/usr/local/ispmanager-mod_rewrite/patches/ cp payload/* %{buildroot}/usr/local/ispmanager-mod_rewrite/patches/
%triggerin -- nginx %triggerin -- nginx
/usr/local/ispmanager-mod_rewrite/utils/build_mod_rewrite.py /usr/local/ispmanager-mod_rewrite/utils/build_mod_rewrite.py --nodeps
%posttrans %posttrans
killall core killall core

View File

@@ -11,18 +11,71 @@ import shutil
import subprocess import subprocess
import zipfile import zipfile
import datetime import datetime
import re
def _get_nginx_version(log_file):
"""
Detect nginx version from /usr/sbin/nginx -V output.
Args:
log_file: File object to write log messages to
Returns:
str or None: Version string (e.g., '1.30.2') if found, None otherwise
"""
nginx_binary = '/usr/sbin/nginx'
if not os.path.exists(nginx_binary):
log_file.write('Nginx binary not found at /usr/sbin/nginx, using default version detection.\n')
return None
try:
result = subprocess.run([nginx_binary, '-V'], capture_output=True, text=True, timeout=30)
if result.returncode != 0:
log_file.write(f'Failed to run nginx -V with exit code {result.returncode}\n')
if result.stderr:
log_file.write(f'nginx stderr: {result.stderr.strip()}\n')
return None
log_file.write(f'nginx stdout:\n{result.stderr.strip()}\n')
# First line contains "nginx version: nginx/X.Y.Z"
first_line = result.stderr.strip().split('\n')[0]
# Parse the version from the first line
# Expected format: "nginx version: nginx/1.30.2 ..."
match = re.search(r'nginx/(\d+\.\d+\.?\d*)', first_line)
if match:
version = match.group(1)
log_file.write(f'Detected nginx version: {version}\n')
return version
else:
log_file.write(f'Could not parse nginx version from: {first_line}\n')
return None
except subprocess.TimeoutExpired:
log_file.write('nginx -V command timed out.\n')
return None
except Exception as e:
log_file.write(f'Error running nginx -V: {e}\n')
return None
def build_mod_rewrite(): def build_mod_rewrite():
""" """
Build and install the nginx mod_rewrite module. Build and install the nginx mod_rewrite module.
Returns: Returns:
str: Error message on failure, None on success str: Error message on failure, None on success
""" """
tmp_dir = '/tmp/nginx-mod-rewrite' tmp_dir = '/tmp/nginx-mod-rewrite'
log_path = '/usr/local/mgr5/var/nginx-mod-rewrite-plugin.log' log_path = '/usr/local/mgr5/var/nginx-mod-rewrite-plugin.log'
# Check for --nodeps argument - skip installdeps stage if provided
nodeps = False
args = sys.argv[1:]
if '--nodeps' in args:
nodeps = True
try: try:
# Ensure log directory exists # Ensure log directory exists
log_dir = os.path.dirname(log_path) log_dir = os.path.dirname(log_path)
@@ -66,12 +119,34 @@ def build_mod_rewrite():
log_file.write(f'Using extracted root: {extracted_root}\n') log_file.write(f'Using extracted root: {extracted_root}\n')
# Define the sequence of commands to run # Define the sequence of commands to run
commands = [ if nodeps:
['bash', 'package_preparer.sh', 'installdeps'], commands = []
['bash', 'package_preparer.sh', 'download', '.', 'system'], else:
commands = [['bash', 'package_preparer.sh', 'installdeps']]
# Detect nginx version and decide on download target
nginx_version_to_use = '.' # Default fallback
detected_version = _get_nginx_version(log_file)
if detected_version is not None:
nginx_version_to_use = detected_version
log_file.write(f'Using detected nginx version: {nginx_version_to_use} for download\n')
else:
log_file.write('Nginx version detection failed, using default (.).\n')
if nginx_version_to_use == '.':
commands.extend([
['bash', 'package_preparer.sh', 'download', nginx_version_to_use, 'system']
])
else:
commands.extend([
['bash', 'package_preparer.sh', 'download', nginx_version_to_use]
])
commands.extend([
['bash', 'package_preparer.sh', 'build'], ['bash', 'package_preparer.sh', 'build'],
['bash', 'package_preparer.sh', 'installmod'] ['bash', 'package_preparer.sh', 'installmod']
] ])
for cmd in commands: for cmd in commands:
log_file.write(f'Running command: {" ".join(cmd)}\n') log_file.write(f'Running command: {" ".join(cmd)}\n')