diff --git a/fs/fs.go b/fs/fs.go index 2dc68e3..8be2017 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -108,6 +108,13 @@ func NewFilesystem(name string, user *user.User, basePath string, log *logging.L return fs } +func (fs *Filesystem) GetHomeDir() (string, error) { + if fs.user == nil { + return "", fmt.Errorf("Home directory not set") + } + return fs.user.HomeDir, nil +} + /* func xcreateEmptyDirectories(base string, paths []string) error { for _, p := range paths { diff --git a/oz-init/init.go b/oz-init/init.go index dac4631..a96476c 100644 --- a/oz-init/init.go +++ b/oz-init/init.go @@ -304,6 +304,12 @@ func (st *initState) handleRunShell(rs *RunShellMsg, msg *ipc.Message) error { if rs.Term != "" { cmd.Env = append(cmd.Env, "TERM="+rs.Term) } + if msg.Ucred.Uid != 0 && msg.Ucred.Gid != 0 { + if homedir, _ := st.fs.GetHomeDir(); homedir != "" { + cmd.Dir = homedir + cmd.Env = append(cmd.Env, "HOME="+homedir) + } + } cmd.Env = append(cmd.Env, "PATH=/usr/bin:/bin") cmd.Env = append(cmd.Env, fmt.Sprintf("PS1=[%s] $ ", st.profile.Name)) st.log.Info("Executing shell...")