Wanted: sketch to activate bundle when hardware is present
A generic form of the disable/enable wifi when docked/undocked example.
usebundle when present, usebundle when absent compare user defined string to lspci, lsusb, lshw output?
Thoughts?
Sounds useful, particularly for desktop management. Could be used to trigger syncing with a handheld when connected, reconfigure CUPS when a printer is connected, etc.
I propose Util::Trigger
- param1: command to execute (execresult will be checked). Use "$(paths.grep) -q" to find a string in a file. Use $(paths.true) to always succeed.
- param2: context string for when to check the execresult, e.g. "Monday". This can be a more complex expression if you want to use external knowledge and not an execresult.
- param3: bundle to run when execresult is OK. Default=empty string. No parameters.
- param4: bundle to run when execresult is not OK. Default=empty string. No parameters.
$(paths.grep) and $(paths.true)? I dont think the paths sketch made it through the last overhaul. Guessing it should be moved to a library.
I think we would need another param with a list of strings to look for in the execresult output, or I am not understanding your param1 proposal
The paths bundle is in the stdlib, recently. I think CFEngine::stdlib needs to be updated from core.git.
In param1, grep can do lists of strings, and you can use many other commands if it's a generic shell command (e.g. $(paths.tail) -200 to make sure the command doesn't take too long). I think that's better and more generic than making it specifically a grep pipeline and passing a list of strings. But please, it's your sketch, so if you like it better in a different way, go for it! I was just trying to help with suggestions.
oh so you were thinking something like this?
vars: "commands" slist => { "lspsi", "lsusb" }; "trigger_strings" slist => { "Lenovo Dockstring", "my big usb drive" };
methods: usebundle => trigger_strings("$(commands) | $(paths.grep) $(trigger_strings)", context, match_active_bundle, nomatch_activate_bundle)
Yup, exactly. Assigned to myself in case you don't get to it.