Skip to content

Support OS_FLAVOR_LIKE and OS_TYPE in run scripts #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 47 additions & 22 deletions automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

##############################################################################

Expand Down
17 changes: 17 additions & 0 deletions script/get-wkhtmltopdf/meta.yaml
Original file line number Diff line number Diff line change
@@ -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


16 changes: 16 additions & 0 deletions script/get-wkhtmltopdf/run-fedora.sh
Original file line number Diff line number Diff line change
@@ -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


5 changes: 5 additions & 0 deletions script/get-wkhtmltopdf/run-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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 $?
30 changes: 30 additions & 0 deletions script/get-wkhtmltopdf/run.bat
Original file line number Diff line number Diff line change
@@ -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
Loading