From 3fc77c5b73e3457ed0653325ee823fcecd40c343 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 30 Nov 2023 16:32:49 +0100 Subject: [PATCH] added environment variable to pass arguments to the specified script --- .vscode/launch.json | 1 + README.md | 3 ++- internal/config/config.go | 2 ++ internal/slideshow.go | 2 +- slideshow.service | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index abd95d9..4cd5e8d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,6 +15,7 @@ "SLIDESHOW_PALETTE_ALGORITHM": "", "SLIDESHOW_PALETTE_COLORS": "", "SLIDESHOW_SCRIPT": "", + "SLIDESHOW_SCRIPT_ARGS": "", "SLIDESHOW_SCRIPT_ASYNC": "", "SLIDESHOW_SCRIPT_STAGE": "", "SLIDESHOW_LOGLEVEL": "debug", diff --git a/README.md b/README.md index 98cbeb8..3832ebd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ configuration is entirely done via environment variables. | SLIDESHOW_PALETTE | | path to a file where the color palette will be stored | | SLIDESHOW_PALETTE_ALGORITHM | "wsm" | the algorithm used to generate the color palette | | SLIDESHOW_PALETTE_COLORS | 16 | the amount of colors generated | -| SLIDESHOW_SCRIPT | | path to a script to execute after each loop | +| SLIDESHOW_SCRIPT | | path to a script to execute each loop | +| SLIDESHOW_SCRIPT_ARGS | | arguments to pass to the script | | SLIDESHOW_SCRIPT_ASYNC | false | run the script asynchronously (in a goroutine) | | SLIDESHOW_SCRIPT_STAGE | | the stage at which the script is executed | | SLIDESHOW_LOGLEVEL | "info" | the log level | diff --git a/internal/config/config.go b/internal/config/config.go index 4d4fc94..1502c34 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,7 @@ var PaletteFile string var PaletteAlgorithm string var PaletteColors int var Script string +var ScriptArgs []string var ScriptAsync bool var ScriptStage string @@ -58,6 +59,7 @@ func Initialize() { } PaletteColors = tmpInt Script = os.Getenv("SLIDESHOW_SCRIPT") + ScriptArgs = strings.Split(os.Getenv("SLIDESHOW_SCRIPT_ARGS"), " ") ScriptAsync, _ = strconv.ParseBool(os.Getenv("SLIDESHOW_SCRIPT_ASYNC")) ScriptStage = strings.ToLower(os.Getenv("SLIDESHOW_SCRIPT_STAGE")) checkScript() diff --git a/internal/slideshow.go b/internal/slideshow.go index 324fc49..427b648 100644 --- a/internal/slideshow.go +++ b/internal/slideshow.go @@ -98,7 +98,7 @@ func runScript(running bool) { if !config.IsScriptSet() { return } - cmd := exec.Command(config.Script) + cmd := exec.Command(config.Script, config.ScriptArgs...) error := cmd.Run() if error != nil { loggo.Error("encountered an error executing the script '"+config.Script+"'", error.Error()) diff --git a/slideshow.service b/slideshow.service index 3242540..fe5638f 100644 --- a/slideshow.service +++ b/slideshow.service @@ -12,6 +12,7 @@ Environment="SLIDESHOW_PALETTE=/tmp/.slideshow.palette" Environment="SLIDESHOW_PALETTE_ALGORITHM=" Environment="SLIDESHOW_PALETTE_COLORS=" Environment="SLIDESHOW_SCRIPT=" +Environment="SLIDESHOW_SCRIPT_ARGS=" Environment="SLIDESHOW_SCRIPT_ASYNC=" Environment="SLIDESHOW_SCRIPT_STAGE=" Environment="SLIDESHOW_LOGLEVEL=debug"