diff --git a/automation/script/module.py b/automation/script/module.py index acdacff8e..731d3b075 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5565,29 +5565,54 @@ def run_postprocess(customize_code, customize_common_input, recursion_spaces, def get_script_name(env, path, script_name='run'): - """ - Internal: find the most appropriate run script name for the detected OS - """ + # Extract environment variables safely, defaulting to empty strings if + # missing + os_flavor = env.get('MLC_HOST_OS_FLAVOR', '') + os_flavor_like = env.get('MLC_HOST_OS_FLAVOR_LIKE', '') + os_type = env.get('MLC_HOST_OS_TYPE', '') + # Only use version if flavor exists + os_version = env.get('MLC_HOST_OS_VERSION', '') if os_flavor else '' + platform_flavor = env.get('MLC_HOST_PLATFORM_FLAVOR', '') + + # Get a list of all files in the directory + try: + available_files = set(os.listdir(path)) + except FileNotFoundError: + # Default if directory doesn't exist + return os.path.join(path, f"{script_name}.sh") + + # Check if any script with a "script_name-" prefix exists + has_prefixed_scripts = any(f.startswith( + f"{script_name}-") for f in available_files) + + # Helper function to construct script filenames dynamically + def script_filename(*parts): + # Remove empty values to avoid extra '-' + suffix = "-".join(filter(None, parts)) + return f"{script_name}-{suffix}.sh" if suffix else f"{script_name}.sh" + + # Define file search order based on priority + candidates = [ + script_filename(os_flavor, os_version, platform_flavor), + script_filename(os_flavor, os_version), + script_filename(os_flavor, platform_flavor), + script_filename(os_flavor), + script_filename(os_flavor_like, platform_flavor), + script_filename(os_flavor_like), + script_filename(os_type, platform_flavor), + script_filename(os_type), + script_filename(platform_flavor), + ] + + # If prefixed scripts exist, check for the first matching candidate + if has_prefixed_scripts: + for candidate in candidates: + if candidate in available_files: + return os.path.join(path, candidate) + + # Fallback to the default script + return os.path.join(path, f"{script_name}.sh") - from os.path import exists - - tmp_suff1 = env.get('MLC_HOST_OS_FLAVOR', '') - tmp_suff2 = env.get('MLC_HOST_OS_VERSION', '') - tmp_suff3 = env.get('MLC_HOST_PLATFORM_FLAVOR', '') - - if exists(os.path.join(path, script_name + '-' + tmp_suff1 + - '-' + tmp_suff2 + '-' + tmp_suff3 + '.sh')): - return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '-' + tmp_suff3 + '.sh' - elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh')): - return script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh' - elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh')): - return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh' - elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '.sh')): - return script_name + '-' + tmp_suff1 + '.sh' - elif exists(os.path.join(path, script_name + '-' + tmp_suff3 + '.sh')): - return script_name + '-' + tmp_suff3 + '.sh' - else: - return script_name + '.sh' ############################################################################## diff --git a/script/get-wkhtmltopdf/meta.yaml b/script/get-wkhtmltopdf/meta.yaml new file mode 100755 index 000000000..eca50da63 --- /dev/null +++ b/script/get-wkhtmltopdf/meta.yaml @@ -0,0 +1,17 @@ +alias: get-wkhtmltopdf +automation_alias: script +automation_uid: 5b4e0237da074764 +cache: true +tags: +- get +- wkhtmltopdf +deps: + - tags: detect,os + - tags: detect,sudo +uid: 67ec874a3dfe4b87 +variations: + with-qt: + group: qt + default: true + + diff --git a/script/get-wkhtmltopdf/run-fedora.sh b/script/get-wkhtmltopdf/run-fedora.sh new file mode 100644 index 000000000..cd3c713a6 --- /dev/null +++ b/script/get-wkhtmltopdf/run-fedora.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# This script installs wkhtmltopdf on Amazon Linux + +# Download the wkhtmltopdf package +wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos6.x86_64.rpm + +# Install the package +sudo yum localinstall -y wkhtmltox-0.12.6-1.centos6.x86_64.rpm + +# Install dependencies +sudo yum install -y xorg-x11-fonts-75dpi + +# Verify the installation +wkhtmltopdf --version + + diff --git a/script/get-wkhtmltopdf/run-ubuntu.sh b/script/get-wkhtmltopdf/run-ubuntu.sh new file mode 100644 index 000000000..13a1c642a --- /dev/null +++ b/script/get-wkhtmltopdf/run-ubuntu.sh @@ -0,0 +1,5 @@ +#!/bin/bash +wget -nc https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb +test $? -eq 0 || exit $? +${MLC_SUDO} dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb +test $? -eq 0 || exit $? diff --git a/script/get-wkhtmltopdf/run.bat b/script/get-wkhtmltopdf/run.bat new file mode 100644 index 000000000..a172d0b66 --- /dev/null +++ b/script/get-wkhtmltopdf/run.bat @@ -0,0 +1,30 @@ +@echo off +setlocal + +:: Define download URL and filename +set "URL=https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox-0.12.6-1.msvc2015-win64.exe" +set "FILE=wkhtmltox-0.12.6-1.msvc2015-win64.exe" + +:: Download the installer if it doesn't already exist +if not exist "%FILE%" ( + echo Downloading %FILE%... + powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%URL%', '%CD%\%FILE%')" + if %ERRORLEVEL% neq 0 ( + echo Download failed! + exit /b %ERRORLEVEL% + ) +) + +:: Install the software (silent mode) +echo Installing wkhtmltopdf... +start /wait %FILE% /S + +if %ERRORLEVEL% neq 0 ( + echo Installation failed! + exit /b %ERRORLEVEL% +) + +echo Installation successful! + +endlocal +exit /b 0