修改ssinstall

This commit is contained in:
2025-06-11 23:16:06 +08:00
parent 0906adc49e
commit 1f5a58e3c2
2 changed files with 70 additions and 22 deletions

View File

@@ -13,6 +13,27 @@ readonly ACE_ENVIRONMENTS_FOR_AUTOINSTALL=(
"bookworm-run:amber-ce-bookworm"
"trixie-run:amber-ce-trixie"
)
function get_current_user() {
# 优先通过 who 命令获取用户
local user
user=$(who | awk '{print $1}' | head -n 1 2>/dev/null)
# 如果 who 无输出,则通过 loginctl 获取
if [[ -z "$user" ]]; then
user=$(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $3}' | head -n 1)
fi
# 返回最终结果(可能为空)
echo "${user}"
}
function zenity() {
local user=$(get_current_user)
local uid=$(id -u "$user")
sudo -u "$user" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/"$uid"/bus zenity "$@"
}
# 全局变量初始化(位于 parse_args 前)
ACE_PARAMS=()
@@ -258,6 +279,10 @@ function install_in_ace_env() {
local deb_path="$2"
local ace_env_pkg="${3#*:}"
if [ "$IS_ACE_ENV" != "" ]; then
echo "无法在ACE中安装ACE包"
return 1
fi
if ! ensure_ace_env "$ace_env_pkg"; then
return 1
fi
@@ -265,13 +290,15 @@ function install_in_ace_env() {
echo "----------------------------------------"
echo "正在尝试使用 $ace_cmd 环境安装..."
echo "----------------------------------------"
$ace_cmd "ensure_aptss_exist"
# 首先尝试dry-run测试
if ! $ace_cmd "ensure_aptss_exist && aptss install --dry-run '$deb_path'"; then
if ! $ace_cmd "aptss install --dry-run '$deb_path'"; then
echo "初始dry-run测试失败尝试更新后重试..."
$ace_cmd "aptss update"
if ! $ace_cmd "aptss install --dry-run '$deb_path'"; then
echo "dry-run测试仍然失败放弃安装"
echo "OMG_IT_GOES_WRONG"
return 1
fi
fi
@@ -316,8 +343,8 @@ function auto_try_install() {
return 0
fi
# 如果主机安装失败且不在强制本地模式尝试ACE环境
if [ "$FORCE_NATIVE" -eq 0 ]; then
# 如果主机安装失败并非在ACE内运行且不在强制本地模式尝试ACE环境
if [ "$FORCE_NATIVE" -eq 0 ] || [ "$IS_ACE_ENV" = "" ]; then
for ace_entry in "${ACE_ENVIRONMENTS_FOR_AUTOINSTALL[@]}"; do
local ace_cmd=${ace_entry%%:*}
local ace_env_pkg=${ace_entry#*:}
@@ -392,7 +419,9 @@ function lock_file() {
}
function unlock_file() {
if [ -e "$1" ];then
chattr -i "$1"
fi
}
# 主安装流程