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