mirror of
https://gitee.com/amber-ce/amber-ce-bookworm.git
synced 2025-05-09 01:29:52 +08:00
支持 Ubuntu 25 等 systemd 不再提供 utmp 的情景下获取当前用户名
Signed-off-by: shenmo <jifengshenmo@outlook.com>
This commit is contained in:
parent
05e00b41f9
commit
26dcf96d87
3
debian/changelog
vendored
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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user