From 6429eac3e8c357744844ec5ac35833ede41405b0 Mon Sep 17 00:00:00 2001 From: sunlintong Date: Mon, 4 Sep 2023 18:15:47 +0800 Subject: [PATCH] fix(chown): use 'id' command to replace SUDO_UID, SUDO_UID env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决容器内无法获取 SUDO_UID, SUDO_UID,的问题,社区暂未合并此PR https://github.com/kubesphere/kubekey/pull/1864 --- cmd/kk/pkg/filesystem/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/kk/pkg/filesystem/task.go b/cmd/kk/pkg/filesystem/task.go index b824e7825..922ea7c52 100644 --- a/cmd/kk/pkg/filesystem/task.go +++ b/cmd/kk/pkg/filesystem/task.go @@ -64,7 +64,7 @@ type LocalTaskChown struct { func (l *LocalTaskChown) Execute(runtime connector.Runtime) error { if exist := util.IsExist(l.Path); exist { - if err := exec.Command("/bin/sh", "-c", fmt.Sprintf("chown -R ${SUDO_UID}:${SUDO_GID} %s", l.Path)).Run(); err != nil { + if err := exec.Command("/bin/sh", "-c", fmt.Sprintf("chown -R $(id -u):$(id -g) %s", l.Path)).Run(); err != nil { return errors.Wrapf(errors.WithStack(err), "chown %s failed", l.Path) } }