Unify our usage of the local shell

This commit is contained in:
Přemysl Eric Janouch 2024-12-27 02:16:14 +01:00
parent d83517f67b
commit 280114a5d3
Signed by: p
GPG Key ID: A0420B94F92B9493

21
acid.go
View File

@ -154,6 +154,14 @@ var shellFuncs = ttemplate.FuncMap{
// --- Utilities --------------------------------------------------------------- // --- Utilities ---------------------------------------------------------------
func localShell() string {
if shell := os.Getenv("SHELL"); shell != "" {
return shell
}
// The os/user package doesn't store the parsed out shell field.
return "/bin/sh"
}
func giteaSign(b []byte) string { func giteaSign(b []byte) string {
payloadHmac := hmac.New(sha256.New, []byte(getConfig().Secret)) payloadHmac := hmac.New(sha256.New, []byte(getConfig().Secret))
payloadHmac.Write(b) payloadHmac.Write(b)
@ -842,7 +850,7 @@ func notifierRunCommand(ctx context.Context, task Task) {
return return
} }
cmd := exec.CommandContext(ctx, "sh") cmd := exec.CommandContext(ctx, localShell())
cmd.Stdin = script cmd.Stdin = script
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -1166,14 +1174,6 @@ func executorDownload(client *ssh.Client, remoteRoot, localRoot string) error {
return nil return nil
} }
func executorLocalShell() string {
if shell := os.Getenv("SHELL"); shell != "" {
return shell
}
// The os/user package doesn't store the parsed out shell field.
return "/bin/sh"
}
func executorTmpDir(fallback string) string { func executorTmpDir(fallback string) string {
// See also: https://systemd.io/TEMPORARY_DIRECTORIES/ // See also: https://systemd.io/TEMPORARY_DIRECTORIES/
if tmp := os.Getenv("TMPDIR"); tmp != "" { if tmp := os.Getenv("TMPDIR"); tmp != "" {
@ -1209,9 +1209,10 @@ func executorDeploy(
return err return err
} }
cmd := exec.CommandContext(ctx, executorLocalShell(), "-c", script.String()) cmd := exec.CommandContext(ctx, localShell())
cmd.Env = rt.localEnv() cmd.Env = rt.localEnv()
cmd.Dir = dir cmd.Dir = dir
cmd.Stdin = script
cmd.Stdout = &rt.DeployLog cmd.Stdout = &rt.DeployLog
cmd.Stderr = &rt.DeployLog cmd.Stderr = &rt.DeployLog
return cmd.Run() return cmd.Run()