Fixed build of module package
This commit is contained in:
1
BUILDINFO.txt
Normal file
1
BUILDINFO.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Built for nginx 1.30.2
|
||||||
148
extract_nginx_args.py
Executable file
148
extract_nginx_args.py
Executable file
@@ -0,0 +1,148 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Extract nginx configure arguments from `nginx -V` output.
|
||||||
|
Correctly handles quoted arguments with balanced single quotes.
|
||||||
|
Returns the parsed command line for use in package_preparer.sh.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args(text):
|
||||||
|
"""
|
||||||
|
Разбить строку аргументов на список, корректно обрабатывая одинарные кавычки.
|
||||||
|
|
||||||
|
Пример:
|
||||||
|
--with-cc-opt='-O2 -g' --with-ld-opt='...'
|
||||||
|
должно разобиться на два элемента, а не на несколько битых строк.
|
||||||
|
"""
|
||||||
|
args = []
|
||||||
|
current = ""
|
||||||
|
in_single_quotes = False
|
||||||
|
|
||||||
|
for char in text:
|
||||||
|
if char == "'":
|
||||||
|
# Переходим в режим одинарных кавычек или выходим из него,
|
||||||
|
# и добавляем кавычку в текущий аргумент
|
||||||
|
in_single_quotes = not in_single_quotes
|
||||||
|
current += char
|
||||||
|
continue
|
||||||
|
|
||||||
|
if char == " " and not in_single_quotes:
|
||||||
|
# Пробел вне кавычек - конец аргумента
|
||||||
|
if current.strip():
|
||||||
|
args.append(current.strip())
|
||||||
|
current = ""
|
||||||
|
else:
|
||||||
|
# Добавляем символ в текущий аргумент
|
||||||
|
current += char
|
||||||
|
|
||||||
|
# Последний аргумент, если остался
|
||||||
|
if current.strip():
|
||||||
|
args.append(current.strip())
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def main(nginx_src_dir="."):
|
||||||
|
"""
|
||||||
|
Запустить nginx -V и извлечь аргументы конфигурации.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
nginx_src_dir: каталог с исходниками nginx (обычно ./nginx-VER)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
0 на успех, 1 на ошибку. Вывод аргументов в stderr для использования bash скриптом.
|
||||||
|
"""
|
||||||
|
# Запускаем nginx -V через PATH, вывод идёт в stderr!
|
||||||
|
print(f"Running nginx -V...", file=sys.stderr)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(["nginx", "-V"], capture_output=True, text=True)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(f"Error: Could not find 'nginx' in PATH: {e}", file=sys.stderr)
|
||||||
|
print("Make sure nginx is installed and added to PATH.", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# Используем stderr вместо stdout!
|
||||||
|
output = result.stderr
|
||||||
|
|
||||||
|
if not output:
|
||||||
|
print(
|
||||||
|
f"Error: empty output from nginx -V. Return code: {result.returncode}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# Ищем строку с configure arguments
|
||||||
|
for line in output.split("\n"):
|
||||||
|
if "configure arguments:" in line:
|
||||||
|
# Извлекаем всё после "configure arguments:"
|
||||||
|
config_line = line.split("configure arguments:", 1)[1]
|
||||||
|
|
||||||
|
# Парсим аргументы с учётом кавычек
|
||||||
|
args_list = parse_args(config_line)
|
||||||
|
|
||||||
|
print(f"Found configure arguments.", file=sys.stderr)
|
||||||
|
print(f"Parsed {len(args_list)} arguments.", file=sys.stderr)
|
||||||
|
for arg in args_list:
|
||||||
|
print(arg, file=sys.stderr)
|
||||||
|
|
||||||
|
# Удаляем параметры --add-dynamic-module, --with-ld-opt и все --with-*module
|
||||||
|
args_to_remove = ["--add-dynamic-module", "--with-ld-opt"]
|
||||||
|
filtered_args = []
|
||||||
|
for arg in args_list:
|
||||||
|
should_skip = False
|
||||||
|
for remove_arg in args_to_remove:
|
||||||
|
if arg.startswith(remove_arg):
|
||||||
|
should_skip = True
|
||||||
|
break
|
||||||
|
# Проверка на паттерн --with-*module
|
||||||
|
if not should_skip and arg.startswith("--with-"):
|
||||||
|
suffix = arg[7:] # Убираем "--with-"
|
||||||
|
if any(suffix.endswith(m) for m in ["module", "=dynamic"]):
|
||||||
|
should_skip = True
|
||||||
|
if not should_skip:
|
||||||
|
filtered_args.append(arg)
|
||||||
|
args_list = filtered_args
|
||||||
|
|
||||||
|
# Добавляем наш модуль в конец
|
||||||
|
args_list.append("--add-dynamic-module=../modules/mod_rewrite")
|
||||||
|
|
||||||
|
print(f"Added --add-dynamic-module=../modules/mod_rewrite", file=sys.stderr)
|
||||||
|
|
||||||
|
# Формируем команду configure и выводим в stderr
|
||||||
|
cmd_line = "./configure " + " ".join(args_list)
|
||||||
|
print("=== GENERATED CONFIGURE COMMAND ===", file=sys.stderr)
|
||||||
|
print(cmd_line, file=sys.stdout)
|
||||||
|
# Execute the generated configure command
|
||||||
|
result = subprocess.run(
|
||||||
|
cmd_line, shell=True, capture_output=True, text=True
|
||||||
|
)
|
||||||
|
# Print stdout and stderr of the configure command
|
||||||
|
if result.stdout:
|
||||||
|
print(result.stdout, file=sys.stdout)
|
||||||
|
if result.stderr:
|
||||||
|
print(result.stderr, file=sys.stderr)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(
|
||||||
|
f"Error: configure command failed with return code {result.returncode}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print("Error: configure arguments line not found in nginx output", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
nginx_src_dir = "."
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
nginx_src_dir = sys.argv[1]
|
||||||
|
|
||||||
|
exit_code = main(nginx_src_dir)
|
||||||
|
sys.exit(exit_code)
|
||||||
@@ -84,7 +84,7 @@ prepare)
|
|||||||
--transform='s,^,nginx-mod-rewrite-'$pkg_ver'/modules/,'
|
--transform='s,^,nginx-mod-rewrite-'$pkg_ver'/modules/,'
|
||||||
|
|
||||||
tar -rf "tmpbuild/nginx-mod-rewrite-$pkg_ver.tar" \
|
tar -rf "tmpbuild/nginx-mod-rewrite-$pkg_ver.tar" \
|
||||||
-C . LICENSE package_preparer.sh \
|
-C . LICENSE package_preparer.sh extract_nginx_args.py \
|
||||||
--transform='s,^,nginx-mod-rewrite-'$pkg_ver'/,'
|
--transform='s,^,nginx-mod-rewrite-'$pkg_ver'/,'
|
||||||
|
|
||||||
gzip -f "tmpbuild/nginx-mod-rewrite-$pkg_ver.tar"
|
gzip -f "tmpbuild/nginx-mod-rewrite-$pkg_ver.tar"
|
||||||
@@ -176,14 +176,14 @@ installdeps)
|
|||||||
# Determine package manager and install nginx
|
# Determine package manager and install nginx
|
||||||
if command -v dnf >/dev/null 2>&1; then
|
if command -v dnf >/dev/null 2>&1; then
|
||||||
PKG_MGR="dnf"
|
PKG_MGR="dnf"
|
||||||
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget
|
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget python3
|
||||||
elif command -v yum >/dev/null 2>&1; then
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
PKG_MGR="yum"
|
PKG_MGR="yum"
|
||||||
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget
|
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget python3
|
||||||
elif command -v apt-get >/dev/null 2>&1; then
|
elif command -v apt-get >/dev/null 2>&1; then
|
||||||
PKG_MGR="apt-get"
|
PKG_MGR="apt-get"
|
||||||
apt-get update
|
apt-get update
|
||||||
$PKG_MGR install -y nginx debhelper-compat dh-autoreconf libssl-dev libpcre2-dev zlib1g-dev make gcc build-essential wget
|
$PKG_MGR install -y nginx debhelper-compat dh-autoreconf libssl-dev libpcre2-dev zlib1g-dev make gcc build-essential wget python3
|
||||||
else
|
else
|
||||||
echo "Unsupported package manager."
|
echo "Unsupported package manager."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -191,7 +191,7 @@ installdeps)
|
|||||||
;;
|
;;
|
||||||
installmod)
|
installmod)
|
||||||
if command -v dnf >/dev/null 2>&1 || command -v yum >/dev/null 2>&1; then
|
if command -v dnf >/dev/null 2>&1 || command -v yum >/dev/null 2>&1; then
|
||||||
mkdir -p /usr/share/nginx/modules /etc/nginx/modules
|
mkdir -p /usr/share/nginx/modules /usr/lib64/nginx/modules/
|
||||||
cp *.so /usr/lib64/nginx/modules/
|
cp *.so /usr/lib64/nginx/modules/
|
||||||
echo 'load_module "/usr/lib64/nginx/modules/ngx_http_apache_rewrite_module.so";' \
|
echo 'load_module "/usr/lib64/nginx/modules/ngx_http_apache_rewrite_module.so";' \
|
||||||
> /usr/share/nginx/modules/ngx_http_apache_rewrite_module.conf
|
> /usr/share/nginx/modules/ngx_http_apache_rewrite_module.conf
|
||||||
@@ -209,14 +209,14 @@ packageprep)
|
|||||||
# Determine package manager and install nginx
|
# Determine package manager and install nginx
|
||||||
if command -v dnf >/dev/null 2>&1; then
|
if command -v dnf >/dev/null 2>&1; then
|
||||||
PKG_MGR="dnf"
|
PKG_MGR="dnf"
|
||||||
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget
|
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget python3
|
||||||
elif command -v yum >/dev/null 2>&1; then
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
PKG_MGR="yum"
|
PKG_MGR="yum"
|
||||||
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget
|
$PKG_MGR install -y nginx openssl-devel pcre-devel zlib-devel rpm-build gcc gcc-c++ make wget python3
|
||||||
elif command -v apt-get >/dev/null 2>&1; then
|
elif command -v apt-get >/dev/null 2>&1; then
|
||||||
PKG_MGR="apt-get"
|
PKG_MGR="apt-get"
|
||||||
apt-get update
|
apt-get update
|
||||||
$PKG_MGR install -y nginx debhelper-compat dh-autoreconf libssl-dev libpcre2-dev zlib1g-dev make gcc build-essential wget
|
$PKG_MGR install -y nginx debhelper-compat dh-autoreconf libssl-dev libpcre2-dev zlib1g-dev make gcc build-essential wget python3
|
||||||
else
|
else
|
||||||
echo "Unsupported package manager."
|
echo "Unsupported package manager."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -329,13 +329,6 @@ build)
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NGINX_VER_OUTPUT=$(nginx -V 2>&1)
|
|
||||||
CONFIG_ARGS=$(echo "$NGINX_VER_OUTPUT" | awk -F'configure arguments: ' '{print $2}')
|
|
||||||
if [ -z "$CONFIG_ARGS" ]; then
|
|
||||||
echo "Could not retrieve nginx configuration arguments."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Retrieved configure arguments: $CONFIG_ARGS"
|
echo "Retrieved configure arguments: $CONFIG_ARGS"
|
||||||
|
|
||||||
# Change to nginx source directory
|
# Change to nginx source directory
|
||||||
@@ -346,9 +339,8 @@ build)
|
|||||||
fi
|
fi
|
||||||
cd "$SRC_DIR" || exit 1
|
cd "$SRC_DIR" || exit 1
|
||||||
|
|
||||||
# Run configure with saved arguments and add mod_rewrite
|
|
||||||
read -ra CONFIG_ARRAY <<< "$CONFIG_ARGS"
|
python3 ../extract_nginx_args.py
|
||||||
./configure "${CONFIG_ARRAY[@]}" --add-dynamic-module=../modules/mod_rewrite
|
|
||||||
make modules
|
make modules
|
||||||
cp objs/ngx_http_apache_rewrite_module.so ../
|
cp objs/ngx_http_apache_rewrite_module.so ../
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user