mirror of
https://gitee.com/amber-ce/amber-pm
synced 2026-03-23 05:59:49 +08:00
apm run 支持自动启动,新增 apm launch ,1.1.8
This commit is contained in:
@@ -1 +1 @@
|
||||
@VERSION@=1.1.7
|
||||
@VERSION@=1.1.8
|
||||
|
||||
84
src/usr/bin/amber-pm-app-launcher
Executable file
84
src/usr/bin/amber-pm-app-launcher
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===== 日志函数(简化版)=====
|
||||
log.info() { echo "INFO: $*"; }
|
||||
log.warn() { echo "WARN: $*"; }
|
||||
log.error() { echo "ERROR: $*"; }
|
||||
log.debug() { :; } # APM 场景下可禁用 debug 日志
|
||||
|
||||
# ===== APM 专用桌面文件扫描(单文件)=====
|
||||
function scan_apm_desktop_log() {
|
||||
unset desktop_file_path
|
||||
local pkg_name="$1"
|
||||
local desktop_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/${pkg_name}/entries/applications"
|
||||
|
||||
[ -d "$desktop_dir" ] || return 1
|
||||
|
||||
while IFS= read -r -d '' path; do
|
||||
[ -f "$path" ] || continue
|
||||
if ! grep -q 'NoDisplay=true' "$path" 2>/dev/null; then
|
||||
log.info "Found valid APM desktop file: $path"
|
||||
export desktop_file_path="$path"
|
||||
return 0
|
||||
fi
|
||||
done < <(find "$desktop_dir" -name "*.desktop" -type f -print0 2>/dev/null)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# ===== APM 专用桌面文件扫描(多文件列表)=====
|
||||
function scan_apm_desktop_list() {
|
||||
local pkg_name="$1"
|
||||
local desktop_dir="/var/lib/apm/apm/files/ace-env/var/lib/apm/${pkg_name}/entries/applications"
|
||||
local result=""
|
||||
|
||||
[ -d "$desktop_dir" ] || { echo ""; return; }
|
||||
|
||||
while IFS= read -r -d '' path; do
|
||||
[ -f "$path" ] || continue
|
||||
if ! grep -q 'NoDisplay=true' "$path" 2>/dev/null; then
|
||||
result+="${path},"
|
||||
fi
|
||||
done < <(find "$desktop_dir" -name "*.desktop" -type f -print0 2>/dev/null)
|
||||
|
||||
echo "${result%,}"
|
||||
}
|
||||
|
||||
# ===== 启动应用 =====
|
||||
function launch_app() {
|
||||
local desktop_path="${1#file://}"
|
||||
local exec_cmd
|
||||
shift # 移除第一个参数(desktop_path),剩余的是要传递给应用的参数
|
||||
|
||||
# 提取并清理 Exec 行(移除字段代码如 %f %u 等)
|
||||
exec_cmd=$(grep -m1 '^Exec=' "$desktop_path" | cut -d= -f2- | sed 's/%[fFuUdDnNickvm]*//g; s/^[[:space:]]*//; s/[[:space:]]*$//')
|
||||
[ -z "$exec_cmd" ] && return 1
|
||||
|
||||
# 如果有额外参数,添加到命令中
|
||||
if [ $# -gt 0 ]; then
|
||||
log.info "Launching with arguments: $*"
|
||||
exec_cmd="$exec_cmd $*"
|
||||
fi
|
||||
|
||||
log.info "Launching: $exec_cmd"
|
||||
${SHELL:-bash} -c "$exec_cmd" &
|
||||
}
|
||||
|
||||
# 导出函数供 ACE 环境调用
|
||||
export -f launch_app scan_apm_desktop_log scan_apm_desktop_list log.info log.error
|
||||
|
||||
# ===== 主逻辑 =====
|
||||
[ $# -lt 1 ] && {
|
||||
log.error "Usage: $0 <apm-package-name> [additional arguments...]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
pkg_name="$1"
|
||||
shift # 移除包名参数,剩余的都是要传递给应用的参数
|
||||
|
||||
# 直接执行 launch 逻辑,并将剩余参数传递给 launch_app
|
||||
if scan_apm_desktop_log "$pkg_name" && launch_app "$desktop_file_path" "$@"; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
@@ -21,9 +21,10 @@ Usage:
|
||||
Commands:
|
||||
install 安装软件包
|
||||
remove 卸载软件包
|
||||
run <package> 运行指定软件包的可执行文件
|
||||
sandbox-run <package> 运行指定软件包的可执行文件(主目录沙箱化)
|
||||
bwrap-run <package> 运行指定软件包的可执行文件(使用特殊的挂载参数以支持bwrap)
|
||||
launch <package> [args...] 启动软件包(通过应用启动器)
|
||||
run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(可指定容器内路径)
|
||||
sandbox-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(主目录沙箱化)
|
||||
bwrap-run <package> [EXEC_PATH] [args...] 运行指定软件包的可执行文件(使用特殊的挂载参数以支持bwrap)
|
||||
|
||||
update 更新软件包信息
|
||||
hold 锁定软件包版本
|
||||
@@ -195,8 +196,34 @@ apm_exec(){
|
||||
umount "/tmp/apm/${coredir}"
|
||||
}
|
||||
|
||||
# 启动应用:通过 amber-pm-app-launcher 运行
|
||||
apm_launch() {
|
||||
local pkg="$1"
|
||||
shift
|
||||
if [ -z "$pkg" ]; then
|
||||
log.error "Package name required for 'launch' command"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 保存原始 PATH_PREFIX,检查包是否存在(逻辑同 run 分支)
|
||||
local original_path_prefix="$PATH_PREFIX"
|
||||
if ! [ -d "${PATH_PREFIX}/var/lib/apm/$pkg" ]; then
|
||||
if [ -d "/var/lib/apm/$pkg" ]; then
|
||||
PATH_PREFIX=""
|
||||
else
|
||||
log.error "Package not installed: $pkg"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 调用应用启动器,传递所有参数
|
||||
amber-pm-app-launcher "$pkg" "$@"
|
||||
local exit_code=$?
|
||||
|
||||
# 恢复 PATH_PREFIX(不影响后续命令)
|
||||
PATH_PREFIX="$original_path_prefix"
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# 调试信息函数
|
||||
debug_info() {
|
||||
@@ -234,11 +261,11 @@ bronya_egg() {
|
||||
cat <<'EOF'
|
||||
_ __ ____ _ ____ __
|
||||
| | / /__ _/ / /____ ______(_)__ / __/_ _____ / /____ __ _
|
||||
| |/ / _ `/ / '_/ // / __/ / -_) _\ \/ // (_-</ __/ -_) ' \
|
||||
| |/ / _ `/ / '_/ // / __/ / _-) _\ \/ // (_-</ __/ -_) ' \
|
||||
|___/\_,_/_/_/\_\\_, /_/ /_/\__/ /___/\_, /___/\__/\__/_/_/_/
|
||||
/ / ___ ___ __/___/____/ / /___/
|
||||
/ /__/ _ `/ // / _ \/ __/ _ \
|
||||
/____/\_,_/\_,_/_//_/\__/_//_/
|
||||
/____/\_,_/_,_/_//_/\__/_//_/
|
||||
|
||||
Valkyrie 系统启动 - 重装小兔,Fire!
|
||||
💎 感谢 Anysets 为 AmberCE 和 AmberPM 的 Arch 架构支持提供帮助~
|
||||
@@ -360,6 +387,17 @@ case "$1" in
|
||||
amber-pm-debug amber-pm-dstore-patch
|
||||
amber-pm-gxde-desktop-fix
|
||||
;;
|
||||
launch)
|
||||
shift
|
||||
apm_launch "$@"
|
||||
exit_code=$?
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
log.info "Operation successful"
|
||||
else
|
||||
log.error "Error: Operation failed"
|
||||
exit $exit_code
|
||||
fi
|
||||
;;
|
||||
run)
|
||||
# 运行包命令:第二个参数必须是包名
|
||||
if [ -z "$2" ]; then
|
||||
@@ -393,9 +431,11 @@ case "$1" in
|
||||
log.info "Running user command: $*"
|
||||
apm_exec "$@"
|
||||
else
|
||||
# 没有额外参数:提示
|
||||
log.info "Usage: $SCRIPT_NAME run $pkg [EXEC_PATH]"
|
||||
exit 1
|
||||
# 没有额外参数:提示用户改用 launch,并自动调用 launch
|
||||
log.info "未指定可执行文件路径。如果希望在未指定容器路径的情况下启动应用程序,推荐使用 "launch" 命令"
|
||||
log.info "正在启动:$SCRIPT_NAME launch $pkg"
|
||||
apm_launch "$pkg"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
sandbox-run)
|
||||
|
||||
Reference in New Issue
Block a user