Propellor often generates some shell code to run. Examples include Propellor.Bootstrap, but also things like userScriptProperty where a shell command has to be built that can be fed into sudo.
The current code for this is just all strings and easy to make mistakes in. It would be good to integrate http://hackage.haskell.org/package/shell-monad (or a similar library) as a way to generate shell code. --Joey
http://hackage.haskell.org/package/turtle might be another good option --Joey
How would you see the integration of shell-monad or turtle?
Do you have a preference?
I actually use turtle and it is great! It may be more complete than shell-monad which may be an advantage or a disadvantage...
One easy way would be something like:
But, I don't know if that would really be useful. The better use case for shell-monad seems to be where things like
userScriptProperty
take aScript
, that is currently an alias forString
. Since shell-monad can generate a shell script, it would be easy to write:Or, perhaps change userScriptProperty to accept either a stringy-Script or a shell monad Script, via a type class. Then it could be used like this:
Turtle seems to not have its own monad but simply uses MonadIO. So seems you can use Turtle in the implementation of propellor properties the same as other IO actions. Which is great, it should be easy to use it if you want to. Something like:
But I don't think turtle can generate shell scripts like used by
userScriptProperty
.I've posted a question on https://github.com/Gabriel439/Haskell-Turtle-Library/issues/157
Probably Gabriel will have a good idea for this :-). Maybe another solution would be to generate executables instead of shell scripts?
We already have /usr/local/bin/propellor executable, so the cron job or whatever could be made to run it with a parameter that runs the turtle IO action. (Or generally, any IO action.. Being able to run arbitrary haskell IO code as a cron job would be great!)
This would need some way to get a
UniqueId
for an IO action, that is stable across runs of propellor, and a way to build up aMap UniqueId (IO ())
of such actions. The Info interface could be used to build up that Map.Some of the places I'd like to use shell-monad though are where propellor is bootstrapping itself on a host and all it can easily run at that point is shell script.
That would be over cool!
I don't see how to create these UniqueIds, though. I'm not sure I could help a lot on this one (at least before we have a first prototype)...
Could use a tuple of a Data.Unique for the current build of propellor, and a propellor build ID (eg, git rev that was built).
That would make sure that propellor runs the correct IO action. But, when propellor is updated, any cron jobs etc that try to run with the old UniqueId would fail. Unless the old propellor binary could be cached away and used as a fallback, I suppose..