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

Skip to content

fix: Apply environment variables to startup script #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2022
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