#!/bin/bash

# 防止循环调用
if [ "$KM_TRIAL_MODE_LAUNCHED" = "1" ]; then
    echo "Already in trial mode, skipping..."
    exit 0
fi

export KM_TRIAL_MODE_LAUNCHED=1

# 设置环境变量
appDir=$1
runtimeDir=$2
baseDir=$3
arch=$4
shift 4                      
exec_bin=$1                   
shift                       
exec_args=("$@")             

export LD_LIBRARY_PATH="${appDir}/files/lib:${runtimeDir}/files/usr/lib:${baseDir}/files/usr/lib:${appDir}/depends/usr/lib/${arch}:${runtimeDir}/files/usr/lib/${arch}"
export QT_PLUGIN_PATH="${runtimeDir}/files/usr/lib/${arch}/qt5/plugins"

exec_name=$(basename "$exec_bin")
# 判断路径是否存在并执行
if [ -x "${appDir}/files/bin/${exec_name}" ]; then
    exec_bin_path="${appDir}/files/bin/${exec_name}"
elif [ -x "${appDir}/files/usr/bin/${exec_name}" ]; then
    exec_bin_path="${appDir}/files/usr/bin/${exec_name}"
else
    echo "Executable not found: $exec_name"
    exit 1
fi

# 执行命令并传递参数
"$exec_bin_path" "${exec_args[@]}"


