make sendmail path configurable using an env var

Closes: #80
This commit is contained in:
chayleaf 2023-10-23 15:31:06 +07:00 committed by Andrew Ayer
parent f38583b79f
commit 74fb03b579
4 changed files with 13 additions and 3 deletions

View File

@ -201,11 +201,16 @@ func main() {
Verbose: flags.verbose,
Script: flags.script,
ScriptDir: defaultScriptDir(),
SendmailPath: "/usr/sbin/sendmail",
Email: flags.email,
Stdout: flags.stdout,
HealthCheckInterval: flags.healthcheck,
}
if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" {
config.SendmailPath = envVar
}
emailFileExists := false
if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil {
emailFileExists = true

View File

@ -218,6 +218,10 @@ and non-zero when a serious error occurs.
: URL of proxy server for making HTTPS requests. `http://`, `https://`, and
`socks5://` URLs are supported. By default, no proxy server is used.
`SENDMAIL_PATH`
: Path to the sendmail binary. Defaults to `/usr/sbin/sendmail`.
# SEE ALSO
certspotter-script(8)

View File

@ -20,6 +20,7 @@ type Config struct {
WatchList WatchList
Verbose bool
SaveCerts bool
SendmailPath string
Script string
ScriptDir string
Email []string

View File

@ -36,7 +36,7 @@ func notify(ctx context.Context, config *Config, notif notification) error {
}
if len(config.Email) > 0 {
if err := sendEmail(ctx, config.Email, notif); err != nil {
if err := sendEmail(ctx, config.SendmailPath, config.Email, notif); err != nil {
return err
}
}
@ -62,7 +62,7 @@ func writeToStdout(notif notification) {
os.Stdout.WriteString(notif.Text() + "\n")
}
func sendEmail(ctx context.Context, to []string, notif notification) error {
func sendEmail(ctx context.Context, sendmailPath string, to []string, notif notification) error {
stdin := new(bytes.Buffer)
stderr := new(bytes.Buffer)
@ -77,7 +77,7 @@ func sendEmail(ctx context.Context, to []string, notif notification) error {
args := []string{"-i", "--"}
args = append(args, to...)
sendmail := exec.CommandContext(ctx, "/usr/sbin/sendmail", args...)
sendmail := exec.CommandContext(ctx, sendmailPath, args...)
sendmail.Stdin = stdin
sendmail.Stderr = stderr