mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
Merge V4
This commit is contained in:
43
tool/store-helper/check-is-installed
Executable file
43
tool/store-helper/check-is-installed
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
readonly ACE_ENVIRONMENTS=(
|
||||
"bookworm-run:amber-ce-bookworm"
|
||||
"trixie-run:amber-ce-trixie"
|
||||
"deepin23-run:amber-ce-deepin23"
|
||||
"sid-run:amber-ce-sid"
|
||||
)
|
||||
dpkg -s '$1' 2>/dev/null | grep -q 'Status: install ok installed' > /dev/null 2>&1
|
||||
RET="$?"
|
||||
if [[ "$RET" != "0" ]] && [[ "$IS_ACE_ENV" == "" ]];then ## 如果未在ACE环境中
|
||||
|
||||
for ace_entry in "${ACE_ENVIRONMENTS[@]}"; do
|
||||
ace_cmd=${ace_entry%%:*}
|
||||
if command -v "$ace_cmd" >/dev/null 2>&1; then
|
||||
echo "----------------------------------------"
|
||||
echo "正在检查 $ace_cmd 环境的安装..."
|
||||
echo "----------------------------------------"
|
||||
|
||||
# 在ACE环境中使用dpkg -s检查安装状态
|
||||
# 使用dpkg -s并检查输出中是否包含"Status: install ok installed"
|
||||
$ace_cmd dpkg -s "$1" 2>/dev/null | grep -q 'Status: install ok installed'
|
||||
try_run_ret="$?"
|
||||
|
||||
# 最终检测结果处理
|
||||
if [ "$try_run_ret" -eq 0 ]; then
|
||||
echo "----------------------------------------"
|
||||
echo "在 $ace_cmd 环境中找到了安装"
|
||||
echo "----------------------------------------"
|
||||
exit $try_run_ret
|
||||
else
|
||||
echo "----------------------------------------"
|
||||
echo "在 $ace_cmd 环境中未能找到安装,继续查找"
|
||||
echo "----------------------------------------"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "----------------------------------------"
|
||||
echo "所有已安装的 ACE 环境中未能找到安装,退出"
|
||||
echo "----------------------------------------"
|
||||
exit "$RET"
|
||||
fi
|
||||
## 如果在ACE环境中或者未出错
|
||||
exit "$RET"
|
||||
49
tool/store-helper/pass-auth.sh
Executable file
49
tool/store-helper/pass-auth.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
|
||||
#!/bin/bash
|
||||
# We use sudo twice to avoid ACE bug here
|
||||
# https://gitee.com/amber-ce/amber-ce-bookworm/commit/43e1a1599ede474b37e41aa10c53fd8afc4d35a1
|
||||
|
||||
function zenity_prompt() {
|
||||
if [[ -e /usr/bin/garma ]]; then
|
||||
garma "$@"
|
||||
else
|
||||
$(command -v zenity) "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "${IS_ACE_ENV}" = "" ]; then
|
||||
echo "检测为非ACE环境,直接提权"
|
||||
pkexec "$@"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# 检查sudo是否需要密码
|
||||
if sudo -n true 2>/dev/null; then
|
||||
echo "sudo 无需密码,继续执行"
|
||||
else
|
||||
# 循环输入密码直到成功或用户取消
|
||||
while true; do
|
||||
# 使用zenity弹出密码输入框
|
||||
PASSWORD=$(zenity_prompt --password --title="需要sudo权限")
|
||||
|
||||
# 检查用户是否取消输入
|
||||
if [ -z "$PASSWORD" ]; then
|
||||
zenity_prompt --error --text="操作已取消"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 尝试使用输入的密码执行sudo命令
|
||||
echo "$PASSWORD" | sudo -S -v 2>/dev/null
|
||||
|
||||
# 检查sudo是否成功
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "密码正确,继续执行"
|
||||
break
|
||||
else
|
||||
zenity_prompt --error --text="密码错误,请重新输入"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# 使用sudo命令执行目标程序
|
||||
echo "$PASSWORD" | sudo sudo -S "$@"
|
||||
164
tool/store-helper/ss-launcher
Executable file
164
tool/store-helper/ss-launcher
Executable file
@@ -0,0 +1,164 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ===== ACE环境配置 =====
|
||||
readonly ACE_ENVIRONMENTS=(
|
||||
"bookworm-run:amber-ce-bookworm"
|
||||
"trixie-run:amber-ce-trixie"
|
||||
"deepin23-run:amber-ce-deepin23"
|
||||
"sid-run:amber-ce-sid"
|
||||
)
|
||||
|
||||
# ===== 日志和函数 =====
|
||||
[ -f /opt/durapps/spark-store/bin/bashimport/log.amber ] && \
|
||||
source /opt/durapps/spark-store/bin/bashimport/log.amber || {
|
||||
log.info() { echo "INFO: $*"; }
|
||||
log.warn() { echo "WARN: $*"; }
|
||||
log.error() { echo "ERROR: $*"; }
|
||||
log.debug() { echo "DEBUG: $*"; }
|
||||
}
|
||||
|
||||
# ===== 功能函数 =====
|
||||
function scan_desktop_file_log() {
|
||||
unset desktop_file_path
|
||||
local package_name=$1
|
||||
# 标准desktop文件检测
|
||||
while IFS= read -r path; do
|
||||
[ -z "$(grep 'NoDisplay=true' "$path")" ] && {
|
||||
log.info "Found valid desktop file: $path"
|
||||
export desktop_file_path="$path"
|
||||
return 0
|
||||
}
|
||||
done < <(dpkg -L "$package_name" 2>/dev/null | grep -E '/usr/share/applications/.*\.desktop$|/opt/apps/.*/entries/applications/.*\.desktop$')
|
||||
|
||||
# 深度环境特殊处理
|
||||
while IFS= read -r path; do
|
||||
[ -z "$(grep 'NoDisplay=true' "$path")" ] && {
|
||||
log.info "Found deepin desktop file: $path"
|
||||
export desktop_file_path="$path"
|
||||
return 0
|
||||
}
|
||||
done < <(find /opt/apps/$package_name -path '*/entries/applications/*.desktop' 2>/dev/null)
|
||||
return 1
|
||||
}
|
||||
|
||||
function scan_desktop_file() {
|
||||
local package_name=$1 result=""
|
||||
# 标准结果收集
|
||||
while IFS= read -r path; do
|
||||
[ -z "$(grep 'NoDisplay=true' "$path")" ] && result+="$path,"
|
||||
done < <(dpkg -L "$package_name" 2>/dev/null | grep -E '/usr/share/applications/.*\.desktop$|/opt/apps/.*/entries/applications/.*\.desktop$')
|
||||
|
||||
# 深度环境补充扫描
|
||||
while IFS= read -r path; do
|
||||
[ -z "$(grep 'NoDisplay=true' "$path")" ] && result+="$path,"
|
||||
done < <(find /opt/apps/$package_name -path '*/entries/applications/*.desktop' 2>/dev/null)
|
||||
|
||||
echo "${result%,}"
|
||||
}
|
||||
|
||||
function launch_app() {
|
||||
local DESKTOP_FILE_PATH="${1#file://}"
|
||||
# 提取并净化Exec命令
|
||||
exec_command=$(grep -m1 '^Exec=' "$DESKTOP_FILE_PATH" | cut -d= -f2- | sed 's/%.//g')
|
||||
[ -z "$exec_command" ] && return 1
|
||||
[ ! -z "$IS_ACE_ENV" ] && HOST_PREFIX="host-spawn"
|
||||
exec_command="${HOST_PREFIX} $exec_command"
|
||||
log.info "Launching: $exec_command"
|
||||
${SHELL:-bash} -c " $exec_command" &
|
||||
|
||||
}
|
||||
|
||||
# 导出函数以便在ACE环境中使用
|
||||
export -f launch_app scan_desktop_file scan_desktop_file_log log.info log.warn log.debug log.error
|
||||
|
||||
# ===== ACE环境执行器 =====
|
||||
function ace_runner() {
|
||||
local action=$1
|
||||
local target=$2
|
||||
|
||||
for ace_entry in "${ACE_ENVIRONMENTS[@]}"; do
|
||||
local ace_cmd=${ace_entry%%:*}
|
||||
local ace_env=${ace_entry#*:}
|
||||
|
||||
if ! command -v "$ace_cmd" >/dev/null; then
|
||||
log.debug "$ace_cmd not found, skipping..."
|
||||
continue
|
||||
fi
|
||||
|
||||
log.info "Attempting in $ace_env environment..."
|
||||
|
||||
case "$action" in
|
||||
check)
|
||||
if "$ace_cmd" scan_desktop_file_log "$target"; then
|
||||
log.info "Found desktop file in $ace_env"
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
list)
|
||||
local result
|
||||
if result=$("$ace_cmd" scan_desktop_file "$target"); then
|
||||
echo "$result"
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
launch|start)
|
||||
"$ace_cmd" scan_desktop_file_log "$target"
|
||||
if desktop_path=$("$ace_cmd" scan_desktop_file_log "$target"); then
|
||||
log.info "Launching from $ace_env..."
|
||||
"$ace_cmd" launch_app $("$ace_cmd" scan_desktop_file "$target")
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
log.debug "Attempt in $ace_env failed"
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# ===== 主逻辑 =====
|
||||
[ $# -lt 2 ] && {
|
||||
log.error "Usage: $0 {check|launch|list|start} package_name/desktop_file"
|
||||
exit 1
|
||||
}
|
||||
|
||||
case $1 in
|
||||
check)
|
||||
# 当前环境检查
|
||||
if scan_desktop_file_log "$2"; then
|
||||
exit 0
|
||||
else
|
||||
# 非ACE环境下执行ACE环境扫描
|
||||
[ -z "$IS_ACE_ENV" ] && ace_runner check "$2"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
|
||||
list)
|
||||
# 当前环境列表
|
||||
if result=$(scan_desktop_file "$2"); then
|
||||
echo "$result"
|
||||
exit 0
|
||||
else
|
||||
# 非ACE环境下执行ACE环境扫描
|
||||
[ -z "$IS_ACE_ENV" ] && ace_runner list "$2"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
|
||||
launch|start)
|
||||
# 当前环境启动
|
||||
if scan_desktop_file_log "$2" && launch_app "$desktop_file_path"; then
|
||||
exit 0
|
||||
else
|
||||
# 非ACE环境下通过ACE环境启动
|
||||
[ -z "$IS_ACE_ENV" ] && ace_runner launch "$2"
|
||||
exit $?
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
log.error "Invalid command: $1"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
190
tool/store-helper/uninstaller
Executable file
190
tool/store-helper/uninstaller
Executable file
@@ -0,0 +1,190 @@
|
||||
#!/bin/bash
|
||||
# ===== ACE环境配置 =====
|
||||
|
||||
readonly ACE_ENVIRONMENTS=(
|
||||
"bookworm-run:amber-ce-bookworm"
|
||||
"trixie-run:amber-ce-trixie"
|
||||
"deepin23-run:amber-ce-deepin23"
|
||||
"sid-run:amber-ce-sid"
|
||||
)
|
||||
# 生成ACE环境参数帮助信息
|
||||
function generate_ace_help() {
|
||||
local help_text=""
|
||||
for ace_entry in "${ACE_ENVIRONMENTS[@]}"; do
|
||||
local ace_param="--${ace_entry#*:}"
|
||||
help_text+=" $ace_param 使用${ace_entry%%:*} ACE容器卸载\n"
|
||||
done
|
||||
echo -e "$help_text"
|
||||
}
|
||||
# 帮助函数
|
||||
function show_help() {
|
||||
echo "Spark Store Uninstall script. 星火商店卸载脚本"
|
||||
echo "用法: $0 [选项] 包名"
|
||||
echo "选项:"
|
||||
echo " -h, --help 显示帮助信息"
|
||||
echo " --delete-after-install 安装成功后删除软件包"
|
||||
echo " --no-create-desktop-entry 不创建桌面快捷方式"
|
||||
echo " --force-create-desktop-entry 强制创建桌面快捷方式"
|
||||
echo "$(generate_ace_help)"
|
||||
echo " --native 只在主机卸载,不使用ACE容器"
|
||||
}
|
||||
|
||||
|
||||
# 参数解析
|
||||
function parse_args() {
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
--delete-after-install)
|
||||
DELETE_AFTER_INSTALL="1"
|
||||
shift
|
||||
;;
|
||||
--native)
|
||||
FORCE_NATIVE="1"
|
||||
shift
|
||||
;;
|
||||
--no-create-desktop-entry)
|
||||
NO_CREATE_DESKTOP="1"
|
||||
shift
|
||||
;;
|
||||
--force-create-desktop-entry)
|
||||
FORCE_CREATE_DESKTOP="1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
# 检查是否为ACE环境参数
|
||||
local is_ace_param=0
|
||||
for ace_entry in "${ACE_ENVIRONMENTS[@]}"; do
|
||||
local ace_param="--${ace_entry#*:}"
|
||||
if [ "$1" = "$ace_param" ]; then
|
||||
# 将ACE环境命令名加入数组
|
||||
ACE_PARAMS+=("${ace_entry%%:*}")
|
||||
is_ace_param=1
|
||||
shift
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果不是ACE环境参数,则视为包名
|
||||
if [ "$is_ace_param" -eq 0 ]; then
|
||||
PACKAGE_NAME="$1"
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# ===== 日志和函数 =====
|
||||
[ -f /opt/durapps/spark-store/bin/bashimport/log.amber ] && \
|
||||
source /opt/durapps/spark-store/bin/bashimport/log.amber || {
|
||||
log.info() { echo "INFO: $*"; }
|
||||
log.warn() { echo "WARN: $*"; }
|
||||
log.error() { echo "ERROR: $*"; }
|
||||
log.debug() { echo "DEBUG: $*"; }
|
||||
}
|
||||
|
||||
# 初始化变量
|
||||
FORCE_NATIVE=0
|
||||
ACE_PARAMS=()
|
||||
PACKAGE_NAME=""
|
||||
uninstall_success=0
|
||||
|
||||
# 解析参数
|
||||
parse_args "$@"
|
||||
|
||||
if [ -z "$PACKAGE_NAME" ]; then
|
||||
log.error "请指定要卸载的包名"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 尝试在本地卸载
|
||||
try_native_uninstall() {
|
||||
if [ "$FORCE_NATIVE" -eq 1 ] || [ ${#ACE_PARAMS[@]} -eq 0 ]; then
|
||||
echo "----------------------------------------"
|
||||
echo "正在检查本地环境中的安装..."
|
||||
echo "----------------------------------------"
|
||||
|
||||
dpkg -s "$PACKAGE_NAME" > /dev/null
|
||||
RET="$?"
|
||||
if [[ "$RET" == "0" ]]; then
|
||||
echo "----------------------------------------"
|
||||
echo "在本地环境中找到了安装"
|
||||
echo "----------------------------------------"
|
||||
apt autopurge "$PACKAGE_NAME" -y
|
||||
uninstall_success=1
|
||||
return 0
|
||||
else
|
||||
echo "----------------------------------------"
|
||||
echo "在本地环境中未能找到安装"
|
||||
echo "----------------------------------------"
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# 尝试在ACE环境中卸载
|
||||
try_ace_uninstall() {
|
||||
local ace_cmd="$1"
|
||||
if command -v "$ace_cmd" >/dev/null 2>&1; then
|
||||
echo "----------------------------------------"
|
||||
echo "正在检查 $ace_cmd 环境的安装..."
|
||||
echo "----------------------------------------"
|
||||
|
||||
$ace_cmd dpkg -l | grep "^ii $PACKAGE_NAME " > /dev/null
|
||||
try_run_ret="$?"
|
||||
|
||||
if [ "$try_run_ret" -eq 0 ]; then
|
||||
echo "----------------------------------------"
|
||||
echo "在 $ace_cmd 环境中找到了安装"
|
||||
echo "----------------------------------------"
|
||||
$ace_cmd apt autopurge "$PACKAGE_NAME" -y
|
||||
uninstall_success=1
|
||||
return 0
|
||||
else
|
||||
echo "----------------------------------------"
|
||||
echo "在 $ace_cmd 环境中未能找到安装"
|
||||
echo "----------------------------------------"
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# 主卸载逻辑
|
||||
if [ $FORCE_NATIVE -eq 1 ] && [ ${#ACE_PARAMS[@]} -eq 0 ]; then
|
||||
# 只有 --native 参数时,只尝试本地卸载
|
||||
try_native_uninstall || exit $?
|
||||
elif [ $FORCE_NATIVE -eq 0 ] && [ ${#ACE_PARAMS[@]} -gt 0 ]; then
|
||||
# 只有 ACE 参数时,只尝试指定的 ACE 环境卸载
|
||||
for ace_param in "${ACE_PARAMS[@]}"; do
|
||||
try_ace_uninstall "$ace_param"
|
||||
done
|
||||
elif [ $FORCE_NATIVE -eq 1 ] && [ ${#ACE_PARAMS[@]} -gt 0 ]; then
|
||||
# 同时有 --native 和 ACE 参数时,先尝试本地卸载,再尝试 ACE 环境卸载
|
||||
try_native_uninstall
|
||||
for ace_param in "${ACE_PARAMS[@]}"; do
|
||||
try_ace_uninstall "$ace_param"
|
||||
done
|
||||
else
|
||||
# 无参数时,先尝试本地卸载,再尝试所有 ACE 环境卸载
|
||||
try_native_uninstall
|
||||
|
||||
for ace_entry in "${ACE_ENVIRONMENTS[@]}"; do
|
||||
ace_cmd=${ace_entry%%:*}
|
||||
if command -v "$ace_cmd" >/dev/null 2>&1; then
|
||||
try_ace_uninstall "$ace_cmd"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $uninstall_success -eq 0 ]; then
|
||||
echo "----------------------------------------"
|
||||
echo "在所有指定的环境中未能找到安装,退出"
|
||||
echo "----------------------------------------"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user