Skip to content

Commit b073ced

Browse files
authored
Support OS_FLAVOR_LIKE and OS_TYPE in run scripts (#297)
* Support OS_FLAVOR_LIKE and OS_TYPE in run script selection * [Automated Commit] Format Codebase [skip ci] * Added get-wkhtmltopdf script * Added run.bat for get-wkhtmltopdf
1 parent 728085a commit b073ced

File tree

5 files changed

+115
-22
lines changed

5 files changed

+115
-22
lines changed

automation/script/module.py

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5565,29 +5565,54 @@ def run_postprocess(customize_code, customize_common_input, recursion_spaces,
55655565

55665566

55675567
def get_script_name(env, path, script_name='run'):
5568-
"""
5569-
Internal: find the most appropriate run script name for the detected OS
5570-
"""
5568+
# Extract environment variables safely, defaulting to empty strings if
5569+
# missing
5570+
os_flavor = env.get('MLC_HOST_OS_FLAVOR', '')
5571+
os_flavor_like = env.get('MLC_HOST_OS_FLAVOR_LIKE', '')
5572+
os_type = env.get('MLC_HOST_OS_TYPE', '')
5573+
# Only use version if flavor exists
5574+
os_version = env.get('MLC_HOST_OS_VERSION', '') if os_flavor else ''
5575+
platform_flavor = env.get('MLC_HOST_PLATFORM_FLAVOR', '')
5576+
5577+
# Get a list of all files in the directory
5578+
try:
5579+
available_files = set(os.listdir(path))
5580+
except FileNotFoundError:
5581+
# Default if directory doesn't exist
5582+
return os.path.join(path, f"{script_name}.sh")
5583+
5584+
# Check if any script with a "script_name-" prefix exists
5585+
has_prefixed_scripts = any(f.startswith(
5586+
f"{script_name}-") for f in available_files)
5587+
5588+
# Helper function to construct script filenames dynamically
5589+
def script_filename(*parts):
5590+
# Remove empty values to avoid extra '-'
5591+
suffix = "-".join(filter(None, parts))
5592+
return f"{script_name}-{suffix}.sh" if suffix else f"{script_name}.sh"
5593+
5594+
# Define file search order based on priority
5595+
candidates = [
5596+
script_filename(os_flavor, os_version, platform_flavor),
5597+
script_filename(os_flavor, os_version),
5598+
script_filename(os_flavor, platform_flavor),
5599+
script_filename(os_flavor),
5600+
script_filename(os_flavor_like, platform_flavor),
5601+
script_filename(os_flavor_like),
5602+
script_filename(os_type, platform_flavor),
5603+
script_filename(os_type),
5604+
script_filename(platform_flavor),
5605+
]
5606+
5607+
# If prefixed scripts exist, check for the first matching candidate
5608+
if has_prefixed_scripts:
5609+
for candidate in candidates:
5610+
if candidate in available_files:
5611+
return os.path.join(path, candidate)
5612+
5613+
# Fallback to the default script
5614+
return os.path.join(path, f"{script_name}.sh")
55715615

5572-
from os.path import exists
5573-
5574-
tmp_suff1 = env.get('MLC_HOST_OS_FLAVOR', '')
5575-
tmp_suff2 = env.get('MLC_HOST_OS_VERSION', '')
5576-
tmp_suff3 = env.get('MLC_HOST_PLATFORM_FLAVOR', '')
5577-
5578-
if exists(os.path.join(path, script_name + '-' + tmp_suff1 +
5579-
'-' + tmp_suff2 + '-' + tmp_suff3 + '.sh')):
5580-
return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '-' + tmp_suff3 + '.sh'
5581-
elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh')):
5582-
return script_name + '-' + tmp_suff1 + '-' + tmp_suff3 + '.sh'
5583-
elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh')):
5584-
return script_name + '-' + tmp_suff1 + '-' + tmp_suff2 + '.sh'
5585-
elif exists(os.path.join(path, script_name + '-' + tmp_suff1 + '.sh')):
5586-
return script_name + '-' + tmp_suff1 + '.sh'
5587-
elif exists(os.path.join(path, script_name + '-' + tmp_suff3 + '.sh')):
5588-
return script_name + '-' + tmp_suff3 + '.sh'
5589-
else:
5590-
return script_name + '.sh'
55915616

55925617
##############################################################################
55935618

script/get-wkhtmltopdf/meta.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
alias: get-wkhtmltopdf
2+
automation_alias: script
3+
automation_uid: 5b4e0237da074764
4+
cache: true
5+
tags:
6+
- get
7+
- wkhtmltopdf
8+
deps:
9+
- tags: detect,os
10+
- tags: detect,sudo
11+
uid: 67ec874a3dfe4b87
12+
variations:
13+
with-qt:
14+
group: qt
15+
default: true
16+
17+

script/get-wkhtmltopdf/run-fedora.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# This script installs wkhtmltopdf on Amazon Linux
3+
4+
# Download the wkhtmltopdf package
5+
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos6.x86_64.rpm
6+
7+
# Install the package
8+
sudo yum localinstall -y wkhtmltox-0.12.6-1.centos6.x86_64.rpm
9+
10+
# Install dependencies
11+
sudo yum install -y xorg-x11-fonts-75dpi
12+
13+
# Verify the installation
14+
wkhtmltopdf --version
15+
16+

script/get-wkhtmltopdf/run-ubuntu.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
wget -nc https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
3+
test $? -eq 0 || exit $?
4+
${MLC_SUDO} dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
5+
test $? -eq 0 || exit $?

script/get-wkhtmltopdf/run.bat

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@echo off
2+
setlocal
3+
4+
:: Define download URL and filename
5+
set "URL=https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox-0.12.6-1.msvc2015-win64.exe"
6+
set "FILE=wkhtmltox-0.12.6-1.msvc2015-win64.exe"
7+
8+
:: Download the installer if it doesn't already exist
9+
if not exist "%FILE%" (
10+
echo Downloading %FILE%...
11+
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%URL%', '%CD%\%FILE%')"
12+
if %ERRORLEVEL% neq 0 (
13+
echo Download failed!
14+
exit /b %ERRORLEVEL%
15+
)
16+
)
17+
18+
:: Install the software (silent mode)
19+
echo Installing wkhtmltopdf...
20+
start /wait %FILE% /S
21+
22+
if %ERRORLEVEL% neq 0 (
23+
echo Installation failed!
24+
exit /b %ERRORLEVEL%
25+
)
26+
27+
echo Installation successful!
28+
29+
endlocal
30+
exit /b 0

0 commit comments

Comments
 (0)