added environment variable to pass arguments to the specified script

This commit is contained in:
Daniel Sommer 2023-11-30 16:32:49 +01:00
parent 6768f6c2e9
commit 3fc77c5b73
5 changed files with 7 additions and 2 deletions

1
.vscode/launch.json vendored
View file

@ -15,6 +15,7 @@
"SLIDESHOW_PALETTE_ALGORITHM": "", "SLIDESHOW_PALETTE_ALGORITHM": "",
"SLIDESHOW_PALETTE_COLORS": "", "SLIDESHOW_PALETTE_COLORS": "",
"SLIDESHOW_SCRIPT": "", "SLIDESHOW_SCRIPT": "",
"SLIDESHOW_SCRIPT_ARGS": "",
"SLIDESHOW_SCRIPT_ASYNC": "", "SLIDESHOW_SCRIPT_ASYNC": "",
"SLIDESHOW_SCRIPT_STAGE": "", "SLIDESHOW_SCRIPT_STAGE": "",
"SLIDESHOW_LOGLEVEL": "debug", "SLIDESHOW_LOGLEVEL": "debug",

View file

@ -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 | | 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_ALGORITHM | "wsm" | the algorithm used to generate the color palette |
| SLIDESHOW_PALETTE_COLORS | 16 | the amount of colors generated | | 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_ASYNC | false | run the script asynchronously (in a goroutine) |
| SLIDESHOW_SCRIPT_STAGE | | the stage at which the script is executed | | SLIDESHOW_SCRIPT_STAGE | | the stage at which the script is executed |
| SLIDESHOW_LOGLEVEL | "info" | the log level | | SLIDESHOW_LOGLEVEL | "info" | the log level |

View file

@ -17,6 +17,7 @@ var PaletteFile string
var PaletteAlgorithm string var PaletteAlgorithm string
var PaletteColors int var PaletteColors int
var Script string var Script string
var ScriptArgs []string
var ScriptAsync bool var ScriptAsync bool
var ScriptStage string var ScriptStage string
@ -58,6 +59,7 @@ func Initialize() {
} }
PaletteColors = tmpInt PaletteColors = tmpInt
Script = os.Getenv("SLIDESHOW_SCRIPT") Script = os.Getenv("SLIDESHOW_SCRIPT")
ScriptArgs = strings.Split(os.Getenv("SLIDESHOW_SCRIPT_ARGS"), " ")
ScriptAsync, _ = strconv.ParseBool(os.Getenv("SLIDESHOW_SCRIPT_ASYNC")) ScriptAsync, _ = strconv.ParseBool(os.Getenv("SLIDESHOW_SCRIPT_ASYNC"))
ScriptStage = strings.ToLower(os.Getenv("SLIDESHOW_SCRIPT_STAGE")) ScriptStage = strings.ToLower(os.Getenv("SLIDESHOW_SCRIPT_STAGE"))
checkScript() checkScript()

View file

@ -98,7 +98,7 @@ func runScript(running bool) {
if !config.IsScriptSet() { if !config.IsScriptSet() {
return return
} }
cmd := exec.Command(config.Script) cmd := exec.Command(config.Script, config.ScriptArgs...)
error := cmd.Run() error := cmd.Run()
if error != nil { if error != nil {
loggo.Error("encountered an error executing the script '"+config.Script+"'", error.Error()) loggo.Error("encountered an error executing the script '"+config.Script+"'", error.Error())

View file

@ -12,6 +12,7 @@ Environment="SLIDESHOW_PALETTE=/tmp/.slideshow.palette"
Environment="SLIDESHOW_PALETTE_ALGORITHM=" Environment="SLIDESHOW_PALETTE_ALGORITHM="
Environment="SLIDESHOW_PALETTE_COLORS=" Environment="SLIDESHOW_PALETTE_COLORS="
Environment="SLIDESHOW_SCRIPT=" Environment="SLIDESHOW_SCRIPT="
Environment="SLIDESHOW_SCRIPT_ARGS="
Environment="SLIDESHOW_SCRIPT_ASYNC=" Environment="SLIDESHOW_SCRIPT_ASYNC="
Environment="SLIDESHOW_SCRIPT_STAGE=" Environment="SLIDESHOW_SCRIPT_STAGE="
Environment="SLIDESHOW_LOGLEVEL=debug" Environment="SLIDESHOW_LOGLEVEL=debug"