From 751d4d0e49ba5add5a943e00b2f70c157bcbe834 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Wed, 3 Dec 2025 11:30:46 +0800 Subject: [PATCH 1/2] bugfix: add check for user value to avoid install issues - https://github.com/Sunrisepeak/mcpp-standard/issues/25 avoid nil value issue when install in root user Signed-off-by: sunrisepeak --- core/xself.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/xself.lua b/core/xself.lua index 08f52b1..f0c1f36 100644 --- a/core/xself.lua +++ b/core/xself.lua @@ -22,7 +22,11 @@ function install() cprint("[xlings]: create xlings home dir %s", xlings_homedir) local current_user = os.getenv("USER") sudo.exec("mkdir -p " .. xlings_homedir) - sudo.exec(string.format("chown %s %s", current_user, xlings_homedir)) + -- avoid crash when user is nil value (root) + -- https://github.com/Sunrisepeak/mcpp-standard/issues/25 + if current_user then + sudo.exec(string.format("chown %s %s", current_user, xlings_homedir)) + end elseif is_host("windows") then if os.isdir(pconfig.homedir) then cprint("[xlings]: xlings home dir %s already exists - [win]", pconfig.homedir) @@ -141,9 +145,9 @@ function __xlings_usergroup_checker() if not exist_xlings_group then -- only run once - cprint("[xlings]: ${yellow dim}create group xlings and add current user [%s] to it(only-first)", current_user) + cprint("[xlings]: ${yellow dim}create group xlings and add current user [%s] to it(only-first)", tostring(current_user)) sudo.exec("groupadd xlings") - sudo.exec("usermod -aG xlings " .. current_user) + if current_user then sudo.exec("usermod -aG xlings " .. current_user) end cprint("[xlings]: ${yellow dim}add current %s owner to xlings group(only-first)", xlings_homedir) sudo.exec("chown -R :xlings " .. xlings_homedir) sudo.exec("chmod -R 775 " .. xlings_homedir) @@ -152,7 +156,8 @@ function __xlings_usergroup_checker() sudo.exec("chmod -R g+s " .. xlings_homedir) -- set default acl, new file will inherit acl(group default rw) -- sudo.exec("setfacl -d -m g::rwx " .. xlings_homedir) - elseif not string.find(os.iorun("groups " .. current_user), "xlings", 1, true) then + elseif current_user and (not string.find(os.iorun("groups " .. current_user), "xlings", 1, true)) then + ---@diagnostic disable-next-line: undefined-global cprint("") cprint("${yellow bright}Warning: current user [%s] is not in group xlings", current_user) cprint("") @@ -339,7 +344,7 @@ function uninstall() utils.remove_user_group_linux("xlings") cprint("[xlings]: remove xlings user group - ${green}ok") local current_user = os.getenv("USER") - sudo.exec("chown -R " .. current_user .. ":" .. current_user .. " " .. rcachedir) + if current_user then sudo.exec("chown -R " .. current_user .. ":" .. current_user .. " " .. rcachedir) end elseif is_host("windows") then cprint("[xlings]: try remove [D:/.xlings_data] ...") os.tryrm("D:/.xlings_data") From e6e9bfe56d38b56819da485b00c98248004f8cd1 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Wed, 3 Dec 2025 11:35:37 +0800 Subject: [PATCH 2/2] update --- core/xself.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/core/xself.lua b/core/xself.lua index f0c1f36..3fef6f2 100644 --- a/core/xself.lua +++ b/core/xself.lua @@ -157,7 +157,6 @@ function __xlings_usergroup_checker() -- set default acl, new file will inherit acl(group default rw) -- sudo.exec("setfacl -d -m g::rwx " .. xlings_homedir) elseif current_user and (not string.find(os.iorun("groups " .. current_user), "xlings", 1, true)) then - ---@diagnostic disable-next-line: undefined-global cprint("") cprint("${yellow bright}Warning: current user [%s] is not in group xlings", current_user) cprint("")