design-center icon indicating copy to clipboard operation
design-center copied to clipboard

Wanted: sketch to activate bundle when hardware is present

Open nickanderson opened this issue 12 years ago • 7 comments

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?

nickanderson avatar Feb 01 '13 16:02 nickanderson

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.

zzamboni avatar Feb 01 '13 17:02 zzamboni

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.

tzz avatar Feb 01 '13 18:02 tzz

$(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.

nickanderson avatar Feb 01 '13 21:02 nickanderson

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

nickanderson avatar Feb 01 '13 22:02 nickanderson

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.

tzz avatar Feb 01 '13 22:02 tzz

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)

nickanderson avatar Feb 01 '13 23:02 nickanderson

Yup, exactly. Assigned to myself in case you don't get to it.

tzz avatar Feb 15 '13 16:02 tzz