支持 Ubuntu 25 等 systemd 不再提供 utmp 的情景下获取当前用户名

Signed-off-by: shenmo <jifengshenmo@outlook.com>
This commit is contained in:
shenmo 2025-04-18 15:01:44 +00:00 committed by Gitee
parent 05e00b41f9
commit 26dcf96d87
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 15 additions and 2 deletions
debian
src/opt/apps/@PKG_NAME@/files/bin

3
debian/changelog vendored

@ -1,7 +1,8 @@
amber-ce-bookworm (12.7.6) UNRELEASED; urgency=low
amber-ce-bookworm (12.8.0) UNRELEASED; urgency=low
* 通用 ACE 构建,现不再需要单独使用构建脚本
* 更方便地更改成其他ACE
* 现可在容器内使用 dpkg-buildpackage
* 支持 Ubuntu 25 等 systemd 不再提供 utmp 的情景下获取当前用户名
-- shenmo <shenmo@spark-app.store> Wed, 25 Sep 2024 23:15:49 +0800

@ -22,8 +22,20 @@ fi
HERE="$(dirname $(realpath $0))"
function get_current_user() {
# 优先通过 who 命令获取用户
local user
user=$(who | awk '{print $1}' | head -n 1 2>/dev/null)
non_root_user=$(who | awk '{print $1}' | head -n 1)
# 如果 who 无输出,则通过 loginctl 获取
if [[ -z "$user" ]]; then
user=$(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $3}' | head -n 1)
fi
# 返回最终结果(可能为空)
echo "${user}"
}
non_root_user=$(get_current_user)
uid=$(id -u $non_root_user)
function bookworm-run(){