From fb8849322d9788205669a74f7c03386ef20009a2 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 27 Oct 2020 22:29:11 +0100 Subject: [PATCH] command now gets the image as a parameter --- main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 900afd3..e5e7bd1 100644 --- a/main.go +++ b/main.go @@ -145,18 +145,21 @@ func currentImage(configPath string, config sunsetConfig) string { return absFile } -func block(config sunsetConfig, command string) { +func block(configPath string, config sunsetConfig, command string) { + image := currentImage(configPath, config) + go runCommand(command, image) for { nextHr, nextMin := getNextWait(config) timer := time.NewTimer((time.Duration(nextHr) * time.Hour) + (time.Duration(nextMin) * time.Minute)) <-timer.C log.Printf("Running command: %s\n", command) - go runCommand(command) + image := currentImage(configPath, config) + go runCommand(command, image) } } -func runCommand(command string) { - cmd := exec.Command("/usr/bin/env", "sh", "-c", command) +func runCommand(command, image string) { + cmd := exec.Command(command, image) err := cmd.Run() if err != nil { log.Printf("Command %s returned a non 0 code", command) @@ -184,7 +187,7 @@ func main() { fmt.Println("Must provide a command.") os.Exit(1) } - block(conf, *blockCommand) + block(*configFile, conf, *blockCommand) } else { fmt.Printf("%s", currentImage(*configFile, conf)) }