Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,10 @@ func (a *agent) run(ctx context.Context) {
}
}

func (*agent) runStartupScript(ctx context.Context, script string) error {
func (a *agent) runStartupScript(ctx context.Context, script string) error {
if script == "" {
return nil
}
currentUser, err := user.Current()
if err != nil {
return xerrors.Errorf("get current user: %w", err)
}
username := currentUser.Username

shell, err := usershell.Get(username)
if err != nil {
return xerrors.Errorf("get user shell: %w", err)
}

writer, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
Expand All @@ -178,12 +168,10 @@ func (*agent) runStartupScript(ctx context.Context, script string) error {
_ = writer.Close()
}()

caller := "-c"
if runtime.GOOS == "windows" {
caller = "/c"
cmd, err := a.createCommand(ctx, script, nil)
if err != nil {
return xerrors.Errorf("create command: %w", err)
}

cmd := exec.CommandContext(ctx, shell, caller, script)
cmd.Stdout = writer
cmd.Stderr = writer
err = cmd.Run()
Expand Down