Tags: +patch It seems that su -c -- doesn't work better:
APT::Src::RootCommand "su -c --";
yields:
[pid 13670] execve("/bin/su", ["su", "-c", "--", "apt-get", "-y",
"build-dep", "awesome"], [/* 55 vars */]) = 0
which yields:
su: invalid option -- y
trying su -- -c instead yields better results:
[pid 18092] execve("/bin/su", ["su", "--", "-c", "apt-get", "-y",
"build-dep", "awesome"], [/* 55 vars */]) = 0
apt 0.8.10.3 for amd64 compiled on Jan 25 2011 11:30:03
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
... because this is like running:
su -- -c apt-get -y build-dep awesome
what we need here is this:
su -- -c "apt-get -y build-dep awesome"
... so I naively tried:
APT::Src::RootCommand "su -- -c '%s'";
.. but this failed with this:
apt-get: line 0: fg: no job control
... probably that '%s' wasn't interpolated.
I have added a crude patch that allows the following RootCommand to
work:
"su -c %s"
while allowing the regular "sudo" default to work also.
--- apt-src 2011-03-19 13:15:42.000000000 -0400
+++ /usr/bin/apt-src 2011-03-19 13:15:27.000000000 -0400
@@ -220,7 +217,12 @@
The command to use if a non-root user needs to become root. This is used for,
example, to satisfy build-deps. sudo is a good choice and the default.
-If you want to use su, you'll need to set it to "su -c".
+The command to run is appended (e.g. for sudo), unless there's a %s
+argument in the string, in which case the command is passed a a single
+argument.
+
+In short, if you want to use su, you'll need to set it to "su -c %s". If
+you use sudo, set it to "sudo" (default).
=item APT::Src::BuildDeps
--- AptSrc.pm 2004-05-22 09:28:10.000000000 -0400
+++ /usr/share/perl5/AptSrc.pm 2011-03-19 13:07:51.000000000 -0400
@@ -654,14 +654,32 @@
# Runs a shell command, gaining root if necessary.
sub do_root {
my $class=shift;
- if ($> != 0) {
- my @command=qw(sudo);
+ my $interpolated = 0;
+ my @command;
+ if ($> == 0) {
+ @command = @_;
+ } else {
if ($_config->exists('APT::Src::RootCommand')) {
@command=split(/\s+/, $_config->get('APT::Src::RootCommand'));
+ } else {
+ @command = qw(sudo);
+ }
+ # look for %s in the command to see if the user requests
+ # interpolation instead of just appending
+ foreach (@command) {
+ if (/%s/) {
+ $interpolated = 1;
+ $_ = sprintf($_, join(' ', @_));
+ last;
+ }
+ }
+ # probably sudo, which doesn't require the command to be passed
+ # as a single string, so append the array
+ if (!$interpolated) {
+ push @command, @_;
}
- unshift @_, @command;
}
- $class->do(@_);
+ $class->do(@command);
}
# Runs a shell command, only displaying its output in verbose mode or if it
signature.asc
Description: Digital signature

