The next release actually makes it so you can do this:

  run "#{sudo} something && #{sudo} something else"

In other words, the sudo() helper, if called without arguments (or with
only a hash of options) will return the command needed to invoke sudo.
Otherwise, it works as it always had.

http://github.com/jamis/capistrano/commit/b45290e6ae3acce465ab5b7b8a82b7ad73a022e3

- Jamis

John Trupiano wrote:
> A basic first step might just be to allow cap's sudo() function to
> take an array of commands.  The expectation of the user would be that
> these individual commands would be prepended with sudo and &&'d
> together.  I realize this only handles one (common) case, but it would
> certainly serve me well.  The question then moves to how to define a
> syntax to properly handle complex chains (||, &&, etc.).
> 
> e.g. syntax
> 
> cmds = [
>   "do_something_dangerous",
>   "do_something_else_dangerous",
>   "stand_up",
>   "take_a_bow"
> ]
> sudo(cmds)  # --> run("sudo do_something_dangerous && sudo
> do_something_else_dangerous && sudo stand_up && sudo take_a_bow")
> 
> Regarding ifs, it might be ugly, but you'd just create two separate
> arrays......if_true_commands and else_commands.
> 
> Just a thought.....I'm actually putting in a helper function for me
> right now to do just this.  Any thoughts?
> 
> -John
> 
> On May 21, 12:48 am, Jamis Buck <[EMAIL PROTECTED]> wrote:
>> I like the SQL placeholder comparison. That might be a more sane
>> approach than some of the options I've been considering.
>>
>> - Jamis
>>
>> On May 20, 2008, at 4:36 PM, David Masover wrote:
>>
>>> Well, one possibility would be to try to parse everything, and be
>>> smart:
>>> if sudo [ -x /path/to/something ]; then cd /path/to; sudo something;
>>> fi
>>> Yes, /usr/bin/[ does exist, at least for me. But this way lies
>>> madness -- that 'cd' obviously must be run in some kind of shell to
>>> affect the following commands, but the user running the command
>>> might not even have access to that path.
>>> One way would be to make sudo simply stick 'sudo ' on the beginning
>>> of a 'run' command. This won't work for everything, but it's simple
>>> enough to be predictable, once you know what it does. A 'sudosh'
>>> command could be added to make it run a '/bin/sh', also.
>>> As for 'injecting' sudo, I don't think it gets any simpler than just
>>> typing 'sudo' -- maybe with a shell quoting helper, so you could do:
>>> run "if [ ! -d /path/to/something ]; then sudo #{shellquote('rm -f /
>>> path/to/something && umask whatever && mkdir /path/to/something')};
>>> fi"
>>> The idea is that shellquote() would escape anything needed to make
>>> it a single literal argument (most likely just wrap it in single
>>> quotes and deal with those). Should be nestable. Something like it
>>> probably already exists (probably even in Cap), but I haven't looked.
>>> Of course, that syntax is hideous, but I'm out of ideas...  maybe
>>> something like SQL placeholder substitution?
>>> On Tue, May 20, 2008 at 3:53 PM, Jamis Buck <[EMAIL PROTECTED]>
>>> wrote:
>>> The real sticky one this when you're using conditionals or
>>> something, e.g.
>>>  if [ -x /path/to/something ]; then cd /path/to; something; fi
>>> First of all, you can't do "sudo if [...] ... fi", because "if"
>>> isn't a command, it's shell syntax. You either need to do "sudo sh -
>>> e '...'" or you do "if [...]; then sudo cd /path/to; sudo something;
>>> fi".
>>> Basically, I don't know that there is a good way to do this
>>> generally. Maybe cap just needs to expose a simple way to "inject"
>>> sudo into commands...
>>> - Jamis
>>> On May 20, 2008, at 2:16 PM, Wes Gamble wrote:
>>> This could be ugly, but when Cap is presented with "sudo x && y",
>>> could that actually be executed as "sudo x && sudo y"?
>>> I haven't tested it and have no idea if it would work with regard to
>>> both running both commands successfully and returning the correct
>>> values for success/failure on the first command for short circuiting
>>> purposes.
>>> Wes
>>> -------------- Original message from Jamis Buck
>>> <[EMAIL PROTECTED]>: --------------
>>
>>  smime.p7s
>> 3KDownload
> 
> > 


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to